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.github.steveash.jg2p.align.FilterWalkerDecorator.java
private boolean isAllowed(String xGram, String yGram) { return allowed.contains(Pair.of(xGram, yGram)); }
From source file:com.spotify.heroic.cluster.NodeRegistry.java
/** * Find multiple registry entries from all shards. * * @param n Max number of entries to find. * @return An iterable of iterables, containing all found entries. *///from w ww.j a v a 2s .co m public List<Pair<Map<String, String>, List<ClusterNode>>> findFromAllShards(OptionalLimit n) { final List<Pair<Map<String, String>, List<ClusterNode>>> result = Lists.newArrayList(); final Multimap<Map<String, String>, ClusterNode> shards = buildShards(entries); final Set<Entry<Map<String, String>, Collection<ClusterNode>>> entries = shards.asMap().entrySet(); for (final Entry<Map<String, String>, Collection<ClusterNode>> e : entries) { result.add(Pair.of(e.getKey(), pickN(e.getValue(), n))); } return result; }
From source file:de.openali.odysseus.chart.ext.base.layer.HoverIndex.java
public synchronized void addElement(final Polygon bounds, final EditInfo info) { final int id = m_elements.size(); m_elements.add(Pair.of(bounds, info)); final Envelope envelope = bounds.getEnvelopeInternal(); final com.infomatiq.jsi.Rectangle jsiRect = JTSUtilities.toRectangle(envelope); m_index.add(jsiRect, id);//w ww . j a v a 2 s .c o m }
From source file:com.muk.services.processor.api.IntentApiProcessor.java
@Override protected Map<String, Object> applyDiff(PatchRequest body, Exchange exchange, UriComponents redirectComponents) { Map<String, Object> response = super.applyDiff(body, exchange, redirectComponents); /* Paypal centric for now since this is the first */ //TODO generalize final String paymentId = exchange.getIn().getHeader("rId", String.class); if ("execute".equals(body.getStateChange())) { final StringBuilder jqBuilder = new StringBuilder(); body.getPathChanges().add(Pair.of(".paymentId", "\"" + paymentId + "\"")); for (final Pair<String, Object> jqStatement : body.getPathChanges()) { jqBuilder.append(jqStatement.getLeft()).append("|=").append(jqStatement.getRight()).append(" | "); }/* w ww . j ava 2 s .com*/ jqBuilder.append("."); final String jqString = jqBuilder.toString(); //jqString = StringUtils.chop(jqString); try { final JsonQuery jq = JsonQuery.compile(jqString); final JsonNode node = getMapper().valueToTree(new PaymentRequest()); final List<JsonNode> patched = jq.apply(node); response = paymentFacade.commitPayment( getMapper().treeToValue(patched.get(0), PaymentRequest.class), redirectComponents); } catch (final JsonProcessingException jsonEx) { LOG.error("Failed in json processing", jsonEx); response.put("error", "internal error"); } } return response; }
From source file:com.hortonworks.registries.storage.util.StorageUtils.java
public static Optional<Pair<Field, Long>> getVersionFieldValue(Storable storable) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { for (Pair<Field, Object> kv : getAnnotatedFieldValues(storable, VersionField.class)) { if (kv.getValue() instanceof Long) { return Optional.of(Pair.of(kv.getKey(), (Long) kv.getValue())); }/*from w ww .j a v a 2 s. com*/ } return Optional.empty(); }
From source file:com.github.steveash.guavate.GuavateTest.java
@Test public void test_zip() { Stream<String> base1 = Stream.of("a", "b", "c"); Stream<Integer> base2 = Stream.of(1, 2, 3); List<Pair<String, Integer>> test = Guavate.zip(base1, base2).collect(Collectors.toList()); assertEquals(test, ImmutableList.of(Pair.of("a", 1), Pair.of("b", 2), Pair.of("c", 3))); }
From source file:com.flowpowered.api.util.SyncedStringMap.java
@Override public int register(String key) { Integer id = store.get(key);/* www. j av a 2 s.com*/ if (id != null) { return id; } int local = super.register(key); callEvent(new SyncedMapEvent(this, SyncedMapEvent.Action.ADD, Arrays.asList(Pair.of(local, key)))); return local; }
From source file:edu.wpi.checksims.util.PairGeneratorTest.java
@Test public void TestGenerateFromTwoElementSet() { Set<Submission> submissions = setFromElements(a, b); Set<Pair<Submission, Submission>> expected = singleton(Pair.of(a, b)); Set<Pair<Submission, Submission>> results = PairGenerator.generatePairs(submissions); checkPairsAreInSet(results, expected); }
From source file:com.samsung.sjs.backend.CBackend.java
/** * Returns a new ID for a new vtable, or the id of an existing * vtable if argument vt is identical to a previous vtable array. *///from w ww .ja v a 2 s . co m protected int memo_vtable(int[] vt) { int result = -1; int hash = Arrays.hashCode(vt); int oldsize = vtables_by_hash.size(); int oldsetsize = -1; boolean collision = false; if (vtables_by_hash.containsKey(hash)) { Set<Pair<int[], Integer>> possible_matches = vtables_by_hash.get(hash); assert (possible_matches != null); for (Pair<int[], Integer> test : possible_matches) { if (Arrays.equals(test.getKey(), vt)) { collision = true; result = test.getValue(); } } if (!collision) { // We hit an existing has bucket, but don't match result = next_vtable_id++; Pair<int[], Integer> newpair = Pair.of(vt, result); oldsetsize = possible_matches.size(); possible_matches.add(newpair); assert (possible_matches.size() > oldsetsize); } } else { // We don't match any existing bucket result = next_vtable_id++; Pair<int[], Integer> newpair = Pair.of(vt, result); Set<Pair<int[], Integer>> newset = new HashSet<Pair<int[], Integer>>(); newset.add(newpair); vtables_by_hash.put(hash, newset); assert (vtables_by_hash.size() >= oldsize); } assert (result >= 0); // we initialize next_vtable_id to 0, so -1 is invalid return result; }
From source file:com.github.blindpirate.gogradle.util.MapUtils.java
@SuppressWarnings("unchecked") public static <K, V> Map<K, V> asMap(K k, V v) { return asMapWithoutNull(Pair.of(k, v)); }