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.newlandframework.avatarmq.core.AckMessageCache.java

public void parallelDispatch(LinkedList<String> list) {
    List<Callable<Long>> tasks = new ArrayList<Callable<Long>>();
    List<Future<Long>> futureList = new ArrayList<Future<Long>>();
    int startPosition = 0;
    Pair<Integer, Integer> pair = calculateBlocks(list.size(), list.size());
    int numberOfThreads = pair.getRight();
    int blocks = pair.getLeft();

    barrier = new CyclicBarrier(numberOfThreads);

    for (int i = 0; i < numberOfThreads; i++) {
        String[] task = new String[blocks];
        System.arraycopy(list.toArray(), startPosition, task, 0, blocks);
        tasks.add(new AckMessageTask(barrier, task));
        startPosition += blocks;/*from w w w . j ava  2s  .  com*/
    }

    ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
    try {
        futureList = executor.invokeAll(tasks);
    } catch (InterruptedException ex) {
        Logger.getLogger(AckMessageCache.class.getName()).log(Level.SEVERE, null, ex);
    }

    for (Future<Long> longFuture : futureList) {
        try {
            succTaskCount += longFuture.get();
        } catch (InterruptedException ex) {
            Logger.getLogger(AckMessageCache.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ExecutionException ex) {
            Logger.getLogger(AckMessageCache.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:appeng.client.render.renderable.ItemRenderable.java

@Override
public void renderTileEntityAt(T te, double x, double y, double z, float partialTicks, int destroyStage) {
    Pair<ItemStack, Matrix4f> pair = f.apply(te);
    if (pair != null && pair.getLeft() != null) {
        GlStateManager.pushMatrix();//w w w  .jav a 2s .  c  om
        if (pair.getRight() != null) {
            FloatBuffer matrix = BufferUtils.createFloatBuffer(16);
            pair.getRight().store(matrix);
            matrix.flip();
            GlStateManager.multMatrix(matrix);
        }
        Minecraft.getMinecraft().getRenderItem().renderItem(pair.getLeft(), TransformType.GROUND);
        GlStateManager.popMatrix();
    }
}

From source file:com.github.tddts.jet.config.spring.postprocessor.EventBusBeanPostProcessor.java

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

    Pair<Class<?>, Object> typeObjectPair = SpringUtil.checkForDinamicProxy(bean);
    Class<?> type = typeObjectPair.getLeft();
    Object target = typeObjectPair.getRight();

    for (Method method : type.getDeclaredMethods()) {

        if (method.isAnnotationPresent(Subscribe.class)) {
            eventBus.register(target);/*from w w w  . jav  a2  s. c  om*/
            logger.debug("Bean registered to EventBus: [" + beanName + "]");
            return bean;
        }
    }
    return bean;
}

From source file:de.johni0702.minecraft.gui.layout.CustomLayout.java

protected void set(GuiElement element, int x, int y, int width, int height) {
    Pair<Point, Dimension> entry = entry(element);
    entry.getLeft().setLocation(x, y);//from w  w w.  j av a 2 s  .c  o m
    entry.getRight().setSize(width, height);
}

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

public static Map<String, Pair<XZ, Double>> performSNRAnalysisAndReturnMetlinIonsRankOrderedBySNRForWells(
        ChemicalToMapOfMetlinIonsToIntensityTimeValues ionToIntensityDataPos,
        List<ChemicalToMapOfMetlinIonsToIntensityTimeValues> ionToIntensityDataNegList,
        Set<Pair<String, Double>> searchMZs) {

    Map<String, Pair<XZ, Double>> result = new HashMap<>();

    for (Pair<String, Double> mz : searchMZs) {

        String chemicalName = mz.getLeft();

        // Compress the input intensity time graph to solve sparse data issues (multiple retention times where intensity
        // is zero). However, we make sure to preserve what the maximum intensity was in that time window in the function
        // called below.
        Pair<List<XZ>, Map<Double, Double>> positiveXZValuesAndMaxIntensity = compressIntensityAndTimeGraphsAndFindMaxIntensityInEveryTimeWindow(
                ionToIntensityDataPos.getMetlinIonsOfChemical(
                        AnalysisHelper.constructChemicalAndScanTypeName(chemicalName, ScanData.KIND.POS_SAMPLE))
                        .get(chemicalName),
                COMPRESSION_CONSTANT);/*from  w  w  w  .ja  va2  s  .  co m*/

        List<XZ> positiveIntensityTimeValues = positiveXZValuesAndMaxIntensity.getLeft();
        Map<Double, Double> positiveTimeToMaxPeak = positiveXZValuesAndMaxIntensity.getRight();

        // Next, we detect peaks within the compressed data.
        List<XZ> positiveIntensityTime = detectPeaksInIntensityTimeWaveform(positiveIntensityTimeValues,
                PEAK_DETECTION_THRESHOLD);

        // Get the compressed results for the negative control data.
        List<List<XZ>> negativeIntensityTimes = new ArrayList<>();
        for (ChemicalToMapOfMetlinIonsToIntensityTimeValues neg : ionToIntensityDataNegList) {
            List<XZ> negativeIntensityTimeValues = compressIntensityAndTimeGraphsAndFindMaxIntensityInEveryTimeWindow(
                    neg.getMetlinIonsOfChemical(AnalysisHelper.constructChemicalAndScanTypeName(chemicalName,
                            ScanData.KIND.NEG_CONTROL)).get(chemicalName),
                    COMPRESSION_CONSTANT).getLeft();

            negativeIntensityTimes.add(negativeIntensityTimeValues);
        }

        // Get the RMS of the negative intensity times
        List<XZ> rmsOfNegativeValues = rmsOfIntensityTimeGraphs(negativeIntensityTimes);

        Double maxSNR = 0.0;
        Double maxTime = 0.0;
        Double peakIntensity = 0.0;

        // For each of the peaks detected in the positive control, find the spectral intensity values from the negative
        // controls and calculate SNR based on that.
        for (XZ positivePosition : positiveIntensityTime) {

            Double time = positivePosition.getTime();

            XZ negativeControlPosition = null;
            for (XZ position : rmsOfNegativeValues) {
                if (position.getTime() > time - POSITION_TIME_WINDOW_IN_SECONDS
                        && position.getTime() < time + POSITION_TIME_WINDOW_IN_SECONDS) {
                    negativeControlPosition = position;
                    break;
                }
            }

            Double snr;
            if (negativeControlPosition == null) {
                LOGGER.error(
                        "There is no intensity value at this time range for the negative control, which is not expected");
                snr = 0.0;
            } else {
                snr = Math.pow(positivePosition.getIntensity() / negativeControlPosition.getIntensity(), 2);
            }

            if (snr > maxSNR) {
                maxSNR = snr;
                maxTime = time;
                peakIntensity = positiveTimeToMaxPeak.get(positivePosition.getTime());
            }
        }

        result.put(chemicalName, Pair.of(new XZ(maxTime, peakIntensity), maxSNR));
    }

    return result;
}

From source file:com.intuit.karate.Script.java

public static AssertionResult matchNamed(MatchType matchType, String name, String path, String expected,
        ScriptContext context) {/*  w  ww . ja v a 2  s.c  om*/
    name = StringUtils.trim(name);
    if (isJsonPath(name) || isXmlPath(name)) { // short-cut for operating on response
        path = name;
        name = ScriptValueMap.VAR_RESPONSE;
    }
    path = StringUtils.trimToNull(path);
    if (path == null) {
        Pair<String, String> pair = parseVariableAndPath(name);
        name = pair.getLeft();
        path = pair.getRight();
    }
    expected = StringUtils.trim(expected);
    if ("header".equals(name)) { // convenience shortcut for asserting against response header
        return matchNamed(matchType, ScriptValueMap.VAR_RESPONSE_HEADERS, "$['" + path + "'][0]", expected,
                context);
    } else {
        ScriptValue actual = context.vars.get(name);
        switch (actual.getType()) {
        case STRING:
        case INPUT_STREAM:
            return matchString(matchType, actual, expected, path, context);

        case XML:
            if ("$".equals(path)) {
                path = "/"; // whole document, also edge case where variable name was 'response'
            }
            if (!isJsonPath(path)) {
                return matchXmlPath(matchType, actual, path, expected, context);
            }
            // break; 
            // fall through to JSON. yes, dot notation can be used on XML !!
        default:
            return matchJsonPath(matchType, actual, path, expected, context);
        }
    }
}

From source file:de.tntinteractive.portalsammler.engine.MapReaderTest.java

@Test
public void testReadEmptyMap() throws Exception {
    final String input = "test123\n" + ".";
    final MapReader r = createReader(input);
    final Pair<String, Map<String, String>> p = r.readNext();
    assertEquals("test123", p.getLeft());
    assertEquals(Collections.emptyMap(), p.getRight());
    assertNull(r.readNext());// w w w.  j a  va  2 s.c o m
}

From source file:de.tudarmstadt.tk.statistics.importer.ExternalResultsReader.java

public static List<SampleData> splitData(SampleData data, StatsConfig config) {

    List<SampleData> splitted = new ArrayList<SampleData>();

    //Use lists instead of sets to maintain order of model metadata
    ArrayList<String> featureSets = new ArrayList<String>();
    ArrayList<String> classifiers = new ArrayList<String>();
    for (Pair<String, String> metadata : data.getModelMetadata()) {
        if (!classifiers.contains(metadata.getLeft())) {
            classifiers.add(metadata.getLeft());
        }//from  ww  w.j  a v  a  2 s  . co m
        if (!featureSets.contains(metadata.getRight())) {
            featureSets.add(metadata.getRight());
        }
    }

    //Only separate data if there's more than one independent variable
    if (!(featureSets.size() > 1 && classifiers.size() > 1)) {
        splitted.add(data);
        return splitted;
    }

    List<String> it = (config
            .getFixIndependentVariable() == StatsConfigConstants.INDEPENDENT_VARIABLES_VALUES.Classifier)
                    ? classifiers
                    : featureSets;
    for (String fixed : it) {
        ArrayList<Pair<String, String>> modelMetadata = new ArrayList<Pair<String, String>>();
        HashMap<String, ArrayList<ArrayList<Double>>> samples = new HashMap<String, ArrayList<ArrayList<Double>>>();
        HashMap<String, ArrayList<Double>> sampleAverages = new HashMap<String, ArrayList<Double>>();
        for (int i = 0; i < data.getModelMetadata().size(); i++) {
            Pair<String, String> model = data.getModelMetadata().get(i);
            boolean eq = (config
                    .getFixIndependentVariable() == StatsConfigConstants.INDEPENDENT_VARIABLES_VALUES.Classifier)
                            ? model.getLeft().equals(fixed)
                            : model.getRight().equals(fixed);
            if (eq) {
                modelMetadata.add(model);
                for (String measure : data.getSamples().keySet()) {
                    if (!samples.containsKey(measure)) {
                        samples.put(measure, new ArrayList<ArrayList<Double>>());
                        sampleAverages.put(measure, new ArrayList<Double>());
                    }
                    samples.get(measure).add(data.getSamples().get(measure).get(i));
                    sampleAverages.get(measure).add(data.getSamplesAverage().get(measure).get(i));
                }
            }
        }
        ArrayList<Pair<String, String>> baselineModelData = new ArrayList<Pair<String, String>>();
        if (data.isBaselineEvaluation()) {
            Pair<String, String> baselineModel = null;
            for (int i = 0; i < data.getBaselineModelMetadata().size(); i++) {
                boolean eq = (config
                        .getFixIndependentVariable() == StatsConfigConstants.INDEPENDENT_VARIABLES_VALUES.Classifier)
                                ? data.getBaselineModelMetadata().get(i).getLeft().equals(fixed)
                                : data.getBaselineModelMetadata().get(i).getRight().equals(fixed);
                if (eq) {
                    baselineModel = data.getBaselineModelMetadata().get(i);
                    break;
                }
            }
            if (baselineModel != null) {
                baselineModelData.add(baselineModel);
                int modelIndex = modelMetadata.indexOf(baselineModel);
                modelMetadata.remove(modelIndex);
                modelMetadata.add(0, baselineModel);
                for (String measure : data.getSamples().keySet()) {
                    ArrayList<Double> s = samples.get(measure).get(modelIndex);
                    samples.get(measure).remove(modelIndex);
                    samples.get(measure).add(0, s);
                    double a = sampleAverages.get(measure).get(modelIndex);
                    sampleAverages.get(measure).remove(modelIndex);
                    sampleAverages.get(measure).add(0, a);
                }
            } else {
                logger.log(Level.ERROR,
                        "Missing baseline model! Please check if baseline indicators are set correctly in the input file, and if they correspond correctly to the fixIndependentVariable property in the configuration. In case of both varying feature sets and classifiers, baseline indicators have to be set multiple times.");
                System.err.println(
                        "Missing baseline model! Please check if baseline indicators are set correctly in the input file, and if they correspond correctly to the fixIndependentVariable property in the configuration. In case of both varying feature sets and classifiers, baseline indicators have to be set multiple times.");
                System.exit(1);
            }
        }
        SampleData newData = new SampleData(null, samples, sampleAverages, data.getDatasetNames(),
                modelMetadata, baselineModelData, data.getPipelineType(), data.getnFolds(),
                data.getnRepetitions());
        splitted.add(newData);
    }
    return splitted;
}

From source file:fr.cnrs.sharp.test.UnificationRuleTest.java

@Test
public void testUnification() {
    Model data = ModelFactory.createDefaultModel();
    InputStream stream = new ByteArrayInputStream(inputGraph.getBytes(StandardCharsets.UTF_8));
    RDFDataMgr.read(data, stream, Lang.TTL);
    data.write(System.out, "TTL");
    logger.info("Graph size / BNodes : " + data.size() + "/" + Unification.countBN(data));

    Assert.assertEquals(13, data.size());
    Assert.assertEquals(3, Unification.countBN(data));

    int nbSubst = 1;
    while (nbSubst > 0) {
        // UNIFICATION : 1. select substitutions
        List<Pair<RDFNode, RDFNode>> toBeMerged = Unification.selectSubstitutions(data);
        nbSubst = toBeMerged.size();/*from w  w  w  .  j  av a 2 s  .c  om*/
        logger.info("Found substitutions: " + nbSubst);

        // UNIFICATION : 2. effectively replacing blank nodes by matching nodes
        for (Pair<RDFNode, RDFNode> p : toBeMerged) {
            Unification.mergeNodes(p.getLeft(), p.getRight().asResource());
        }
        logger.info("Graph size / BNodes with unified PROV inferences: " + data.size() + "/"
                + Unification.countBN(data));

        nbSubst = Unification.selectSubstitutions(data).size();
        logger.info("Found substitutions: " + nbSubst + " after merging");
    }
    data.write(System.out, "TTL");

    Assert.assertEquals(10, data.size());
    Assert.assertEquals(1, Unification.countBN(data));
}

From source file:be.error.rpi.adc.ObjectStatusUdpSender.java

public void send(List<Pair<AdcChannel, ObjectStatusType>> results) throws Exception {
    for (Pair<AdcChannel, ObjectStatusType> pair : results) {
        byte id = (byte) Integer.parseInt(pair.getLeft().getId());
        byte[] toSend = add(new byte[] { id }, pair.getRight().getId());
        DatagramPacket sendPacket = new DatagramPacket(toSend, toSend.length, IPAddress, port);
        clientSocket.send(sendPacket);/*from  ww  w.j  ava 2 s.  c  o  m*/
    }
}