List of usage examples for org.apache.commons.lang3.tuple Pair of
public static <L, R> Pair<L, R> of(final L left, final R right)
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.
From source file:com.amazon.janusgraph.diskstorage.dynamodb.AbstractDynamoDBStore.java
@Override public void acquireLock(StaticBuffer key, StaticBuffer column, StaticBuffer expectedValue, StoreTransaction txh) throws BackendException { final DynamoDBStoreTransaction tx = DynamoDBStoreTransaction.getTx(txh); final Pair<StaticBuffer, StaticBuffer> keyColumn = Pair.of(key, column); final DynamoDBStoreTransaction existing; try {/*from w w w . ja v a2s.c o m*/ existing = keyColumnLocalLocks.get(keyColumn, new SetStoreIfTxMappingDoesntExist(tx, keyColumn)); } catch (ExecutionException | UncheckedExecutionException | ExecutionError e) { throw new TemporaryLockingException("Unable to acquire lock", e); } if (null != existing && tx != existing) { throw new TemporaryLockingException( String.format("tx %s already locked key-column %s when tx %s tried to lock", existing.getId(), keyColumn.toString(), tx.getId())); } // Titan's locking expects that only the first expectedValue for a given key/column should be used if (!tx.contains(key, column)) { tx.put(key, column, expectedValue); } }
From source file:enumj.EnumerableTest.java
@Test public void testOfLazyIterable() { System.out.println("ofLazyIterable"); EnumerableGenerator.generatorPairs().limit(100) .map(p -> Pair.of(p.getLeft().ofLazyIterableEnumerable(), p.getRight().ofLazyIterableEnumerable())) .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight()))); }
From source file:alfio.manager.PaymentManager.java
PaymentResult processPayPalPayment(String reservationId, String token, String payerId, int price, Event event) { try {//from w w w . ja va 2 s . 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); } }
From source file:com.microsoft.azure.management.compute.implementation.VirtualMachineMsiHelper.java
/** * Specifies that applications running on the virtual machine requires the given access role * with scope of access limited to the arm resource identified by the resource id specified * in the scope parameter./* w ww . jav a 2 s. c o m*/ * * @param scope scope of the access represented in arm resource id format * @param asRole access role to assigned to the virtual machine * @return VirtualMachineMsiHelper */ VirtualMachineMsiHelper withRoleBasedAccessTo(String scope, BuiltInRole asRole) { this.requireSetup = true; String key = scope.toLowerCase() + "_" + asRole.toString().toLowerCase(); this.rolesToAssign.put(key, Pair.of(scope, asRole)); return this; }
From source file:de.ks.activity.initialization.ActivityInitialization.java
private Supplier<DefaultLoader<Node, Object>> getDefaultLoaderSupplier(Class<?> controllerClass) { return () -> { DefaultLoader<Node, Object> loader = new DefaultLoader<>(controllerClass); loader.load();/*from w w w. j av a 2 s. c o m*/ Node view = loader.getView(); currentlyLoadedControllers.get().forEach((c) -> { assert c != null; log.debug("Registering controller {} with node {}", c, view); controllers.putIfAbsent(c.getClass(), new LinkedList<>()); controllers.get(c.getClass()).add(Pair.of(c, view)); }); currentlyLoadedControllers.get().clear(); return loader; }; }
From source file:com.facebook.presto.accumulo.conf.AccumuloTableProperties.java
/** * Gets the value of the column_mapping property, or Optional.empty() if not set. * <p>/*ww w. j av a 2s .c o m*/ * Parses the value into a map of Presto column name to a pair of strings, the Accumulo column family and qualifier. * * @param tableProperties The map of table properties * @return The column mapping, presto name to (accumulo column family, qualifier) */ public static Optional<Map<String, Pair<String, String>>> getColumnMapping( Map<String, Object> tableProperties) { requireNonNull(tableProperties); @SuppressWarnings("unchecked") String strMapping = (String) tableProperties.get(COLUMN_MAPPING); if (strMapping == null) { return Optional.empty(); } // Parse out the column mapping // This is a comma-delimited list of "(presto, column:accumulo, fam:accumulo qualifier)" triplets ImmutableMap.Builder<String, Pair<String, String>> mapping = ImmutableMap.builder(); for (String m : COMMA_SPLITTER.split(strMapping)) { String[] tokens = Iterables.toArray(COLON_SPLITTER.split(m), String.class); checkState(tokens.length == 3, format("Mapping of %s contains %d tokens instead of 3", m, tokens.length)); mapping.put(tokens[0], Pair.of(tokens[1], tokens[2])); } return Optional.of(mapping.build()); }
From source file:io.knotx.assembler.FragmentAssemblerTest.java
private void callAssemblerWithAssertions(TestContext context, List<Pair<List<String>, String>> fragments, Action1<KnotContext> testFunction) { Async async = context.async();//from w ww . j a v a2s . c om KnotProxy service = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS); service.rxProcess(KnotContextFactory.create(fragments)).map(ctx -> Pair.of(async, ctx)) .subscribe(success -> { testFunction.call(success.getRight()); async.complete(); }, context::fail); }
From source file:com.intuit.karate.Script.java
public static Pair<String, String> parseVariableAndPath(String text) { Matcher matcher = VAR_AND_PATH_PATTERN.matcher(text); matcher.find();//from w ww .j av a 2 s. c o m String name = text.substring(0, matcher.end()); String path; if (matcher.end() == text.length()) { path = ""; } else { path = text.substring(matcher.end()); } if (Script.isXmlPath(path) || Script.isXmlPathFunction(path)) { // xml, don't prefix for json } else { path = "$" + path; } return Pair.of(name, path); }
From source file:edu.uci.ics.pregelix.runtime.simpleagg.AccumulatingAggregatorFactory.java
@SuppressWarnings("unchecked") @Override/* w w w . ja v a 2s. com*/ 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:com.microsoft.azure.management.compute.implementation.VirtualMachineScaleSetMsiHelper.java
/** * Specifies that applications running on the virtual machine scale set instance requires the * given access role with scope of access limited to the arm resource identified by the resource * id specified in the scope parameter./*from w w w. j av a 2s .com*/ * * @param scope scope of the access represented in arm resource id format * @param asRole access role to assigned to the virtual machine scale set * @return VirtualMachineScaleSetMsiHelper */ VirtualMachineScaleSetMsiHelper withRoleBasedAccessTo(String scope, BuiltInRole asRole) { this.requireSetup = true; String key = scope.toLowerCase() + "_" + asRole.toString().toLowerCase(); this.rolesToAssign.put(key, Pair.of(scope, asRole)); return this; }