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

@Override
public void postVisitDirectory(Path relativeDirectoryPath, FileExistence existence) {
    try {//from w  w  w.j a v  a2 s  .co m
        if (isNotInErrorPath(relativeDirectoryPath)) {
            Pair<FileHashStore, FileHashStore> hashStorePair = hashStoresByDirectory.get(relativeDirectoryPath);
            List<Path> visitedFiles = visitedFilesByDirectory.get(relativeDirectoryPath);

            syncLogic.removeUnvisitedHashes(hashStorePair.getLeft(), visitedFiles);
            syncLogic.removeUnvisitedHashes(hashStorePair.getRight(), visitedFiles);
            List<Action> newActions = syncLogic.checkHashStores(hashStorePair.getLeft(),
                    hashStorePair.getRight());
            actions.addAll(newActions);
        }

        hashStoresByDirectory.remove(relativeDirectoryPath);
        visitedFilesByDirectory.remove(relativeDirectoryPath);
    } catch (Exception e) {
        errorPath = relativeDirectoryPath;

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

From source file:com.uber.hoodie.common.util.TestCompactionUtils.java

@Test
public void testCompactionTransformation() {
    // check HoodieCompactionOperation <=> CompactionOperation transformation function
    Pair<List<Pair<String, FileSlice>>, HoodieCompactionPlan> inputAndPlan = buildCompactionPlan();
    HoodieCompactionPlan plan = inputAndPlan.getRight();
    List<HoodieCompactionOperation> originalOps = plan.getOperations();
    List<HoodieCompactionOperation> regeneratedOps = originalOps.stream().map(op -> {
        // Convert to CompactionOperation
        return CompactionUtils.buildCompactionOperation(op);
    }).map(op2 -> {/*  www.j a v a2  s . c  o  m*/
        // Convert back to HoodieCompactionOperation and check for equality
        return CompactionUtils.buildHoodieCompactionOperation(op2);
    }).collect(Collectors.toList());
    Assert.assertTrue("Transformation did get tested", originalOps.size() > 0);
    Assert.assertEquals("All fields set correctly in transformations", originalOps, regeneratedOps);
}

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();
    }/*w  ww .  ja v  a  2 s. c  o m*/
}

From source file:com.sk89q.craftbook.sponge.mechanics.variable.Variables.java

public String parseVariables(String line, @Nullable Player player) {
    for (Pair<String, String> possibleVariable : getPossibleVariables(line)) {
        String namespace = possibleVariable.getLeft();
        String name = possibleVariable.getRight();

        boolean explicit = true;
        if (namespace == null) {
            if (defaultToGlobal.getValue()) {
                namespace = GLOBAL_NAMESPACE;
                if (player != null && getVariable(player.getUniqueId().toString(), name) != null) {
                    namespace = player.getUniqueId().toString();
                }//www. j a v  a  2 s . co m
            } else {
                if (player != null) {
                    namespace = player.getUniqueId().toString();
                } else {
                    continue;
                }
            }
            explicit = false;
        }

        String variable = getVariable(namespace, name);

        if (variable != null) {
            String variableText = (explicit ? (namespace + '|') : "") + name;
            line = line.replace('%' + variableText + '%', getVariable(namespace, name));
        }
    }

    return line;
}

From source file:com.act.utils.parser.GenbankInterpreterTest.java

private void validateFeatureMap(Map<Pair<String, String>, Map<String, String>> feature_to_qualifiers,
        GenbankInterpreter gi) {//from w ww.  java2 s.c  o m
    for (Pair<String, String> feature_type_and_source : feature_to_qualifiers.keySet()) {
        for (List<Qualifier> qual_list : gi
                .getQualifiers(0, feature_type_and_source.getLeft(), feature_type_and_source.getRight())
                .values()) {
            for (Qualifier qual : qual_list) {
                Map<String, String> qual_map = feature_to_qualifiers.get(feature_type_and_source);
                assertTrue("testing whether the qualifier name extracted is accurate",
                        qual_map.containsKey(qual.getName()));
                if (qual.getName().equals("dbxref")) {
                    assertEquals("testing whether the extracted value of the db_xref qualifier is accurate",
                            qual_map.get(qual.getName()),
                            ((DBReferenceInfo) qual).getDatabase() + ":" + ((DBReferenceInfo) qual).getId());
                } else {
                    assertEquals("testing whether the extracted value of the qualifier is accurate",
                            qual_map.get(qual.getName()), qual.getValue());
                }
            }
        }
    }
}

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

/**
 * testExtractLabelAndValue02()./*from   ww w .  j a  v a2s. co  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  .j  a  va2 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:com.sludev.commons.vfs2.provider.s3.SS3FileObject.java

/**
 * Callback for checking the type of the current FileObject.  Typically can
 * be of type.../*from   ww w  . j a  v a2  s .com*/
 * FILE for regular remote files
 * FOLDER for regular remote containers
 * IMAGINARY for a path that does not exist remotely.
 * 
 * @return
 * @throws Exception 
 */
@Override
protected FileType doGetType() throws Exception {
    FileType res;

    Pair<String, String> path = getContainerAndPath();

    if (objectExists(path.getLeft(), path.getRight())) {
        res = FileType.FILE;
    } else {
        // Blob Service does not have folders.  Just files with path separators in
        // their names.

        // Here's the trick for folders.
        //
        // Do a listing on that prefix.  If it returns anything, after not
        // existing, then it's a folder.
        String prefix = path.getRight();
        if (prefix.endsWith("/") == false) {
            // We need folders ( prefixes ) to end with a slash
            prefix += "/";
        }

        ObjectListing blobs = null;
        if (prefix.equals("/")) {
            // Special root path case. List the root blobs with no prefix
            blobs = fileSystem.getClient().listObjects(path.getLeft());
        } else {
            blobs = fileSystem.getClient().listObjects(path.getLeft(), prefix);
        }

        if (blobs.getObjectSummaries().isEmpty()) {
            res = FileType.IMAGINARY;
        } else {
            res = FileType.FOLDER;
        }
    }

    return res;
}

From source file:edu.uci.ics.pregelix.runtime.simpleagg.AccumulatingAggregatorFactory.java

@SuppressWarnings("unchecked")
@Override//  w ww.  j av  a 2  s  .c  om
public IAggregatorDescriptor createAggregator(IHyracksTaskContext ctx, RecordDescriptor inRecordDesc,
        RecordDescriptor outRecordDescriptor, int[] aggKeys, int[] partialKeys) throws HyracksDataException {

    return new IAggregatorDescriptor() {

        private FrameTupleReference ftr = new FrameTupleReference();

        @Override
        public void init(ArrayTupleBuilder tupleBuilder, IFrameTupleAccessor accessor, int tIndex,
                AggregateState state) throws HyracksDataException {
            Pair<ArrayBackedValueStorage[], IAggregateFunction[]> aggState = (Pair<ArrayBackedValueStorage[], IAggregateFunction[]>) state.state;
            ArrayBackedValueStorage[] aggOutput = aggState.getLeft();
            IAggregateFunction[] agg = aggState.getRight();

            // initialize aggregate functions
            for (int i = 0; i < agg.length; i++) {
                aggOutput[i].reset();
                try {
                    agg[i].init();
                } catch (Exception e) {
                    throw new HyracksDataException(e);
                }
            }

            ftr.reset(accessor, tIndex);
            for (int i = 0; i < agg.length; i++) {
                try {
                    agg[i].step(ftr);
                } catch (Exception e) {
                    throw new HyracksDataException(e);
                }
            }
        }

        @Override
        public void aggregate(IFrameTupleAccessor accessor, int tIndex, IFrameTupleAccessor stateAccessor,
                int stateTupleIndex, AggregateState state) throws HyracksDataException {
            Pair<ArrayBackedValueStorage[], IAggregateFunction[]> aggState = (Pair<ArrayBackedValueStorage[], IAggregateFunction[]>) state.state;
            IAggregateFunction[] agg = aggState.getRight();
            ftr.reset(accessor, tIndex);
            for (int i = 0; i < agg.length; i++) {
                try {
                    agg[i].step(ftr);
                } catch (Exception e) {
                    throw new HyracksDataException(e);
                }
            }
        }

        @Override
        public void outputFinalResult(ArrayTupleBuilder tupleBuilder, IFrameTupleAccessor accessor, int tIndex,
                AggregateState state) throws HyracksDataException {
            Pair<ArrayBackedValueStorage[], IAggregateFunction[]> aggState = (Pair<ArrayBackedValueStorage[], IAggregateFunction[]>) state.state;
            ArrayBackedValueStorage[] aggOutput = aggState.getLeft();
            IAggregateFunction[] agg = aggState.getRight();
            for (int i = 0; i < agg.length; i++) {
                try {
                    agg[i].finish();
                    tupleBuilder.addField(aggOutput[i].getByteArray(), aggOutput[i].getStartOffset(),
                            aggOutput[i].getLength());
                } catch (Exception e) {
                    throw new HyracksDataException(e);
                }
            }
        }

        @Override
        public AggregateState createAggregateStates() {
            IAggregateFunction[] agg = new IAggregateFunction[aggFactories.length];
            ArrayBackedValueStorage[] aggOutput = new ArrayBackedValueStorage[aggFactories.length];
            for (int i = 0; i < agg.length; i++) {
                aggOutput[i] = new ArrayBackedValueStorage();
                try {
                    agg[i] = aggFactories[i].createAggregateFunction(aggOutput[i]);
                } catch (Exception e) {
                    throw new IllegalStateException(e);
                }
            }
            return new AggregateState(Pair.of(aggOutput, agg));
        }

        @Override
        public void reset() {

        }

        @Override
        public void outputPartialResult(ArrayTupleBuilder tupleBuilder, IFrameTupleAccessor accessor,
                int tIndex, AggregateState state) throws HyracksDataException {
            throw new IllegalStateException("this method should not be called");
        }

        @Override
        public void close() {

        }

    };
}

From source file:alfio.manager.PaymentManager.java

PaymentResult processPayPalPayment(String reservationId, String token, String payerId, int price, Event event) {
    try {/*from   w w  w  .  jav  a  2s  .  c o  m*/
        Pair<String, String> captureAndPaymentId = paypalManager.commitPayment(reservationId, token, payerId,
                event);
        String captureId = captureAndPaymentId.getLeft();
        String paymentId = captureAndPaymentId.getRight();
        Supplier<String> feeSupplier = () -> FeeCalculator.getCalculator(event, configurationManager)
                .apply(ticketRepository.countTicketsInReservation(reservationId), (long) price)
                .map(String::valueOf).orElse("0");
        Pair<Long, Long> fees = paypalManager.getInfo(paymentId, captureId, event, feeSupplier).map(i -> {
            Long platformFee = Optional.ofNullable(i.getPlatformFee()).map(Long::parseLong).orElse(0L);
            Long gatewayFee = Optional.ofNullable(i.getFee()).map(Long::parseLong).orElse(0L);
            return Pair.of(platformFee, gatewayFee);
        }).orElseGet(() -> Pair.of(0L, 0L));
        transactionRepository.insert(captureId, paymentId, reservationId, ZonedDateTime.now(), price,
                event.getCurrency(), "Paypal confirmation", PaymentProxy.PAYPAL.name(), fees.getLeft(),
                fees.getRight());
        return PaymentResult.successful(captureId);
    } catch (Exception e) {
        log.warn("errow while processing paypal payment: " + e.getMessage(), e);
        if (e instanceof PayPalRESTException) {
            return PaymentResult.unsuccessful(ErrorsCode.STEP_2_PAYPAL_UNEXPECTED);
        } else if (e instanceof PaypalManager.HandledPaypalErrorException) {
            return PaymentResult.unsuccessful(e.getMessage());
        }
        throw new IllegalStateException(e);
    }
}