Example usage for org.apache.commons.lang ArrayUtils toPrimitive

List of usage examples for org.apache.commons.lang ArrayUtils toPrimitive

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toPrimitive.

Prototype

public static boolean[] toPrimitive(Boolean[] array) 

Source Link

Document

Converts an array of object Booleans to primitives.

Usage

From source file:gda.device.scannable.ScannableUtils.java

private static double[] positionToArray(String name, Object currentPositionObj, int numberOfParts)
        throws DeviceException {
    if (currentPositionObj == null || numberOfParts == 0) {
        return null;
    }/*from   w  w w . j  a v a2 s. c om*/

    Double[] objectToArray = objectToArray(currentPositionObj);
    if (objectToArray.length == numberOfParts) {
        return ArrayUtils.toPrimitive(objectToArray);
    }
    throw new DeviceException("positionToArray error (" + currentPositionObj.toString() + ") of " + name
            + " as array sizes inconsistent. objectToArray.length = " + Integer.toString(objectToArray.length)
            + ", numberOfParts = " + Integer.toString(numberOfParts));

}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.PlateHeatMapController.java

/**
 *
 * @return/*  ww  w  .j  a  v  a  2s.  c  om*/
 */
private Map<Well, Double> computeValuesMap() {
    Map<Well, Double> valuesMap = new LinkedHashMap<>();

    TrackCoordinatesPanel trackCoordinatesPanel = trackCoordinatesController.getTrackCoordinatesPanel();
    int measurement = trackCoordinatesPanel.getMeasurementComboBox().getSelectedIndex();
    int aggregation = trackCoordinatesPanel.getAggregationComboBox().getSelectedIndex();
    Double value = 0.0;
    double min = 0.0000000000000000;
    double max = 0.0000000000000000;
    List<PlateCondition> plateConditionList = trackCoordinatesController.getPlateConditionList();
    for (PlateCondition condition : plateConditionList) {
        SingleCellConditionDataHolder conditionDataHolder = trackCoordinatesController
                .getConditionDataHolder(condition);
        List<SingleCellWellDataHolder> singleCellWellDataHolders = conditionDataHolder
                .getSingleCellWellDataHolders();
        for (SingleCellWellDataHolder wellDataHolder : singleCellWellDataHolders) {
            if (!wellDataHolder.getTrackDataHolders().isEmpty()) {
                Well well = wellDataHolder.getWell();

                switch (measurement) {
                case 0: // number of trajectories
                    int nrTrack = wellDataHolder.getTrackDataHolders().size();
                    value = (double) nrTrack;

                    if (value > max) {
                        max = value;
                    }
                    if (value < min) {
                        min = value;
                    }
                    break;
                case 1: // speed
                    Double[] trackSpeedsVector = wellDataHolder.getTrackSpeedsVector();
                    switch (aggregation) {
                    case 0: // mean
                        value = AnalysisUtils.computeMean(
                                ArrayUtils.toPrimitive(AnalysisUtils.excludeNullValues(trackSpeedsVector)));

                        if (value > max) {
                            max = value;
                        }
                        if (value < min) {
                            min = value;
                        }
                        break;
                    case 1: // median
                        value = AnalysisUtils.computeMedian(
                                ArrayUtils.toPrimitive(AnalysisUtils.excludeNullValues(trackSpeedsVector)));

                        if (value > max) {
                            max = value;
                        }
                        if (value < min) {
                            min = value;
                        }
                        break;
                    }
                    break;
                case 3: // directionality
                    Double[] endPointDirectionalityRatios = wellDataHolder.getEndPointDirectionalityRatios();
                    switch (aggregation) {
                    case 0: // mean
                        value = AnalysisUtils.computeMean(ArrayUtils
                                .toPrimitive(AnalysisUtils.excludeNullValues(endPointDirectionalityRatios)));

                        if (value > max) {
                            max = value;
                        }
                        if (value < min) {
                            min = value;
                        }
                        break;
                    case 1: // median
                        value = AnalysisUtils.computeMedian(ArrayUtils
                                .toPrimitive(AnalysisUtils.excludeNullValues(endPointDirectionalityRatios)));

                        if (value > max) {
                            max = value;
                        }
                        if (value < min) {
                            min = value;
                        }
                        break;
                    }
                    break;
                }
                valuesMap.put(well, value);
            }

        }
    }
    heatMapPlatePanel.setMin(min);
    heatMapPlatePanel.setMax(max);
    return valuesMap;

}

From source file:com.opengamma.analytics.financial.interestrate.swap.method.SwapCalculatorTest.java

@Test
public void parSpreadCurveSensitivityFixedIborBeforeFirstFixing() {
    final ZonedDateTime referenceDate = DateUtils.getUTCDate(2012, 5, 14);
    final SwapFixedCoupon<Coupon> swap = SWAP_FIXED_IBOR_DEFINITION.toDerivative(referenceDate, CURVE_NAMES);
    final String fwdCurveName = ((CouponIbor) swap.getSecondLeg().getNthPayment(0)).getForwardCurveName();
    InterestRateCurveSensitivity pscsComputed = swap.accept(PSCSC, CURVES);
    pscsComputed = pscsComputed.cleaned();
    final double[] timesDsc = new double[swap.getSecondLeg().getNumberOfPayments()];
    for (int loopcpn = 0; loopcpn < swap.getSecondLeg().getNumberOfPayments(); loopcpn++) {
        timesDsc[loopcpn] = swap.getSecondLeg().getNthPayment(loopcpn).getPaymentTime();
    }/*from  ww w. j  ava 2  s  .  c o  m*/
    final List<DoublesPair> sensiDscFD = FDCurveSensitivityCalculator.curveSensitvityFDCalculator(swap, PSC,
            CURVES, swap.getFirstLeg().getDiscountCurve(), timesDsc, 1.0E-10);
    final List<DoublesPair> sensiDscComputed = pscsComputed.getSensitivities()
            .get(swap.getFirstLeg().getDiscountCurve());
    assertTrue("parSpread: curve sensitivity - dsc",
            InterestRateCurveSensitivityUtils.compare(sensiDscFD, sensiDscComputed, TOLERANCE_SPREAD_DELTA));
    final Set<Double> timesFwdSet = new TreeSet<>();
    for (int loopcpn = 0; loopcpn < swap.getSecondLeg().getNumberOfPayments(); loopcpn++) {
        timesFwdSet.add(((CouponIbor) swap.getSecondLeg().getNthPayment(loopcpn)).getFixingPeriodStartTime());
        timesFwdSet.add(((CouponIbor) swap.getSecondLeg().getNthPayment(loopcpn)).getFixingPeriodEndTime());
    }
    final Double[] timesFwd = timesFwdSet.toArray(new Double[timesFwdSet.size()]);
    final List<DoublesPair> sensiFwdFD = FDCurveSensitivityCalculator.curveSensitvityFDCalculator(swap, PSC,
            CURVES, fwdCurveName, ArrayUtils.toPrimitive(timesFwd), 1.0E-10);
    final List<DoublesPair> sensiFwdComputed = pscsComputed.getSensitivities().get(fwdCurveName);
    assertTrue("parSpread: curve sensitivity - fwd",
            InterestRateCurveSensitivityUtils.compare(sensiFwdFD, sensiFwdComputed, TOLERANCE_SPREAD_DELTA));
}

From source file:aldenjava.opticalmapping.data.data.OptMapDataReader.java

private DataNode parseBNX() throws IOException {

    // Currently unused information, Only support one (single-color) channel

    // int labelChannel;
    // double avgIntensity;
    // double snr;
    // int noOfLables;
    // String originalMoleculeID;
    // int scanNumber;
    // int scanDirection;
    // String chipID;
    // int flowCell;
    // int runID;
    // int globalScanNumber;

    // BNX File Version 1.0
    // #0h LabelChannel MoleculeId Length AvgIntensity SNR NumberofLabels OriginalMoleculeId ScanNumber ScanDirection ChipId Flowcell
    // #0f int int float float float int int int int string int
    // #1h LabelChannel LabelPositions[N]
    // #1f int float
    // #2h LabelChannel LabelPositions[N]
    // #2h int float
    // #Qh QualityScoreID QualityScores[N]
    // #Qf str float
    // BNX File Version 1.2
    // #0h LabelChannel MoleculeId Length AvgIntensity SNR NumberofLabels OriginalMoleculeId ScanNumber ScanDirection ChipId Flowcell RunId GlobalScanNumber
    // #0f int int float float float int int int int string int int int
    // #1h LabelChannel LabelPositions[N]
    // #1f int float
    // #2h LabelChannel LabelPositions[N]
    // #2h int float
    // #Qh QualityScoreID QualityScores[N]
    // #Qf str float
    String name = "";
    long size = -1;

    double[] snr = null;
    double[] intensity = null;

    long[] refp = null;
    boolean gotNameSizeInfo = false;
    boolean gotDetailInfo = false;
    boolean gotSNRInfo = false;
    boolean gotIntensityInfo = false;
    do {/*  w  w  w  .j  av  a2s  . c o m*/

        String s = this.nextline.trim();

        String[] l = s.split("\t");
        switch (l[0]) {
        case "0":
            name = l[1];
            size = (long) Double.parseDouble(l[2]);
            gotNameSizeInfo = true;
            break;
        case "1":
            refp = new long[l.length - 2]; // last element should be the size of molecule
            for (int i = 1; i < l.length - 1; i++)
                refp[i - 1] = (long) Double.parseDouble(l[i]);
            gotDetailInfo = true;
            break;
        case "QX01":
        case "QX11":
            snr = new double[l.length - 1];
            for (int i = 1; i < l.length; i++)
                snr[i - 1] = Double.parseDouble(l[i]);
            gotSNRInfo = true;
            break;
        case "QX02":
        case "QX12":
            intensity = new double[l.length - 1];
            for (int i = 1; i < l.length; i++)
                intensity[i - 1] = Double.parseDouble(l[i]);
            gotIntensityInfo = true;
            break;
        default:

        }
        proceedNextLine();
    } while ((this.nextline != null) && (this.nextline.startsWith("1") || this.nextline.startsWith("QX01")
            || this.nextline.startsWith("QX02") || this.nextline.startsWith("QX11")
            || this.nextline.startsWith("QX12")));
    if (gotNameSizeInfo && gotDetailInfo && gotSNRInfo && gotIntensityInfo) {
        List<Long> refpList = new ArrayList<Long>();
        for (int i = 0; i < refp.length; i++)
            if (snr[i] >= bnxSNR)
                refpList.add(refp[i]);
        refp = ArrayUtils.toPrimitive(refpList.toArray(new Long[refpList.size()]));
        BnxDataNode data = new BnxDataNode(name, size, refp, intensity, snr);
        return data;
    } else {
        System.err.println("Warning: incomplete record is found.");
        return null;
    }
}

From source file:com.ironiacorp.statistics.r.AbstractRClient.java

@Override
@SuppressWarnings({ "unchecked", "cast" })
public LinearModelSummary linearModel(double[] data, Map<String, List<?>> factors) {

    String datName = RandomStringUtils.randomAlphabetic(10);
    assign(datName, data);//ww w .ja  v a  2  s .c o  m

    for (String factorName : factors.keySet()) {
        List<?> list = factors.get(factorName);
        if (list.iterator().next() instanceof String) {
            assignFactor(factorName, (List<String>) list);
        } else {
            // treat is as a numeric covariate
            List<Double> d = new ArrayList<Double>();
            for (Object object : list) {
                d.add((Double) object);
            }

            assign(factorName, ArrayUtils.toPrimitive(d.toArray(new Double[] {})));
        }
    }

    String modelDeclaration = datName + " ~ " + StringUtils.join(factors.keySet(), "+");

    String lmName = RandomStringUtils.randomAlphabetic(10);
    String command = lmName + "<-lm(" + modelDeclaration + ", na.action=na.exclude)";
    voidEval(command);

    REXP lmsum = eval("summary(" + lmName + ")");
    REXP anova = eval("anova(" + lmName + ")");

    return new LinearModelSummary(lmsum, anova, factors.keySet().toArray(new String[] {}));

}

From source file:it.iit.genomics.cru.structures.business.StructureMapper.java

private int[] getPdbPositions(String structureId, Chain chain, AAPosition search, MoleculeEntry protein) {

    ArrayList<Integer> positions = new ArrayList<>();

    // Align the region to the chain
    SmithWaterman nw;//  w ww  . ja v  a2  s. co m
    nw = new SmithWaterman(search.getGene().getUniprotSequence().getSequence(), chain.getAtomSequence());

    String regionAlignedSequence = nw.getAlignmentSeqA();
    String chainAlignedSequence = nw.getAlignmentSeqB();

    int groupPosition = 0;

    // go to the first AA of the group, skiping non AA
    for (int chainAAindex = 0; chainAAindex < nw.getStartAlignmentB(); chainAAindex++) {

        Group group = chain.getAtomGroup(groupPosition);

        if (false == GroupType.AMINOACID.equals(group.getType())) {
            chainAAindex++;
        }
        groupPosition++;
    }

    int uniprotCursor = nw.getStartAlignmentA();

    for (int aaPosition = 0; aaPosition < regionAlignedSequence.length(); aaPosition++) {

        char uniprotAA = regionAlignedSequence.charAt(aaPosition);
        char pdbAA = chainAlignedSequence.charAt(aaPosition);

        if ('-' == pdbAA) {
            uniprotCursor++;
            continue;
        }

        Group group = chain.getAtomGroup(groupPosition);

        groupPosition++;

        if (GroupType.AMINOACID.equals(group.getType())) {

            Integer pos = group.getResidueNumber().getSeqNum();

            if ('-' == uniprotAA) {
                logger.warn("Position not aligned to uniprot: {0} {1} {2}",
                        new Object[] { structureId, chain.getChainID(), pos });
            } else if (uniprotCursor >= search.getStart() - 1 && uniprotCursor <= search.getEnd() - 1) {

                // Add residue
                positions.add(pos);

                int uniprotPos = uniprotCursor + 1;

                search.addPdbToProtein(structureId, pos, chain.getChainID(), new UniprotPosition(uniprotPos));
            }

        }

        if ('-' != uniprotAA) {
            uniprotCursor++;
        }

    }

    return ArrayUtils.toPrimitive(positions.toArray(new Integer[positions.size()]));

}

From source file:com.opengamma.analytics.financial.provider.curve.InflationBuildingCurveWithDiscountTestEUR.java

@Test(enabled = false)
public void comparison1Unit2Units() {
    final InflationProviderDiscount[] units = new InflationProviderDiscount[2];
    final CurveBuildingBlockBundle[] bb = new CurveBuildingBlockBundle[2];
    final YieldAndDiscountCurve[] curveDsc = new YieldAndDiscountCurve[2];
    final PriceIndexCurve[] curveInflation = new PriceIndexCurve[2];

    for (int loopblock = 0; loopblock < 2; loopblock++) {
        units[loopblock] = CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(loopblock).getFirst();
        bb[loopblock] = CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(loopblock).getSecond();
        curveDsc[loopblock] = units[loopblock].getCurve(USD);
        curveInflation[loopblock] = units[loopblock].getCurve(US_CPI);

    }/*ww  w.  ja v  a2  s .c o  m*/
    assertEquals("Curve construction: 1 unit / 3 units ", curveDsc[0].getNumberOfParameters(),
            curveDsc[1].getNumberOfParameters());
    assertEquals("Curve construction: 1 unit / 3 units ", curveInflation[0].getNumberOfParameters(),
            curveInflation[1].getNumberOfParameters());

    assertArrayEquals("Curve construction: 1 unit / 3 units ",
            ArrayUtils.toPrimitive(((YieldCurve) curveDsc[0]).getCurve().getXData()),
            ArrayUtils.toPrimitive(((YieldCurve) curveDsc[1]).getCurve().getXData()), TOLERANCE_CAL);
    assertArrayEquals("Curve construction: 1 unit / 3 units ",
            ArrayUtils.toPrimitive(((YieldCurve) curveDsc[0]).getCurve().getYData()),
            ArrayUtils.toPrimitive(((YieldCurve) curveDsc[1]).getCurve().getYData()), TOLERANCE_CAL);
    assertArrayEquals("Curve construction: 1 unit / 3 units ",
            ArrayUtils.toPrimitive(curveInflation[0].getCurve().getXData()),
            ArrayUtils.toPrimitive(curveInflation[1].getCurve().getXData()), TOLERANCE_CAL);
    assertArrayEquals("Curve construction: 1 unit / 3 units ",
            ArrayUtils.toPrimitive(curveInflation[0].getCurve().getYData()),
            ArrayUtils.toPrimitive(curveInflation[1].getCurve().getYData()), TOLERANCE_CAL);
}

From source file:com.opengamma.analytics.financial.provider.curve.MulticurveBuildingDiscountingDiscountUSD2Test.java

@Test
public void comparison1Unit2Units() {
    final MulticurveProviderDiscount[] units = new MulticurveProviderDiscount[2];
    final CurveBuildingBlockBundle[] bb = new CurveBuildingBlockBundle[2];
    final YieldAndDiscountCurve[] curveDsc = new YieldAndDiscountCurve[2];
    final YieldAndDiscountCurve[] curveFwd = new YieldAndDiscountCurve[2];
    for (int loopblock = 0; loopblock < 2; loopblock++) {
        units[loopblock] = CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(loopblock).getFirst();
        bb[loopblock] = CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(loopblock).getSecond();
        curveDsc[loopblock] = units[loopblock].getCurve(USD);
        curveFwd[loopblock] = units[loopblock].getCurve(USDLIBOR3M);
    }/*  w ww .j  a va 2s  . c o m*/
    assertEquals("Curve construction: 1 unit / 2 units ", curveDsc[0].getNumberOfParameters(),
            curveDsc[1].getNumberOfParameters());
    assertEquals("Curve construction: 1 unit / 2 units ", curveFwd[0].getNumberOfParameters(),
            curveFwd[1].getNumberOfParameters());
    assertArrayEquals("Curve construction: 1 unit / 2 units ",
            ArrayUtils.toPrimitive(((YieldCurve) curveDsc[0]).getCurve().getXData()),
            ArrayUtils.toPrimitive(((YieldCurve) curveDsc[1]).getCurve().getXData()), TOLERANCE_CAL);
    assertArrayEquals("Curve construction: 1 unit / 2 units ",
            ArrayUtils.toPrimitive(((YieldCurve) curveDsc[0]).getCurve().getYData()),
            ArrayUtils.toPrimitive(((YieldCurve) curveDsc[1]).getCurve().getYData()), TOLERANCE_CAL);
    assertArrayEquals("Curve construction: 1 unit / 2 units ",
            ArrayUtils.toPrimitive(((YieldCurve) curveFwd[0]).getCurve().getXData()),
            ArrayUtils.toPrimitive(((YieldCurve) curveFwd[1]).getCurve().getXData()), TOLERANCE_CAL);
    assertArrayEquals("Curve construction: 1 unit / 2 units ",
            ArrayUtils.toPrimitive(((YieldCurve) curveFwd[0]).getCurve().getYData()),
            ArrayUtils.toPrimitive(((YieldCurve) curveFwd[1]).getCurve().getYData()), TOLERANCE_CAL);

    assertEquals("Curve construction: 1 unit / 2 units ", bb[0].getBlock(CURVE_NAME_FWD3_USD).getFirst(),
            bb[1].getBlock(CURVE_NAME_FWD3_USD).getFirst());
    // Test note: the discounting curve building blocks are not the same; in one case both curves are build together in the other one after the other.
    final int nbLineDsc = bb[0].getBlock(CURVE_NAME_DSC_USD).getSecond().getNumberOfRows();
    final int nbLineFwd = bb[0].getBlock(CURVE_NAME_FWD3_USD).getSecond().getNumberOfRows();
    assertEquals("Curve construction: 1 unit / 2 units ",
            bb[1].getBlock(CURVE_NAME_DSC_USD).getSecond().getNumberOfRows(), nbLineDsc);
    assertEquals("Curve construction: 1 unit / 2 units ",
            bb[1].getBlock(CURVE_NAME_FWD3_USD).getSecond().getNumberOfRows(), nbLineFwd);
    for (int loopline = 0; loopline < nbLineFwd; loopline++) {
        assertArrayEquals("Curve construction: 1 unit / 2 units ",
                bb[0].getBlock(CURVE_NAME_FWD3_USD).getSecond().getRowVector(loopline).getData(),
                bb[1].getBlock(CURVE_NAME_FWD3_USD).getSecond().getRowVector(loopline).getData(),
                TOLERANCE_CAL);
        for (int loopcol = 0; loopcol < nbLineDsc; loopcol++) { // Test rely on dsc being first
            assertEquals("Curve construction: 1 unit / 2 units ",
                    bb[0].getBlock(CURVE_NAME_FWD3_USD).getSecond().getRowVector(loopline).getData()[loopcol],
                    bb[1].getBlock(CURVE_NAME_FWD3_USD).getSecond().getRowVector(loopline).getData()[loopcol],
                    TOLERANCE_CAL);
        }
        for (int loopcol = 0; loopcol < nbLineFwd - nbLineDsc; loopcol++) { // Test rely on dsc being first
            assertEquals("Curve construction: 1 unit / 2 units ", 0, bb[1].getBlock(CURVE_NAME_FWD3_USD)
                    .getSecond().getRowVector(loopline).getData()[loopcol + nbLineDsc], TOLERANCE_CAL);
        }
    }
}

From source file:com.stoxx.service.business.registration.RegistrationServiceImpl.java

public User saveUserToLiferayDB(UserProfileDetails userProfileDetails, ThemeDisplay themeDisplay,
        ServiceContext serviceContext) throws STOXXException {
    try {/*from   w w w.  j ava2 s  .  c  o m*/
        Group stoxxNetgroup = GroupLocalServiceUtil.getGroup(themeDisplay.getCompanyId(),
                STOXXConstants.STOXXNET_SITE_NAME);
        Group stoxxgroup = GroupLocalServiceUtil.getGroup(themeDisplay.getCompanyId(),
                STOXXConstants.STOXX_SITE_NAME);
        User adminDefaultUser = UserLocalServiceUtil.getDefaultUser(themeDisplay.getCompanyId());
        logger.info("the ****************************>default user id is " + adminDefaultUser.getUserId()
                + EMAIL_ADDRESS_IS + adminDefaultUser.getEmailAddresses());
        long[] groupIds = null;
        if (userProfileDetails.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_VENDOR_USER)) {
            groupIds = new long[] { stoxxNetgroup.getGroupId() };
        } else if (userProfileDetails.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_GENERAL_USER)
                || userProfileDetails.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)) {
            groupIds = new long[] { stoxxgroup.getGroupId() };
        } else if (userProfileDetails.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_STAFF_USER)) {
            groupIds = new long[] { stoxxNetgroup.getGroupId(), stoxxgroup.getGroupId() };
        }
        User user = null;
        if (!(userProfileDetails.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_VENDOR_USER))) {
            if (userProfileDetails.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)) {
                if (null != userProfileDetails.getSalesEntryId()) {

                    List<Long> roleList = new ArrayList<Long>();
                    Long salesEntryID = userProfileDetails.getSalesEntryId();
                    SalesEntry salesEntry = SalesEntryLocalServiceUtil.getSalesEntry(salesEntryID);
                    if (!(salesEntry.getPackageNames().contains(StringPool.COMMA))) {
                        Role packageRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),
                                salesEntry.getPackageNames().trim());
                        long packageRoleId = packageRole.getRoleId();
                        roleList.add(packageRoleId);
                    } else {
                        for (String packageName : salesEntry.getPackageNames().split(StringPool.COMMA)) {
                            Role packageRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),
                                    packageName.trim());
                            long packageRoleId = packageRole.getRoleId();
                            roleList.add(packageRoleId);
                        }
                    }

                    if (StringUtils.isNotBlank(salesEntry.getKeyEmailAddress())
                            && salesEntry.getKeyEmailAddress().trim()
                                    .equalsIgnoreCase(userProfileDetails.getEmailAddress())) {
                        if (isLicensedUser(userProfileDetails.getEmailAddress())) {
                            Role keyAccntHolderUserRole = RoleLocalServiceUtil.getRole(
                                    themeDisplay.getCompanyId(), STOXXConstants.STOXX_KEY_ACCOUNT_HOLDER_ROLE);
                            long roleKeyAccntHolder = keyAccntHolderUserRole.getRoleId();
                            roleList.add(roleKeyAccntHolder);
                        }
                    }

                    long roleLicensed[] = ArrayUtils.toPrimitive(roleList.toArray(new Long[roleList.size()]));
                    user = UserLocalServiceUtil.addUser(adminDefaultUser.getUserId(),
                            themeDisplay.getCompanyId(), false, userProfileDetails.getPassword(),
                            userProfileDetails.getPassword(), true, StringPool.BLANK,
                            userProfileDetails.getEmailAddress(), 0, StringPool.BLANK, themeDisplay.getLocale(),
                            userProfileDetails.getFirstName(), StringPool.BLANK,
                            userProfileDetails.getLastName(), userProfileDetails.getPrefixId(), 0,
                            userProfileDetails.isGender(), userProfileDetails.getBirthMonth(),
                            userProfileDetails.getBirthDay(), userProfileDetails.getBirthYear(),
                            userProfileDetails.getJobTitle(), groupIds, null, roleLicensed, null, false,
                            serviceContext);
                }
            } else {
                user = UserLocalServiceUtil.addUser(adminDefaultUser.getUserId(), themeDisplay.getCompanyId(),
                        false, userProfileDetails.getPassword(), userProfileDetails.getPassword(), true,
                        StringPool.BLANK, userProfileDetails.getEmailAddress(), 0, StringPool.BLANK,
                        themeDisplay.getLocale(), userProfileDetails.getFirstName(), StringPool.BLANK,
                        userProfileDetails.getLastName(), userProfileDetails.getPrefixId(), 0,
                        userProfileDetails.isGender(), userProfileDetails.getBirthMonth(),
                        userProfileDetails.getBirthDay(), userProfileDetails.getBirthYear(),
                        userProfileDetails.getJobTitle(), groupIds, null, null, null, false, serviceContext);
            }
        }
        Role powerUserRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),
                RoleConstants.POWER_USER);
        if (Validator.isNotNull(powerUserRole)) {
            long rolePower[] = { powerUserRole.getRoleId() };
            if (Validator.isNotNull(user) && rolePower.length > 0) {
                RoleLocalServiceUtil.unsetUserRoles(user.getUserId(), rolePower);
            }
        }
        return user;
    } catch (PortalException e) {
        logger.error(e.getMessage(), e);
        throw new STOXXException(e.getMessage(), e);
    } catch (SystemException e) {
        logger.error(e.getMessage(), e);
        throw new STOXXException(e.getMessage(), e);
    }
}

From source file:aldenjava.opticalmapping.data.data.OptMapDataReader.java

private DataNode parseXML() throws IOException {

    List<Long> reflList = null;
    long[] refl = null;
    String id = null;/*  w w  w.  ja  v a2  s .  c o m*/
    try {
        while (xmlReader.hasNext()) {

            int event = xmlReader.next();
            switch (event) {
            case XMLEvent.START_ELEMENT:
                switch (xmlReader.getLocalName()) {
                case "RESTRICTION_MAP":
                    ;
                    id = xmlReader.getAttributeValue("", "ID");
                    break;
                case "FRAGMENTS":
                    reflList = new ArrayList<Long>();
                    break;
                case "F":
                    reflList.add(Long.parseLong(xmlReader.getAttributeValue("", "S")));
                    break;
                }
                break;
            case XMLEvent.END_ELEMENT:
                switch (xmlReader.getLocalName()) {
                case "RESTRICTION_MAP":
                    ;
                    return new DataNode(id, refl);
                case "FRAGMENTS":
                    refl = ArrayUtils.toPrimitive(reflList.toArray(new Long[reflList.size()]));
                    break;
                case "F":
                    // Nothing to do
                    break;
                }

                break;

            case XMLEvent.START_DOCUMENT:
                break;
            case XMLEvent.END_DOCUMENT:
                return null;

            }

        }

    } catch (XMLStreamException e) {
        throw new IOException("XML parse exception");
    }
    return null;
}