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

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

Introduction

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

Prototype

public abstract L getLeft();

Source Link

Document

Gets the left element from this pair.

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

Usage

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

public void plotSpectra(Map<String, List<XZ>> ms1s, Double maxIntensity,
        Map<String, Double> individualMaxIntensities, Map<String, Double> metlinMzs, String outPrefix,
        String fmt, boolean makeHeatmap, boolean overlayPlots) throws IOException {

    String outImg = outPrefix + "." + fmt;
    String outData = outPrefix + ".data";

    // Write data output to outfile
    try (FileOutputStream out = new FileOutputStream(outData)) {
        List<Pair<String, String>> ionAndplotID = writeMS1Values(ms1s, maxIntensity, metlinMzs, out,
                makeHeatmap);//from w  ww.j  a  v a 2s .  c o m

        // writeMS1Values picks an ordering of the plots.
        // create two new sets plotID and yMaxes that have the matching ordering
        // and contain plotNames, and yRanges respectively
        List<Double> yMaxesInSameOrderAsPlots = new ArrayList<>();
        List<String> plotID = new ArrayList<>();
        for (Pair<String, String> plot : ionAndplotID) {
            String ion = plot.getLeft();
            Double yMax = individualMaxIntensities.get(ion);
            yMaxesInSameOrderAsPlots.add(yMax);
            plotID.add(plot.getRight());
        }
        Double[] yMaxes = yMaxesInSameOrderAsPlots.toArray(new Double[yMaxesInSameOrderAsPlots.size()]);

        // render outDATA to outPDF using gnuplot
        Gnuplotter gp = new Gnuplotter();
        String[] plotNames = plotID.toArray(new String[plotID.size()]);

        if (makeHeatmap) {
            gp.plotHeatmap(outData, outImg, plotNames, maxIntensity, fmt);
        } else {
            if (!overlayPlots) {
                gp.plot2D(outData, outImg, plotNames, "time", maxIntensity, "intensity", fmt, null, null,
                        yMaxes, outImg + ".gnuplot");
            } else {
                gp.plotOverlayed2D(outData, outImg, plotNames, "time", maxIntensity, "intensity", fmt,
                        outImg + ".gnuplot");
            }
        }
    }
}

From source file:com.formkiq.core.util.StringsTest.java

/**
 * testExtractLabelAndValue01()./*from w w w  .  j  a  v a2s  .c  o  m*/
 */
@Test
public void testExtractLabelAndValue01() {
    // given
    String s = "name[1]";

    // when
    Pair<String, String> results = Strings.extractLabelAndValue(s);

    // then
    assertEquals("name", results.getLeft());
    assertEquals("1", results.getRight());
}

From source file:com.formkiq.core.util.StringsTest.java

/**
 * testExtractLabelAndValue02().//  w w w . ja v  a 2 s  .  c  o m
 */
@Test
public void testExtractLabelAndValue02() {
    // given
    String s = "name";

    // when
    Pair<String, String> results = Strings.extractLabelAndValue(s);

    // then
    assertEquals("name", results.getLeft());
    assertEquals("name", results.getRight());
}

From source file:com.twitter.distributedlog.service.DistributedLogCluster.java

private DistributedLogCluster(DistributedLogConfiguration dlConf, ServerConfiguration bkConf, int numBookies,
        boolean shouldStartZK, String zkServers, int zkPort, boolean shouldStartProxy, int proxyPort)
        throws Exception {
    this.dlConf = dlConf;
    if (shouldStartZK) {
        File zkTmpDir = IOUtils.createTempDir("zookeeper", "distrlog");
        tmpDirs.add(zkTmpDir);//from w  ww .  ja v  a  2  s .  c o  m
        if (0 == zkPort) {
            Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkTmpDir);
            this.zks = serverAndPort.getLeft();
            zkPort = serverAndPort.getRight();
        } else {
            this.zks = LocalBookKeeper.runZookeeper(1000, zkPort, zkTmpDir);
        }
    } else {
        this.zks = null;
    }
    this.dlmEmulator = LocalDLMEmulator.newBuilder().numBookies(numBookies).zkHost(zkServers).zkPort(zkPort)
            .serverConf(bkConf).shouldStartZK(false).build();
    this.shouldStartProxy = shouldStartProxy;
    this.proxyPort = proxyPort;
}

From source file:act.installer.pubchem.PubchemTTLMergerTest.java

public PubchemSynonyms getPCSyonymsForKey(
        Pair<RocksDB, Map<PubchemTTLMerger.COLUMN_FAMILIES, ColumnFamilyHandle>> dbAndHandles, String key)
        throws Exception {
    byte[] valBytes = dbAndHandles.getLeft()
            .get(dbAndHandles.getRight().get(PubchemTTLMerger.COLUMN_FAMILIES.CID_TO_SYNONYMS), key.getBytes());
    try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(valBytes))) {
        return (PubchemSynonyms) ois.readObject();
    }//from   ww  w  .  j a  v a 2 s.co  m
}

From source file:com.hortonworks.streamline.streams.runtime.rule.sql.SqlBasicExprScriptTest.java

@Test
public void testBasicAggregation() throws Exception {
    // SELECT STREAM DEPTID, EMPID, MIN(SALARY) FROM FOO where ID > 0 GROUP BY DEPTID, EMPID

    Expression min_salary = new AggregateFunctionExpression("MIN",
            ImmutableList.of(new FieldExpression(Schema.Field.of("salary", Schema.Type.INTEGER))));

    Expression deptid = new FieldExpression(Schema.Field.of("deptid", Schema.Type.INTEGER));
    Expression empid = new FieldExpression(Schema.Field.of("empid", Schema.Type.INTEGER));
    GroupBy groupBy = new GroupBy(ImmutableList.of(deptid, empid));
    Expression id = new FieldExpression(Schema.Field.of("id", Schema.Type.INTEGER));
    Expression id_gt_0 = new BinaryExpression(Operator.GREATER_THAN, id, new Literal("0"));
    Condition condition = new Condition();
    condition.setExpression(id_gt_0);/*from w ww  . j a va2  s.  c o m*/

    Projection projection = new Projection();
    projection.setExpressions(ImmutableList.<Expression>of(deptid, empid, min_salary));

    sqlScript = new SqlScript(new StormSqlExpression(condition, projection, groupBy, null), new SqlEngine(),
            new SqlScript.CorrelatedValuesToStreamlineEventConverter(
                    Lists.newArrayList("deptid", "empid", "MIN")));

    // (100, 100), 10
    Map<String, Object> kv1 = new HashMap<>();
    kv1.put("id", 1);
    kv1.put("deptid", 100);
    kv1.put("empid", 100);
    kv1.put("salary", 10);

    // (100, 100), 5
    Map<String, Object> kv2 = new HashMap<>();
    kv2.put("id", 2);
    kv2.put("deptid", 100);
    kv2.put("empid", 100);
    kv2.put("salary", 5);

    // (101, 101), 10
    Map<String, Object> kv3 = new HashMap<>();
    kv3.put("id", 3);
    kv3.put("deptid", 101);
    kv3.put("empid", 101);
    kv3.put("salary", 10);

    // (102, 102), 5
    Map<String, Object> kv4 = new HashMap<>();
    kv4.put("id", 4);
    kv4.put("deptid", 102);
    kv4.put("empid", 102);
    kv4.put("salary", 5);

    StreamlineEvent group1Event1 = StreamlineEventImpl.builder().fieldsAndValues(kv1).dataSourceId("1").build();
    StreamlineEvent group1Event2 = StreamlineEventImpl.builder().fieldsAndValues(kv2).dataSourceId("1").build();
    StreamlineEvent group2Event1 = StreamlineEventImpl.builder().fieldsAndValues(kv3).dataSourceId("1").build();
    StreamlineEvent group3Event1 = StreamlineEventImpl.builder().fieldsAndValues(kv4).dataSourceId("1").build();

    sqlScript.evaluate(group1Event1);
    sqlScript.evaluate(group1Event2);
    sqlScript.evaluate(group2Event1);
    sqlScript.evaluate(group3Event1);
    Collection<StreamlineEvent> result = sqlScript.evaluate(StreamlineEventImpl.GROUP_BY_TRIGGER_EVENT);

    Assert.assertEquals(3, result.size());

    Map<List<Integer>, Pair<Integer, Set<String>>> expectedGroupValueToMinAndParentIds;
    expectedGroupValueToMinAndParentIds = new HashMap<>();
    expectedGroupValueToMinAndParentIds.put(Lists.newArrayList(100, 100),
            new ImmutablePair<>(5, Sets.newHashSet(group1Event1.getId(), group1Event2.getId())));
    expectedGroupValueToMinAndParentIds.put(Lists.newArrayList(101, 101),
            new ImmutablePair<>(10, Sets.newHashSet(group2Event1.getId())));
    expectedGroupValueToMinAndParentIds.put(Lists.newArrayList(102, 102),
            new ImmutablePair<>(5, Sets.newHashSet(group3Event1.getId())));

    result.iterator().forEachRemaining(res -> {
        List<Integer> groupValue = Lists.newArrayList((Integer) res.get("deptid"), (Integer) res.get("empid"));
        Assert.assertTrue(expectedGroupValueToMinAndParentIds.containsKey(groupValue));
        Pair<Integer, Set<String>> minAndPairIds = expectedGroupValueToMinAndParentIds.get(groupValue);
        Integer minValue = (Integer) res.get("MIN");
        Assert.assertEquals(minValue, minAndPairIds.getLeft());

        Assert.assertTrue(EventCorrelationInjector.containsParentIds(res));
        Assert.assertEquals(minAndPairIds.getRight(), EventCorrelationInjector.getParentIds(res));

        // avoid matching multiple times
        expectedGroupValueToMinAndParentIds.remove(groupValue);
    });
}

From source file:ca.on.oicr.pde.workflows.GATK3Workflow.java

private <T, S> Set<T> getLeftCollection(Collection<Pair<T, S>> pairs) {
    Set<T> ts = new HashSet<>();
    for (Pair<T, S> p : pairs) {
        ts.add(p.getLeft());
    }/*from  w ww . j  av a2  s.com*/
    return ts;
}

From source file:com.shieldsbetter.sbomg.ModelClass.java

public void addOverriddenRootMethod(String methodName, TypeName returnType,
        Iterable<Pair<String, TypeName>> parameters, CodeBlock code) {
    MethodSpec.Builder b = MethodSpec.methodBuilder(methodName).addAnnotation(java.lang.Override.class)
            .returns(returnType).addCode(code).addModifiers(Modifier.PUBLIC);

    for (Pair<String, TypeName> param : parameters) {
        b.addParameter(param.getRight(), param.getLeft(), Modifier.FINAL);
    }//  www  .j a v  a 2  s  .  c o  m

    myRootMethods.add(b.build());
}

From source file:com.shieldsbetter.sbomg.ModelClass.java

public void addRootMethod(String methodName, TypeName returnType,
        Iterable<? extends Pair<String, TypeName>> parameters, CodeBlock code) {
    MethodSpec.Builder b = MethodSpec.methodBuilder(methodName).returns(returnType).addCode(code)
            .addModifiers(Modifier.PUBLIC);

    for (Pair<String, TypeName> param : parameters) {
        b.addParameter(param.getRight(), param.getLeft(), Modifier.FINAL);
    }/* ww w.j a  v a 2s  .com*/

    myRootMethods.add(b.build());
}

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   w ww. j  a va  2s  .c om

        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;
}