Example usage for org.apache.commons.lang3.tuple Pair getRight

List of usage examples for org.apache.commons.lang3.tuple Pair getRight

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Pair getRight.

Prototype

public abstract R getRight();

Source Link

Document

Gets the right element from this pair.

When treated as a key-value pair, this is the value.

Usage

From source file:com.act.lcms.MS2Simple.java

private List<Pair<MS2Collected, Integer>> filterByMS2PeakMatch(List<Double> ms2SearchMZs,
        List<MS2Collected> scans, Integer pickTopN) {
    List<Pair<MS2Collected, Integer>> results = new ArrayList<>();
    for (MS2Collected scan : scans) {
        Integer matchCount = searchForMatchingPeaks(ms2SearchMZs, scan);
        if (matchCount > 0) {
            results.add(Pair.of(scan, matchCount));
        }//from  ww w .j ava 2s. c  o m
    }

    Collections.sort(results, new Comparator<Pair<MS2Collected, Integer>>() {
        @Override
        public int compare(Pair<MS2Collected, Integer> o1, Pair<MS2Collected, Integer> o2) {
            if (!o1.getRight().equals(o2.getRight())) {
                // Sort in descending order of match count first.
                return o2.getRight().compareTo(o1.getRight());
            }

            // Fall back to sorting on trigger time (in ascending order) to enforce output stability/reproducability.
            return o1.getLeft().triggerTime.compareTo(o2.getLeft().triggerTime);
        }
    });

    if (pickTopN != null && pickTopN > 0 && pickTopN < results.size()) {
        return results.subList(0, pickTopN);
    }
    return results;
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.solversImpl.DagSimSolver.DagSimSolver.java

@Override
protected Pair<Double, Boolean> run(Pair<List<File>, List<File>> pFiles, String remoteName,
        String remoteDirectory) throws Exception {
    if (pFiles.getLeft() == null || pFiles.getLeft().size() != 1) {
        throw new Exception("Model file missing");
    }//from   w w  w.  ja v a 2 s .  c  o m

    if (pFiles.getRight() == null || pFiles.getRight().isEmpty()) {
        throw new Exception("Replayer files missing");
    }

    double result = 0.;
    boolean success = false;
    List<String> remoteMsg = null;

    boolean stillNotOk = true;
    for (int i = 0; stillNotOk && i < MAX_ITERATIONS; ++i) {
        logger.info(remoteName + "-> Starting DagSim resolution on the server");

        File modelFile = pFiles.getLeft().get(0);
        String fileName = modelFile.getName();
        String remotePath = remoteDirectory + File.separator + fileName;

        List<File> workingFiles = pFiles.getRight();
        workingFiles.add(modelFile);
        cleanRemoteSubDirectory(remoteDirectory);
        sendFiles(remoteDirectory, workingFiles);
        logger.debug(remoteName + "-> Working files sent");

        logger.debug(remoteName + "-> Starting DagSim model...");
        String command = String.format("%s %s", connSettings.getSolverPath(), remotePath);
        remoteMsg = connector.exec(command, getClass());

        if (remoteMsg.contains("exit-status: 0")) {
            stillNotOk = false;
            logger.info(remoteName + "-> The remote simulation process completed correctly");
        } else {
            logger.debug(remoteName + "-> Remote exit status: " + remoteMsg);
        }
    }

    if (stillNotOk) {
        logger.info(remoteName + "-> Error in remote simulation on DagSim");
        throw new Exception("Error in the DagSim server");
    } else {
        final String stdout = remoteMsg.get(0);
        final String stderr = remoteMsg.get(1);

        try (Scanner scanner = new Scanner(stdout)) {
            while (!success && scanner.hasNextLine()) {
                Matcher matcher = RESULT_LINE.matcher(scanner.nextLine());
                if (matcher.find()) {
                    result = Double.valueOf(matcher.group("avg"));
                    success = true;
                }
            }
        }

        if (!success) {
            logger.error(String.format("%s -> Error in remote DagSim simulation", remoteName));
            logger.error(String.format("%s -> stdout:\n%s", remoteName, stdout));
            logger.error(String.format("%s -> stderr:\n%s", remoteName, stderr));
        }
    }

    return Pair.of(result, !success);
}

From source file:name.martingeisse.phunky.runtime.code.expression.array.ArrayElementExpression.java

@Override
public Variable resolveOrCreateVariable(final Environment environment) {
    Pair<Variable, String> variableArrayAndKey = obtainArrayVariableAndKey(environment);
    if (variableArrayAndKey == null) {
        return null;
    } else {/*w  w w.  ja v a  2 s.com*/
        PhpVariableArray variableArray = variableArrayAndKey.getLeft()
                .getVariableArray(environment.getRuntime(), getLocation());
        String key = variableArrayAndKey.getRight();
        return variableArray.getOrCreateVariable(key);
    }
}

From source file:com.act.lcms.v2.fullindex.Searcher.java

private List<MZWindow> mzWindowsInRange(Pair<Double, Double> mzRange) {
    List<MZWindow> mzWindowsInRange = new ArrayList<>( // Same here--access by index.
            mzWindows.stream()/* w  ww .j  av  a2  s  .com*/
                    .filter(x -> rangesOverlap(mzRange.getLeft(), mzRange.getRight(), x.getMin(), x.getMax()))
                    .collect(Collectors.toList()));
    if (mzWindowsInRange.size() == 0) {
        LOGGER.warn("Found zero m/z windows in range %.6f - %.6f", mzRange.getLeft(), mzRange.getRight());
    }
    return mzWindowsInRange;
}

From source file:com.act.lcms.plotter.WriteAndPlotMS1Results.java

public void plotFeedings(List<Pair<Double, MS1ScanForWellAndMassCharge>> feedings, String ion, String outPrefix,
        String fmt, String gnuplotFile) throws IOException {
    String outSpectraImg = outPrefix + "." + fmt;
    String outSpectraData = outPrefix + ".data";
    String outFeedingImg = outPrefix + ".fed." + fmt;
    String outFeedingData = outPrefix + ".fed.data";
    String feedingGnuplotFile = gnuplotFile + ".fed";

    boolean useMaxPeak = true;

    // maps that hold the values for across different concentrations
    List<Pair<Double, List<XZ>>> concSpectra = new ArrayList<>();
    List<Pair<Double, Double>> concAreaUnderSpectra = new ArrayList<>();
    List<Pair<Double, Double>> concMaxPeak = new ArrayList<>();

    // we will compute a running max of the intensity in the plot, and integral
    Double maxIntensity = 0.0d, maxAreaUnder = 0.0d;

    // now compute the maps { conc -> spectra } and { conc -> area under spectra }
    for (Pair<Double, MS1ScanForWellAndMassCharge> feedExpr : feedings) {
        Double concentration = feedExpr.getLeft();
        MS1ScanForWellAndMassCharge scan = feedExpr.getRight();

        // get the ms1 spectra for the selected ion, and the max for it as well
        List<XZ> ms1 = scan.getIonsToSpectra().get(ion);
        Double maxInThisSpectra = scan.getMaxIntensityForIon(ion);
        Double areaUnderSpectra = scan.getIntegralForIon(ion);

        // update the max intensity over all different spectra
        maxIntensity = Math.max(maxIntensity, maxInThisSpectra);
        maxAreaUnder = Math.max(maxAreaUnder, areaUnderSpectra);

        // install this concentration and spectra in map, to be dumped to file later
        concSpectra.add(Pair.of(concentration, ms1));
        concAreaUnderSpectra.add(Pair.of(concentration, areaUnderSpectra));
        concMaxPeak.add(Pair.of(concentration, maxInThisSpectra));
    }/*from  www.  j  av  a2 s. c  o  m*/

    // Write data output to outfiles
    List<String> plotID = null;
    try (FileOutputStream outSpectra = new FileOutputStream(outSpectraData)) {
        plotID = writeFeedMS1Values(concSpectra, maxIntensity, outSpectra);
    }

    try (FileOutputStream outFeeding = new FileOutputStream(outFeedingData)) {
        writeFeedMS1Values(useMaxPeak ? concMaxPeak : concAreaUnderSpectra, outFeeding);
    }

    // render outDATA to outPDF using gnuplot
    Gnuplotter gp = new Gnuplotter();
    String[] plotNames = plotID.toArray(new String[plotID.size()]);
    gp.plotOverlayed2D(outSpectraData, outSpectraImg, plotNames, "time", maxIntensity, "intensity", fmt,
            gnuplotFile);
    gp.plot2D(outFeedingData, outFeedingImg, new String[] { "feeding ramp" }, "concentration",
            useMaxPeak ? maxIntensity : maxAreaUnder, "integrated area under spectra", fmt, null, null, null,
            feedingGnuplotFile);
}

From source file:com.twitter.distributedlog.TestTruncate.java

@Test
public void testTruncation() throws Exception {
    String name = "distrlog-truncation";

    long txid = 1;
    Map<Long, DLSN> txid2DLSN = new HashMap<Long, DLSN>();
    Pair<DistributedLogManager, AsyncLogWriter> pair = populateData(txid2DLSN, conf, name, 4, 10, true);

    Thread.sleep(1000);/*  w w w  . j  a v a2  s .c o m*/

    // delete invalid dlsn
    assertFalse(Await.result(pair.getRight().truncate(DLSN.InvalidDLSN)));
    verifyEntries(name, 1, 1, 5 * 10);

    for (int i = 1; i <= 4; i++) {
        int txn = (i - 1) * 10 + i;
        DLSN dlsn = txid2DLSN.get((long) txn);
        assertTrue(Await.result(pair.getRight().truncate(dlsn)));
        verifyEntries(name, 1, (i - 1) * 10 + 1, (5 - i + 1) * 10);
    }

    // Delete higher dlsn
    int txn = 43;
    DLSN dlsn = txid2DLSN.get((long) txn);
    assertTrue(Await.result(pair.getRight().truncate(dlsn)));
    verifyEntries(name, 1, 31, 20);

    Utils.close(pair.getRight());
    pair.getLeft().close();
}

From source file:com.sludev.commons.vfs2.provider.s3.SS3FileObject.java

/**
 * Callback for handling delete on this File Object
 * @throws Exception //from w ww  .  j a v  a  2 s.c  o  m
 */
@Override
protected void doDelete() throws Exception {
    Pair<String, String> path = getContainerAndPath();

    // Purposely use the more restrictive delete() over deleteIfExists()
    fileSystem.getClient().deleteObject(path.getLeft(), path.getRight());
}

From source file:com.act.lcms.db.analysis.PathwayProductAnalysis.java

private static Map<Integer, String> extractPathwayStepIonsFromStandardIonAnalysis(
        List<ChemicalAssociatedWithPathway> pathwayChems, File lcmsDir, DB db, List<StandardWell> standardWells,
        String plottingDir, Map<Integer, Pair<Boolean, Boolean>> ionModesAvailable) throws Exception {

    Map<Integer, String> result = new HashMap<>();

    for (ChemicalAssociatedWithPathway pathwayChem : pathwayChems) {

        Map<StandardWell, StandardIonResult> wellToIonRanking = StandardIonAnalysis
                .getBestMetlinIonsForChemical(pathwayChem.getChemical(), lcmsDir, db, standardWells,
                        plottingDir);/*  w  w  w .ja  va  2s  .  co  m*/

        Pair<Boolean, Boolean> modes = ionModesAvailable.get(pathwayChem.getId());

        Map<StandardIonResult, String> chemicalToCuratedMetlinIon = new HashMap<>();
        List<StandardIonResult> standardIonResults = new ArrayList<>(wellToIonRanking.values());

        for (StandardIonResult standardIonResult : standardIonResults) {
            Integer manualOverrideId = standardIonResult.getManualOverrideId();
            if (manualOverrideId != null) {
                chemicalToCuratedMetlinIon.put(standardIonResult,
                        CuratedStandardMetlinIon.getBestMetlinIon(db, manualOverrideId).getBestMetlinIon());
            }
        }

        String bestMetlinIon = AnalysisHelper.scoreAndReturnBestMetlinIonFromStandardIonResults(
                standardIonResults, chemicalToCuratedMetlinIon, modes.getLeft(), modes.getRight());

        if (bestMetlinIon != null) {
            result.put(pathwayChem.getId(), bestMetlinIon);
        } else {
            result.put(pathwayChem.getId(), DEFAULT_SEARCH_ION);
        }
    }
    return result;
}

From source file:com.epam.ngb.cli.manager.command.handler.http.FileRegistrationHandler.java

private RegistrationRequest createRegistrationRequest(Pair<String, String> file,
        BiologicalDataItemFormat format) {
    RegistrationRequest registration = new RegistrationRequest();
    registration.setName(fileName);//from  w w w.  j  av  a  2  s  . c om
    registration.setPrettyName(prettyName);
    registration.setPath(file.getLeft());
    registration.setIndexPath(file.getRight());
    registration.setReferenceId(referenceId);
    registration.setType(BiologicalDataItemResourceType.getTypeFromPath(file.getKey()));

    if (file.getValue() != null) {
        registration.setIndexType(BiologicalDataItemResourceType.getTypeFromPath(file.getValue()));
    }

    if (format == BiologicalDataItemFormat.VCF || format == BiologicalDataItemFormat.GENE) {
        registration.setDoIndex(doIndex);
    }
    return registration;
}

From source file:net.malisis.blocks.tileentity.SwapperTileEntity.java

private void applyState(BlockPos pos, Pair<IBlockState, NBTTagCompound> state) {
    if (getWorld().getBlockState(pos).getBlock() == Blocks.bedrock)
        return;/*from   w w  w .j a v a  2 s  .  com*/

    clearWorldState(pos);
    getWorld().setBlockState(pos, state.getLeft() != null ? state.getLeft() : Blocks.air.getDefaultState(), 0);
    TileEntity te = getWorld().getTileEntity(pos);
    if (te != null && state.getRight() != null)
        te.readFromNBT(state.getRight());
}