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:com.dancorder.Archiverify.SynchingVisitor.java

@Override
public void preVisitDirectory(Path relativeDirectoryPath, FileExistence existence) {
    try {/*www  . j  a v a  2  s  .com*/
        Logger.log("Scanning " + relativeDirectoryPath.toString());
        currentRelativeDirectoryPath = relativeDirectoryPath;

        if (isNotInErrorPath(relativeDirectoryPath)) {
            errorPath = null;

            Path directory1 = root1.resolve(relativeDirectoryPath);
            Path directory2 = root2.resolve(relativeDirectoryPath);

            Pair<FileHashStore, FileHashStore> hashStorePair = Pair.of(
                    fileHashStoreFactory.createFileHashStore(directory1),
                    fileHashStoreFactory.createFileHashStore(directory2));

            hashStoresByDirectory.put(relativeDirectoryPath, hashStorePair);
            visitedFilesByDirectory.put(relativeDirectoryPath, new ArrayList<Path>());

            List<Action> newActions = syncLogic.compareDirectories(directory1, directory2, existence);

            actions.addAll(newActions);
        }
    } catch (Exception e) {
        errorPath = relativeDirectoryPath;

        actions.add(new WarningAction(
                String.format("Error caught visiting directory %s this directory will not be synched. %s",
                        relativeDirectoryPath, e)));
    }
}

From source file:com.github.blindpirate.gogradle.core.GolangConfiguration.java

public void addFirstLevelDependency(Object notation, Closure closure) {
    firstLevelDependencies.add(Pair.of(notation, closure));
}

From source file:de.codecentric.batch.metrics.BatchMetricsImpl.java

@Override
public void decrement(String metricName, Long value) {
    if (TransactionSynchronizationManager.isSynchronizationActive()) {
        initializeMetricContainerAndRegisterTransactionSynchronizationIfNecessary();
        metricContainer.get().metrics.add(Pair.of(metricName, -value));
    } else {//from   w  w  w  . j a v  a2 s  .co  m
        decrementNonTransactional(metricName, value);
    }
}

From source file:cherry.goods.telno.SoumuExcelParserTest.java

@Test
public void testParse4() throws Exception {
    Map<String, Pair<String, String>> map;
    try (InputStream in = getClass().getResourceAsStream("soumu/000124073.xls")) {
        map = parser.parse(in);//from  ww  w  . j  a va 2 s  .  com
    }
    assertEquals(5343, map.size());
    assertEquals(Pair.of("0422", "20"), map.get("042220"));
    assertEquals(Pair.of("04998", "9"), map.get("049989"));
}

From source file:net.lldp.checksims.algorithm.linesimilarity.LineSimilarityCheckerTest.java

public AlgorithmResults cmp(Submission a, Submission b)
        throws TokenTypeMismatchException, InternalAlgorithmError {
    return lineCompare.detectSimilarity(Pair.of(a, b), lineCompare.getPercentableCalculator().fromSubmission(a),
            lineCompare.getPercentableCalculator().fromSubmission(b));
}

From source file:co.rsk.peg.StateForFederatorTest.java

@Test
public void serialize() {
    Sha3Hash sha3Hash1 = new Sha3Hash(SHA3_1);
    Sha3Hash sha3Hash2 = new Sha3Hash(SHA3_2);
    Sha3Hash sha3Hash3 = new Sha3Hash(SHA3_3);
    Sha3Hash sha3Hash4 = new Sha3Hash(SHA3_4);

    BtcTransaction tx1 = new BtcTransaction(NETWORK_PARAMETERS);
    BtcTransaction tx2 = new BtcTransaction(NETWORK_PARAMETERS);
    BtcTransaction tx3 = new BtcTransaction(NETWORK_PARAMETERS);
    BtcTransaction tx4 = new BtcTransaction(NETWORK_PARAMETERS);

    SortedMap<Sha3Hash, BtcTransaction> rskTxsWaitingForSignatures = new TreeMap<>();
    rskTxsWaitingForSignatures.put(sha3Hash1, tx1);
    rskTxsWaitingForSignatures.put(sha3Hash2, tx2);

    SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> rskTxsWaitingForBroadcasting = new TreeMap<>();
    rskTxsWaitingForBroadcasting.put(sha3Hash3, Pair.of(tx3, 3L));
    rskTxsWaitingForBroadcasting.put(sha3Hash4, Pair.of(tx4, 4L));

    StateForFederator stateForFederator = new StateForFederator(rskTxsWaitingForSignatures,
            rskTxsWaitingForBroadcasting);

    byte[] encoded = stateForFederator.getEncoded();

    Assert.assertTrue(encoded.length > 0);

    StateForFederator reverseResult = new StateForFederator(encoded, NETWORK_PARAMETERS);

    Assert.assertNotNull(reverseResult);
    Assert.assertEquals(2, reverseResult.getRskTxsWaitingForBroadcasting().size());
    Assert.assertEquals(2, reverseResult.getRskTxsWaitingForSignatures().size());

    Assert.assertEquals(tx1, reverseResult.getRskTxsWaitingForSignatures().get(sha3Hash1));
    Assert.assertEquals(tx2, reverseResult.getRskTxsWaitingForSignatures().get(sha3Hash2));

    Assert.assertTrue(checkKeys(reverseResult.getRskTxsWaitingForSignatures().keySet(), sha3Hash1, sha3Hash2));

    Assert.assertEquals(Pair.of(tx3, 3L), reverseResult.getRskTxsWaitingForBroadcasting().get(sha3Hash3));
    Assert.assertEquals(Pair.of(tx4, 4L), reverseResult.getRskTxsWaitingForBroadcasting().get(sha3Hash4));

    Assert.assertTrue(/*from   w  w w .  j a  v  a  2 s.co m*/
            checkKeys(reverseResult.getRskTxsWaitingForBroadcasting().keySet(), sha3Hash3, sha3Hash4));
}

From source file:com.qualys.jserf.NettySerfClient.java

@Override
public void makeRpc(SerfRequest request) throws IOException {
    if (!channelManger.isConnected()) {
        log.debug("We're not connected to Serf, so we can't send command={} with seq={}",
                request.getHeader().command, request.getHeader().seq);
        throw new IOException("Not connected to Serf");
    }// ww w . java  2  s.  c o m

    Channel channel = channelManger.get();

    callBacksBySequenceCache.put(request.getHeader().seq,
            Pair.of(request.getHeader().toCommand(), request.getCallBack()));
    try {
        log.debug("Sending command={} with seq={}", request.getHeader().command, request.getHeader().seq);
        channel.write(messagePack.write(request.getHeader()));
        channel.writeAndFlush(messagePack.write(request.getBody()));
        log.debug("Sent command={} with seq={}", request.getHeader().command, request.getHeader().seq);
    } catch (IOException e) {
        log.warn("Caught IOException while trying to write request. Removing callback from cache", e);
        callBacksBySequenceCache.invalidate(request.getHeader().seq);
        throw e;
    } finally {
        if (Command.STOP.equals(request.getHeader().toCommand())) {
            StopRequestBody stopRequest = (StopRequestBody) request.getBody();
            log.debug("Found stop request with sequence={}. Removing callback from the cache.",
                    stopRequest.stop);
            callBacksBySequenceCache.invalidate(stopRequest.stop);
            log.debug("Removed callback for sequence={}.", stopRequest.stop);
        }
    }
}

From source file:com.spotify.heroic.consumer.collectd.CollectdChannelHandler.java

@Override
protected void channelRead0(final ChannelHandlerContext ctx, final DatagramPacket msg) throws Exception {
    final Iterator<CollectdSample> samples = CollectdParser.parse(msg.content());

    while (samples.hasNext()) {
        final CollectdSample s = samples.next();

        final Set<Map.Entry<String, String>> base = ImmutableMap
                .of("host", s.getHost(), "plugin", s.getPlugin()).entrySet();

        final List<Ingestion.Request> ingestions;

        if (hostProcessor.isPresent()) {
            final Map<String, Object> parts = hostProcessor.get().parse(s.getHost());

            final Set<Map.Entry<String, String>> tags = ImmutableSet.copyOf(
                    Iterables.transform(parts.entrySet(), e -> Pair.of(e.getKey(), e.getValue().toString())));

            ingestions = types.convert(s, Iterables.concat(base, tags));
        } else {//www  .j  a v a 2 s .co m
            ingestions = types.convert(s, base);
        }

        final List<AsyncFuture<Ingestion>> futures = new ArrayList<>();

        for (final Ingestion.Request w : ingestions) {
            futures.add(ingestion.write(w));
        }

        async.collectAndDiscard(futures);
    }
}

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

public static <K, L> Pair<K, Double> findMax2(Map<K, Pair<L, Double>> map) {
    Pair<K, Double> ret = null;
    for (Map.Entry<K, Pair<L, Double>> e : map.entrySet()) {
        if (ret == null || e.getValue().getValue() > ret.getValue()) {
            ret = Pair.of(e.getKey(), e.getValue().getValue());
        }//from w  w  w. j  a v  a 2  s.co m
    }
    return ret;
}

From source file:ee.ria.xroad.proxy.testsuite.testcases.AttachmentBig.java

@Override
protected Pair<String, InputStream> getRequestInput(boolean addUtf8Bom) throws Exception {
    PipedOutputStream os = new PipedOutputStream();
    PipedInputStream is = new PipedInputStream(os);
    MultiPartOutputStream mpos = new MultiPartOutputStream(os);

    if (addUtf8Bom) {
        mpos.write(ByteOrderMark.UTF_8.getBytes());
    }/*from w w w .j  a  v  a2 s . co m*/

    new Thread(new MpWriter(mpos)).start();

    return Pair.of("multipart/related; charset=UTF-8; " + "boundary=" + mpos.getBoundary(), (InputStream) is);
}