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

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

Introduction

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

Prototype

public static <L, R> Pair<L, R> of(final L left, final R right) 

Source Link

Document

Obtains an immutable pair of from two objects inferring the generic types.

This factory allows the pair to be created using inference to obtain the generic types.

Usage

From source file:de.tudarmstadt.tk.statistics.helper.Helpers.java

/**
 * Remove models with the worst performance measures from the sample data if
 * the no. of models exceeds a certain threshold. If a baseline evaluation
 * is performed, the baseline model is retained. If the number of models
 * does not exceed the specified threshold, nothing happens.
 * //from   w  w w.  ja  v a2  s  . c o m
 * @param sampleData
 *            An object of type {@link StatisticalEvaluationData}
 * @param selectBestN
 *            Maximum number of models
 * @param selectByMeasure
 *            Measure by which to select the models
 * @return the truncated SampleData object
 */
public static SampleData truncateData(SampleData sampleData, int selectBestN, String selectByMeasure) {

    int nModels = sampleData.getModelMetadata().size();

    // Only select a subset of the data if there're more models than the
    // specified maximum
    if (nModels > selectBestN && nModels > 1) {

        // Get sample averages
        ArrayList<Double> sampleAverages = sampleData.getSamplesAverage().get(selectByMeasure);
        if (sampleAverages == null) {
            sampleAverages = sampleData.getSamplesAverage().get("Averaged " + selectByMeasure);
        }

        if (sampleAverages == null) {
            logger.log(Level.ERROR, "Measure for model selection not available in sample data! No selection.");
            return sampleData;
        }

        // Sort them
        ArrayList<Pair<Integer, Double>> sortedAvgs = new ArrayList<Pair<Integer, Double>>();
        for (int i = 0; i < sampleAverages.size(); i++) {
            sortedAvgs.add(Pair.of(i, sampleAverages.get(i)));
        }

        Collections.sort(sortedAvgs, new PairValueComparator());

        ArrayList<Integer> obsolete = new ArrayList<Integer>();
        for (int i = 0; i < sortedAvgs.size() - selectBestN; i++) {
            int toBeRemoved = sortedAvgs.get(i).getKey();
            // If this is a baseline evaluation, do not remove the baseline
            // model
            if (sampleData.isBaselineEvaluation() && toBeRemoved == 0) {
                continue;
            }
            obsolete.add(toBeRemoved);
        }

        Collections.sort(obsolete);
        Collections.reverse(obsolete);

        // Remove obsolete samples
        Iterator<String> itm = sampleData.getSamplesAverage().keySet().iterator();
        while (itm.hasNext()) {
            String measure = itm.next();
            for (int i = 0; i < obsolete.size(); i++) {
                sampleData.getSamplesAverage().get(measure).remove((int) obsolete.get(i));
                sampleData.getSamples().get(measure).remove((int) obsolete.get(i));
            }
        }
        // Remove obsolete model metadata
        for (int i = 0; i < obsolete.size(); i++) {
            sampleData.getModelMetadata().remove((int) obsolete.get(i));
        }

    }

    return sampleData;
}

From source file:io.cloudslang.lang.runtime.bindings.AbstractBinding.java

protected Value getEvalResultForMap(Value evalResult, LoopStatement loopStatement,
        String collectionExpression) {
    if (loopStatement instanceof MapLoopStatement) {
        if (evalResult != null && evalResult.get() instanceof Map) {
            List<Value> entriesAsValues = new ArrayList<>();
            @SuppressWarnings("unchecked")
            Set<Map.Entry<Serializable, Serializable>> entrySet = ((Map) evalResult.get()).entrySet();

            for (Map.Entry<Serializable, Serializable> entry : entrySet) {
                entriesAsValues.add(ValueFactory
                        .create(Pair.of(ValueFactory.create(entry.getKey(), evalResult.isSensitive()),
                                ValueFactory.create(entry.getValue(), evalResult.isSensitive()))));
            }/*  ww w.ja  v  a2  s  . c om*/
            evalResult = ValueFactory.create((Serializable) entriesAsValues);
        } else {
            throw new RuntimeException(
                    LoopsBinding.INVALID_MAP_EXPRESSION_MESSAGE + ": " + collectionExpression);
        }
    }
    return evalResult;
}

From source file:com.yahoo.bullet.tracing.FilterRuleTest.java

@Test
public void testNoAggregationAttempted() {
    FilterRule rule = getFilterRule(makeRawFullRule("map_field.id", Arrays.asList("1", "23"), FilterType.EQUALS,
            AggregationType.RAW, Aggregation.DEFAULT_MAX_SIZE, Pair.of("map_field.id", "mid")), emptyMap());

    RecordBox boxA = RecordBox.get().addMap("map_field", Pair.of("id", "23"));
    RecordBox expectedA = RecordBox.get().add("mid", "23");
    Assert.assertTrue(rule.consume(boxA.getRecord()));
    Assert.assertEquals(rule.getData(), getListBytes(expectedA.getRecord()));

    RecordBox boxB = RecordBox.get().addMap("map_field", Pair.of("id", "3"));
    Assert.assertFalse(rule.consume(boxB.getRecord()));
    Assert.assertNull(rule.getData());//from w  w  w .j  a  va 2  s .c om

    RecordBox boxC = RecordBox.get().addMap("map_field", Pair.of("id", "1"));
    RecordBox expectedC = RecordBox.get().add("mid", "1");
    Assert.assertTrue(rule.consume(boxC.getRecord()));
    Assert.assertEquals(rule.getData(), getListBytes(expectedC.getRecord()));
}

From source file:ee.ria.xroad.common.RequestInputDataSimple.java

@Override
public Pair<String, InputStream> getRequestInput() {
    try {/*from  w  w  w  .  j a v a2  s.c o m*/
        return Pair.of(contentType, getRequestContentInputStream());
    } catch (Exception e) {
        throw new RuntimeException("Cannot create request input", e);
    }
}

From source file:flens.input.SocketInput.java

@Override
public Pair<String, DataInputStream> getStream(Socket newSocket) throws IOException {
    String hostname = newSocket.getInetAddress().getHostName();
    return Pair.of(hostname, new DataInputStream(newSocket.getInputStream()));
}

From source file:com.github.blindpirate.gogradle.util.MapUtils.java

@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> asMapWithoutNull(K k1, V v1, K k2, V v2) {
    return asMapWithoutNull(new Pair[] { Pair.of(k1, v1), Pair.of(k2, v2) });
}

From source file:net.mindengine.blogix.tests.RequestSampleParser.java

public void done() {
    if (!url.trim().isEmpty()) {
        samples.add(Pair.of(url, response.toString()));
    }
}

From source file:hu.ppke.itk.nlpg.purepos.common.lemma.AbstractLemmaTransformation.java

@Override
public Pair<String, Integer> analyze(String word) {
    Pair<String, Integer> ret = encode(word, representation);
    return Pair.of(postprocess(ret.getLeft()), ret.getRight());

}

From source file:com.yahoo.bullet.result.ClipTest.java

@Test
public void testRecordsAddition() {
    BulletRecord record = new RecordBox().add("field", "sample").addMap("map_field", Pair.of("foo", "bar"))
            .addList("list_field", new HashMap<>(), singletonMap("foo", 1L)).getRecord();

    BulletRecord another = new RecordBox().add("field", "another").getRecord();

    List<BulletRecord> list = new ArrayList<>();
    list.add(another);/* ww w. j  a va2  s .c om*/
    list.add(record);
    assertJSONEquals(Clip.of(list).asJSON(), makeJSON(
            "[{'field':'another'}, {'list_field':[{},{'foo':1}],'field':'sample','map_field':{'foo':'bar'}}]"));
}

From source file:cherry.sqlman.tool.statement.SqlStatementSupport.java

public Pair<PageSet, ResultSet> search(SqlStatementForm form) {
    String databaseName = form.getDatabaseName();
    String sql = form.getSql();/*from  ww w  .j a v  a  2s . c om*/
    Map<String, ?> paramMap = paramParser.parseMap(form.getParamMap());

    ResultSet resultSet = new ResultSet();
    PageSet ps = execQueryService.query(databaseName, sql, paramMap, resultSet);

    return Pair.of(ps, resultSet);
}