List of usage examples for org.apache.commons.lang3.tuple Pair getRight
public abstract R getRight();
Gets the right element from this pair.
When treated as a key-value pair, this is the value.
From source file:net.malisis.doors.door.tileentity.FenceGateTileEntity.java
public void updateAll() { if (!worldObj.isRemote) return;//w w w. j a va2 s . com Pair<BlockState, Integer> pair = updateCamo(); camoState = pair.getLeft(); camoColor = pair.getRight(); isWall = updateWall(); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); }
From source file:com.blacklocus.qs.worker.WorkerQueueItemHandler.java
@SuppressWarnings("unchecked") @Override/* ww w . java2 s. c o m*/ public void withFuture(QSTaskModel task, final Future<Pair<QSTaskModel, Object>> future) { // I don't know if this is useful or not. QSWorker worker = workers.get(task.handler); if (worker == null) { throw new RuntimeException("No worker available for worker identifier: " + task.handler); } final TaskKitFactory factory = new TaskKitFactory(task, worker, logService, workerIdService); worker.withFuture(factory, new Future<Pair<TaskKitFactory, Object>>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { return future.cancel(mayInterruptIfRunning); } @Override public boolean isCancelled() { return future.isCancelled(); } @Override public boolean isDone() { return future.isDone(); } @Override public Pair<TaskKitFactory, Object> get() throws InterruptedException, ExecutionException { Pair<QSTaskModel, Object> theFuture = future.get(); return Pair.of(factory, theFuture.getRight()); } @Override public Pair<TaskKitFactory, Object> get(long timeout, @SuppressWarnings("NullableProblems") TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Pair<QSTaskModel, Object> theFuture = future.get(timeout, unit); return Pair.of(factory, theFuture.getRight()); } }); }
From source file:hu.ppke.itk.nlpg.purepos.common.AnalysisQueue.java
public void addWord(String input, Integer position) { Pair<String, List<String>> res = parse(input); String word = res.getLeft();/*from w w w . j a v a2s .c o m*/ List<String> analsList = res.getRight(); words.set(position, word); anals.set(position, new HashMap<String, Double>()); for (String anal : analsList) { int indexOfValSep = anal.indexOf("$$"); String lemmaTag = anal; double prob = 1; if (indexOfValSep > -1) { useProb.set(position, true); prob = Double.parseDouble(anal.substring(indexOfValSep + 2)); lemmaTag = anal.substring(0, indexOfValSep); } anals.get(position).put(lemmaTag, prob); } }
From source file:at.gridtec.lambda4j.consumer.bi.BiConsumer2.java
/** * Applies this consumer to the given tuple. * * @param tuple The tuple to be applied to the consumer * @throws NullPointerException If given argument is {@code null} * @see org.apache.commons.lang3.tuple.Pair *//* w w w.j ava 2 s .co m*/ default void accept(@Nonnull Pair<T, U> tuple) { Objects.requireNonNull(tuple); accept(tuple.getLeft(), tuple.getRight()); }
From source file:cherry.foundation.querydsl.CustomizingConfigurationFactoryBean.java
@Override public void afterPropertiesSet() throws Exception { if (listeners != null) { for (SQLListener l : listeners) { configuration.addListener(l); }// www . j a v a 2s. c o m } if (customTypes != null) { for (Type<?> t : customTypes) { configuration.register(t); } } if (numericTypeSpecs != null) { for (String spec : numericTypeSpecs) { List<String> l = Splitter.onPattern(",").trimResults().splitToList(spec); if (l.size() != 3) { throw new IllegalArgumentException( "numericTypeSpecs must be \"{total},{decimal},{javaType}\" or \"{beginTotal}-{endTotal},{beginDecimal}-{endDecimal},{javaType}\""); } Pair<Integer, Integer> total = parsePair(l.get(0)); Pair<Integer, Integer> decimal = parsePair(l.get(1)); configuration.registerNumeric(total.getLeft(), total.getRight(), decimal.getLeft(), decimal.getRight(), Class.forName(l.get(2))); } } }
From source file:cherry.sqlman.tool.statement.SqlStatementControllerImpl.java
@Override public ModelAndView execute(SqlStatementForm form, BindingResult binding, Authentication auth, Locale locale, SitePreference sitePref, NativeWebRequest request) { if (hasErrors(form, binding)) { return withViewname(viewnameOfStart).build(); }/*from ww w . j a va 2 s .c o m*/ try { Pair<PageSet, ResultSet> pair = search(form); return withViewname(viewnameOfStart).addObject(pair.getLeft()).addObject(pair.getRight()).build(); } catch (BadSqlGrammarException ex) { LogicalErrorUtil.reject(binding, LogicError.BadSqlGrammer, Util.getRootCause(ex).getMessage()); return withViewname(viewnameOfStart).build(); } }
From source file:com.act.biointerpretation.l2expansion.ValidReactionSubstratesIterator.java
@Override public String[] next() { if (nextValidReaction != null) { Reaction r = nextValidReaction;//from w ww. java2 s. c om nextValidReaction = null; // Invalidate reaction to avoid accidental double next() calls. List<String> substrateInchis = new ArrayList<>(r.getSubstrates().length); for (Long id : r.getSubstrates()) { Pair<String, Boolean> lookupResults = getInchiAndIsCacheHit(id); assert (lookupResults.getRight()); // We should always hit the cache here since we looked up to validate. Integer coefficient = r.getSubstrateCoefficient(id); if (coefficient == null) { coefficient = 1; // Default to one if we can't find a coefficient for this substrate. } // Add the inchi once per coefficient count. for (int i = 0; i < coefficient; i++) { substrateInchis.add(lookupResults.getLeft()); } } return substrateInchis.toArray(new String[substrateInchis.size()]); } else { throw new RuntimeException("next() called without calling hasNext() or on an exhausted iterator"); } }
From source file:com.lyncode.jtwig.functions.repository.FunctionResolver.java
public CallableFunction get(String name, GivenParameters givenParameters) throws FunctionNotFoundException, ResolveException { if (!functions.containsKey(name)) throw new FunctionNotFoundException("Function with name '" + name + "' not found."); if (!cachedFunctions.containsKey(name)) cachedFunctions.put(name, new HashMap<Class[], Pair<FunctionReference, Boolean>>()); if (cachedFunctions.get(name).containsKey(givenParameters.types())) { Pair<FunctionReference, Boolean> pair = cachedFunctions.get(name).get(givenParameters.types()); Object[] arguments = pair.getRight() ? parameterResolver.resolveParameters(pair.getLeft(), givenParameters, parameterConverter) : parameterResolver.resolveParameters(pair.getLeft(), givenParameters, emptyConverter()); return new CallableFunction(pair.getLeft(), arguments); }//from www .jav a 2 s.c om List<FunctionReference> functionList = functions.get(name); for (FunctionReference function : functionList) { Object[] arguments = parameterResolver.resolveParameters(function, givenParameters, emptyConverter()); if (arguments != null) { cachedFunctions.get(name).put(givenParameters.types(), new ImmutablePair<>(function, false)); return new CallableFunction(function, arguments); } } for (FunctionReference function : functionList) { Object[] arguments = parameterResolver.resolveParameters(function, givenParameters, parameterConverter); if (arguments != null) { cachedFunctions.get(name).put(givenParameters.types(), new ImmutablePair<>(function, true)); return new CallableFunction(function, arguments); } } throw new FunctionNotFoundException("Function with name '" + name + "' and given parameters not found. Available:\n" + listAvailable(name, functions.get(name))); }
From source file:com.samsung.sjs.theorysolver.TheorySolverTest.java
/** * This tests the {@link TheorySolver} using a theory which has a random set of * blacklisted objects. We verify that the TheorySolver always finds the entire * set of non-blacklisted objects./*from www.j av a 2 s .c o m*/ */ @Test public void testBasics() { List<Object> all = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h"); for (int i = 0; i < 100; ++i) { Random r = new Random(SEED + i); Collection<Object> truthy = all.stream().filter(x -> r.nextBoolean()).collect(Collectors.toSet()); Theory<Object, Void> theory = positive -> { Collection<Object> bad = positive.stream().filter(x -> !truthy.contains(x)) .collect(Collectors.toSet()); if (bad.size() > 0) { // Construct a random, nonempty unsat core. Collection<Object> unsat = new HashSet<>(); unsat.add(bad.iterator().next()); bad.stream().filter(x -> r.nextBoolean()).forEach(unsat::add); return Either.right(unsat); } else { return Either.left(null); } }; Pair<Void, Collection<Object>> result = TheorySolver.solve(theory, new SatFixingSetFinder<>(new Sat4J()), Collections.emptyList(), all); Assert.assertEquals(all.size() - truthy.size(), result.getRight().size()); Assert.assertEquals(truthy, all.stream().filter(x -> !result.getRight().contains(x)).collect(Collectors.toSet())); } }
From source file:de.codecentric.batch.metrics.BatchMetricsImpl.java
@Override public void afterCompletion(int status) { if (LOG.isDebugEnabled()) { LOG.debug("Entered afterCompletion with status " + status + "."); }//w ww . j av a2 s . co m if (status == STATUS_COMMITTED) { MetricContainer currentMetricContainer = metricContainer.get(); for (Pair<String, ? extends Number> metric : currentMetricContainer.metrics) { if (metric.getRight() instanceof Long) { if (LOG.isDebugEnabled()) { LOG.debug("Increment " + metric + "."); } incrementNonTransactional(metric.getLeft(), (Long) metric.getRight()); } else if (metric.getRight() instanceof Double) { if (LOG.isDebugEnabled()) { LOG.debug("Gauge " + metric + "."); } set(metric.getLeft(), (Double) metric.getRight()); } else if (metric.getRight() == null) { if (LOG.isDebugEnabled()) { LOG.debug("Reset " + metric + "."); } remove(metric.getLeft()); } } } metricContainer.remove(); if (TransactionSynchronizationManager.hasResource(serviceKey)) { TransactionSynchronizationManager.unbindResource(serviceKey); } }