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.teambr.bookshelf.client.gui.component.control.GuiComponentSideSelector.java

/**
 * Draws the highlights onto the block/*from   w w  w. ja va2 s .com*/
 * @param selections The colors to render
 */
private void drawHighlights(List<Pair<SidePicker.Side, Color>> selections) {
    GlStateManager.disableLighting();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.enableBlend();
    GlStateManager.enableAlpha();
    GlStateManager.disableDepth();
    GlStateManager.disableTexture2D();

    GL11.glBegin(GL11.GL_QUADS);
    for (Pair<SidePicker.Side, Color> pair : selections) {
        if (pair.getRight() != null)
            RenderUtils.setColor(pair.getRight());

        switch (pair.getLeft()) {
        case XPos:
            GL11.glVertex3d(0.5, -0.5, -0.5);
            GL11.glVertex3d(0.5, 0.5, -0.5);
            GL11.glVertex3d(0.5, 0.5, 0.5);
            GL11.glVertex3d(0.5, -0.5, 0.5);
            break;
        case YPos:
            GL11.glVertex3d(-0.5, 0.5, -0.5);
            GL11.glVertex3d(-0.5, 0.5, 0.5);
            GL11.glVertex3d(0.5, 0.5, 0.5);
            GL11.glVertex3d(0.5, 0.5, -0.5);
            break;
        case ZPos:
            GL11.glVertex3d(-0.5, -0.5, 0.5);
            GL11.glVertex3d(0.5, -0.5, 0.5);
            GL11.glVertex3d(0.5, 0.5, 0.5);
            GL11.glVertex3d(-0.5, 0.5, 0.5);
            break;
        case XNeg:
            GL11.glVertex3d(-0.5, -0.5, -0.5);
            GL11.glVertex3d(-0.5, -0.5, 0.5);
            GL11.glVertex3d(-0.5, 0.5, 0.5);
            GL11.glVertex3d(-0.5, 0.5, -0.5);
            break;
        case YNeg:
            GL11.glVertex3d(-0.5, -0.5, -0.5);
            GL11.glVertex3d(0.5, -0.5, -0.5);
            GL11.glVertex3d(0.5, -0.5, 0.5);
            GL11.glVertex3d(-0.5, -0.5, 0.5);
            break;
        case ZNeg:
            GL11.glVertex3d(-0.5, -0.5, -0.5);
            GL11.glVertex3d(-0.5, 0.5, -0.5);
            GL11.glVertex3d(0.5, 0.5, -0.5);
            GL11.glVertex3d(0.5, -0.5, -0.5);
            break;
        default:
        }
    }

    GL11.glEnd();

    GlStateManager.disableBlend();
    GlStateManager.enableDepth();
    GlStateManager.enableTexture2D();
}

From source file:mase.spec.BasicHybridExchangerDunn.java

@Override
protected void mergeProcess(EvolutionState state) {
    List<BehaviourResult>[] mpBehavs = new List[metaPops.size()];
    for (int i = 0; i < metaPops.size(); i++) {
        MetaPopulation mp = metaPops.get(i);
        Individual[] inds = getElitePortion(mp.inds, (int) Math.ceil(elitePortion * popSize));
        mpBehavs[i] = new ArrayList<BehaviourResult>(mp.agents.size() * inds.length);
        for (Individual ind : inds) {
            for (Integer a : mp.agents) {
                mpBehavs[i].add(getAgentBR(ind, a));
            }/* www . j av a2s.  c o  m*/
        }
    }
    distanceMatrix = distanceMatrix(mpBehavs, state);
    Pair<MetaPopulation, MetaPopulation> nextMerge = metaPops.size() >= 3 ? findNextMerge(distanceMatrix, state)
            : null;

    // Merge if they are similar
    if (nextMerge != null) {
        state.output.message("*************************** Merging " + nextMerge.getLeft() + " with "
                + nextMerge.getRight() + " ***************************");
        merges++;
        MetaPopulation mpNew = mergePopulations(nextMerge.getLeft(), nextMerge.getRight(), state);
        metaPops.remove(nextMerge.getLeft());
        metaPops.remove(nextMerge.getRight());
        metaPops.add(mpNew);
    }
}

From source file:com.act.lcms.v2.MassChargeCalculatorTest.java

@Test
public void testComputeMass() throws Exception {
    List<Pair<MassChargeCalculator.MZSource, Double>> testCases = Arrays.asList(
            Pair.of(new MassChargeCalculator.MZSource(
                    "InChI=1S/C8H9NO2/c1-6(10)9-7-2-4-8(11)5-3-7/h2-5,11H,1H3,(H,9,10)"), 151.063329),
            Pair.of(new MassChargeCalculator.MZSource(151.063329), 151.063329),
            Pair.of(new MassChargeCalculator.MZSource(Pair.of("APAP", 151.063329)), 151.063329));

    for (Pair<MassChargeCalculator.MZSource, Double> testCase : testCases) {
        Double actualMass = MassChargeCalculator.computeMass(testCase.getLeft());
        assertEquals(//from  w  w  w  .j  a  v a  2  s  . com
                String.format("(Case %d) Actual mass is within bounds: %.6f ~ %.6f", testCase.getLeft().getId(),
                        testCase.getRight(), actualMass),
                testCase.getRight(), actualMass, MASS_ERROR_TOLERANCE);
    }
}

From source file:edu.uci.ics.hyracks.api.rewriter.runtime.SuperActivityOperatorNodePushable.java

@Override
public IFrameWriter getInputFrameWriter(final int index) {
    /**/*  w  ww. j  a va 2s. com*/
     * get the right IFrameWriter from the cluster input index
     */
    Pair<ActivityId, Integer> activityIdInputIndex = parent.getActivityIdInputIndex(index);
    IOperatorNodePushable operatorNodePushable = operatorNodePushables.get(activityIdInputIndex.getLeft());
    IFrameWriter writer = operatorNodePushable.getInputFrameWriter(activityIdInputIndex.getRight());
    return writer;
}

From source file:de.ks.activity.context.ActivityContext.java

@Override
public <T> T get(Contextual<T> contextual) {
    if (contextual instanceof Bean) {
        Bean bean = (Bean) contextual;//from   www.j a v a2 s .  c o  m

        Pair<String, Class<?>> key = getKey(bean);
        lock.readLock().lock();
        try {
            StoredBean storedBean = activities.get(key.getLeft()).getStoredBean(key.getRight());
            if (storedBean != null) {
                return storedBean.getInstance();
            }
        } finally {
            lock.readLock().unlock();
        }
    }
    return null;
}

From source file:im.dadoo.cedar.SelectCriteria.java

private String makeConditionSql(Condition condition) {
    StringBuilder sb = new StringBuilder();
    if (condition != null && condition.getField() != null && condition.getOp() != null
            && condition.getValue() != null) {
        switch (condition.getOp()) {
        case EQ:// www  .  j a  v a  2  s .c o m
        case GT:
        case LT:
            sb.append(condition.getField()).append(" ").append(condition.getOp().getWord()).append(" ")
                    .append(condition.getValue());
            break;
        case IN:
            String temp = null;
            //??
            if (condition.getValue() instanceof String) {
                temp = (String) condition.getValue();
            } else if (condition.getValue() instanceof SelectCriteria) {
                temp = ((SelectCriteria) condition.getValue()).sql();
            }
            sb.append(condition.getField()).append(" ").append(condition.getOp().getWord()).append(" ")
                    .append("( ").append(temp).append(" )");
            break;
        case BETWEEN:
            Pair<String, String> pair = (Pair<String, String>) condition.getValue();
            sb.append(condition.getField()).append(" ").append(condition.getOp().getWord()).append(" ")
                    .append(pair.getLeft()).append(" ").append("AND").append(" ").append(pair.getRight());
            break;
        }
    }
    return sb.toString();
}

From source file:ca.craigthomas.visualclassifier.commandline.TrainCommand.java

public void execute() {
    NeuralNetwork bestModel = null;//  www  .j av a  2s. c  o m
    DataSet bestFold = null;
    double[] tp = new double[arguments.folds];
    double[] fp = new double[arguments.folds];
    double[] tn = new double[arguments.folds];
    double[] fn = new double[arguments.folds];
    double[] precision = new double[arguments.folds];
    double[] recall = new double[arguments.folds];
    double[] f1 = new double[arguments.folds];
    double bestF1 = 0;

    // Step 1: create the dataset
    if (!arguments.csvFile.isEmpty()) {
        loadFromCSV();
    } else {
        loadFromDirectories();
    }

    if (mDataSet == null) {
        LOGGER.log(Level.SEVERE, "no data set could be built, exiting");
        return;
    }

    // Step 2: Generate layer information
    List<Integer> layerSizes = new ArrayList<>();
    layerSizes.add(mDataSet.getNumColsSamples());
    if (arguments.layer1 != 0) {
        layerSizes.add(arguments.layer1);
    }
    if (arguments.layer2 != 0) {
        layerSizes.add(arguments.layer2);
    }
    layerSizes.add(arguments.outputLayer);

    // Step 3: generate the folds and train the model
    for (int fold = 0; fold < arguments.folds; fold++) {
        LOGGER.log(Level.INFO, "processing fold " + (fold + 1));
        LOGGER.log(Level.INFO, "randomizing dataset");
        mDataSet.randomize();
        LOGGER.log(Level.INFO, "generating training and testing sets");
        Pair<DataSet, DataSet> split = mDataSet.splitEqually(arguments.split);
        DataSet trainingData = split.getLeft();
        DataSet testingData = split.getRight();
        LOGGER.log(Level.INFO, "training neural network...");
        trainingData.randomize();
        Trainer trainer = new Trainer.Builder(layerSizes, trainingData).maxIterations(arguments.iterations)
                .heartBeat(arguments.heartBeat).learningRate(arguments.learningRate).lambda(arguments.lambda)
                .build();
        trainer.train();

        // Step 4: evaluate each model
        NeuralNetwork model = trainer.getNeuralNetwork();
        Prediction prediction = new Prediction(model, arguments.predictionThreshold);
        prediction.predict(testingData);
        System.out.println("True Positives " + prediction.getTruePositives());
        System.out.println("False Positives " + prediction.getFalsePositives());
        System.out.println("True Negatives " + prediction.getTrueNegatives());
        System.out.println("False Negatives " + prediction.getFalseNegatives());
        System.out.println("Precision " + prediction.getPrecision());
        System.out.println("Recall " + prediction.getRecall());
        System.out.println("F1 " + prediction.getF1());

        tp[fold] = prediction.getTruePositives();
        fp[fold] = prediction.getFalsePositives();
        tn[fold] = prediction.getTrueNegatives();
        fn[fold] = prediction.getFalseNegatives();
        precision[fold] = prediction.getPrecision();
        recall[fold] = prediction.getRecall();
        f1[fold] = prediction.getF1();
        if (f1[fold] > bestF1) {
            bestModel = model;
            bestFold = mDataSet.dup();
            bestF1 = f1[fold];
        }
    }

    // Step 6: save the best information to the specified directory
    if (!arguments.saveDir.isEmpty()) {
        saveResults(bestModel, bestFold);
    }

    // Step 5: compute the overall statistics
    System.out.println("Overall Statistics");
    System.out.println("True Positives " + StatUtils.mean(tp) + " (" + StatUtils.variance(tp) + ")");
    System.out.println("False Positives " + StatUtils.mean(fp) + " (" + StatUtils.variance(fp) + ")");
    System.out.println("True Negatives " + StatUtils.mean(tn) + " (" + StatUtils.variance(tn) + ")");
    System.out.println("False Negatives " + StatUtils.mean(fn) + " (" + StatUtils.variance(fn) + ")");
    System.out.println("Precision " + StatUtils.mean(precision) + " (" + StatUtils.variance(precision) + ")");
    System.out.println("Recall " + StatUtils.mean(recall) + " (" + StatUtils.variance(recall) + ")");
    System.out.println("F1 " + StatUtils.mean(f1) + " (" + StatUtils.variance(f1) + ")");
}

From source file:com.streamsets.pipeline.stage.executor.jdbc.TestJdbcQueryExecutor.java

/**
 * Validate structure of the result set (column names and types).
 *///from   w ww . j a va2 s. com
public void assertResultSetStructure(ResultSet rs, Pair<String, Integer>... columns) throws Exception {
    ResultSetMetaData metaData = rs.getMetaData();
    Assert.assertEquals(Utils.format("Unexpected number of columns"), columns.length,
            metaData.getColumnCount());
    int i = 1;
    for (Pair<String, Integer> column : columns) {
        Assert.assertEquals(Utils.format("Unexpected name for column {}", i), column.getLeft(),
                metaData.getColumnName(i));
        Assert.assertEquals(Utils.format("Unexpected type for column {}", i), (int) column.getRight(),
                metaData.getColumnType(i));
        i++;
    }
}

From source file:com.cisco.oss.foundation.message.FoundationQueueConsumerFailureListener.java

@Override
public void connectionFailed(HornetQException exception, boolean failedOver) {
    LOGGER.error("failed connection: {}, failing over: {}", exception, failedOver);
    if (!failedOver) {

        boolean done = false;

        while (!done) {

            LOGGER.trace("attempting to reconnect to HornetQ");
            HornetQMessagingFactory.sessionThreadLocal.set(null);
            try {
                //                    FoundationQueueConsumerFailureListener foundationQueueConsumerFailureListener = new FoundationQueueConsumerFailureListener();;
                MessageHandler handler = null;
                if (this.messageHandler == null) {
                    handler = clientConsumer.getMessageHandler();
                    this.messageHandler = handler;
                }//from ww w  . jav a2 s .co  m
                for (Pair<ClientSession, SessionFailureListener> clientSessionSessionFailureListenerPair : HornetQMessagingFactory
                        .getSession(FoundationQueueConsumerFailureListener.class)) {
                    FoundationQueueConsumerFailureListener foundationQueueConsumerFailureListener = (FoundationQueueConsumerFailureListener) clientSessionSessionFailureListenerPair
                            .getRight();
                    foundationQueueConsumerFailureListener.setReconnectProperties(queueName, clientConsumer);
                    foundationQueueConsumerFailureListener.setMessageHandler(messageHandler);
                    ClientConsumer consumer = clientSessionSessionFailureListenerPair.getLeft()
                            .createConsumer(queueName);
                    consumer.setMessageHandler(messageHandler);
                }
                done = true;
            } catch (Exception e) {
                LOGGER.trace("failed to reconnect. retrying...", e);
                try {
                    Thread.sleep(ConfigurationFactory.getConfiguration()
                            .getInt("service.hornetq.attachRetryDelay", 10000));
                } catch (InterruptedException e1) {
                    LOGGER.trace("thread interrupted!!!", e1);
                }
            }
        }

    }
}

From source file:com.jaspersoft.jasperserver.jrsh.completion.completer.RepositoryNameCompleter.java

@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
    if (buffer != null && cursor < buffer.length()) {
        candidates.add("");
        return buffer.length();
    }/*  w  w w  .  ja va 2  s . c  om*/

    if (uniqueId == 0) {
        uniqueId = hashCode();
    }

    if (buffer == null) {
        candidates.add("/");
        return 0;
    } else {
        if (uniqueId == hashCode()) {
            if (buffer.isEmpty()) {
                return 0;
            }
            List<Pair<String, Boolean>> resources;
            List<String> filteredResources;
            try {
                if (isResourceExist(buffer)) {
                    resources = download(buffer);
                    if (!resources.isEmpty() && !buffer.equals("/")) {
                        return buffer.length() + 1;
                    }
                    fillResources(candidates, resources);
                } else {
                    String root = getPreviousPath(buffer);
                    if (isResourceExist(root)) {
                        resources = download(root);
                        List<Pair<String, Boolean>> temp = new ArrayList<>();

                        for (Pair<String, Boolean> pair : resources) {
                            String resource = pair.getKey();
                            Boolean isFolder = pair.getRight();
                            if (startsWith(resource, buffer)) {
                                ImmutablePair<String, Boolean> newPair = new ImmutablePair<>(resource,
                                        isFolder);
                                temp.add(newPair);
                            }
                        }
                        fillResources(candidates, temp);
                    } else {
                        String lastInput = getLastInput(buffer);
                        if ("".equals(lastInput)) {
                            List<Pair<String, Boolean>> temp = new ArrayList<>();
                            ImmutablePair<String, Boolean> newPair = new ImmutablePair<>("", false);
                            temp.add(newPair);
                            fillResources(candidates, temp);
                            return buffer.length();
                        }
                    }
                }
            } catch (AuthenticationFailedException e3) {
                SessionUtil.reopenSession();
                complete(buffer, cursor, candidates);
            }
            if (candidates.size() == 1) {
                return buffer.lastIndexOf("/") + 1;
            }
            if (candidates.size() > 1) {
                String lastInput = getLastInput(buffer);
                if (compareCandidatesWithLastInput(lastInput, candidates)) {
                    return buffer.length() - lastInput.length();
                }
            }
            return buffer.length();
        } else {
            candidates.addAll(bufCandidates);
            if (candidates.size() > 0) {
                String lastInput = getLastInput(buffer);
                if (compareCandidatesWithLastInput(lastInput, candidates)) {
                    return buffer.length() - lastInput.length();
                }
            }
            return buffer.length();
        }
    }
}