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:enumj.EnumerableTest.java
@Test public void testOn() { System.out.println("on"); EnumerableGenerator.generatorPairs().limit(100) .map(p -> Pair.of(p.getLeft().onEnumerable(), p.getRight().onEnumerable())) .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight()))); }
From source file:net.lldp.checksims.util.PairGenerator.java
/** * Generate all pairs for normal submissions, and pairs for archive submissions to compare to normal submissions. * * @param submissions Normal submissions - compared to each other and archive submissions * @param archiveSubmissions Archive submissions - only compared to normal submissions, not each other * @return Set of all unordered pairs required for comparison with archive directory *//*from www. jav a 2s. com*/ public static Set<Pair<Submission, Submission>> generatePairsWithArchive(Set<Submission> submissions, Set<Submission> archiveSubmissions) { checkNotNull(submissions); checkNotNull(archiveSubmissions); // TODO it may be desirable to allow comparison of a single submission to an archive // However, generatePairs fails if only 1 submission is given // (This would also require tweaks in the frontend) Set<Pair<Submission, Submission>> basePairs = generatePairs(submissions); // If we have no archive submissions, just return the same result generatePairs would if (archiveSubmissions.isEmpty()) { return basePairs; } // Now we need to add pairs for the archive submissions List<Submission> remaining = new ArrayList<>(); remaining.addAll(archiveSubmissions); // Loop through each archive submission while (!remaining.isEmpty()) { Submission first = remaining.get(0); remaining.remove(0); // For each archive submission, generate pairs for each normal submission for (Submission s : submissions) { Pair<Submission, Submission> pair = Pair.of(first, s); Pair<Submission, Submission> reversed = Pair.of(s, first); // Something's wrong, we've made a duplicate pair (but reversed) // Should never happen if (basePairs.contains(reversed)) { throw new RuntimeException("Internal error in pair generation: duplicate pair produced!"); } // One pair for each normal submission, consisting of the archive submission and the normal submission basePairs.add(pair); } } return basePairs; }
From source file:com.twitter.distributedlog.client.proxy.TestProxyClientManager.java
private static Pair<MockProxyClient, MockServerInfoService> createMockProxyClient(SocketAddress address, ServerInfo serverInfo) {//w w w. j ava 2 s. c o m MockServerInfoService service = new MockServerInfoService(); MockProxyClient proxyClient = new MockProxyClient(address, service); service.updateServerInfo(serverInfo); return Pair.of(proxyClient, service); }
From source file:io.mandrel.data.extract.ExtractorService.java
public Pair<Set<Link>, Set<Link>> extractAndFilterOutlinks(Spider spider, Uri uri, Map<String, Instance<?>> cachedSelectors, Blob blob, OutlinkExtractor ol) { // Find outlinks in page Set<Link> outlinks = extractOutlinks(cachedSelectors, blob, ol); log.trace("Finding outlinks for url {}: {}", uri, outlinks); // Filter outlinks Set<Link> filteredOutlinks = null; if (outlinks != null) { Stream<Link> stream = outlinks.stream().filter(l -> l != null && l.getUri() != null); if (spider.getFilters() != null && CollectionUtils.isNotEmpty(spider.getFilters().getLinks())) { stream = stream/* ww w . j ava 2 s .c o m*/ .filter(link -> spider.getFilters().getLinks().stream().allMatch(f -> f.isValid(link))); } filteredOutlinks = stream.collect(Collectors.toSet()); } Set<Link> allFilteredOutlinks = null; if (filteredOutlinks != null) { Set<Uri> res = MetadataStores.get(spider.getId()) .deduplicate(filteredOutlinks.stream().map(l -> l.getUri()).collect(Collectors.toList())); allFilteredOutlinks = filteredOutlinks.stream().filter(f -> res.contains(f.getUri())) .collect(Collectors.toSet()); } log.trace("And filtering {}", allFilteredOutlinks); return Pair.of(outlinks, allFilteredOutlinks); }
From source file:com.yahoo.elide.parsers.state.RecordTerminalState.java
@Override public Supplier<Pair<Integer, JsonNode>> handleDelete(StateContext state) { try {/*ww w . j a v a2s.co m*/ record.deleteResource(); return () -> Pair.of(HttpStatus.SC_NO_CONTENT, null); } catch (ForbiddenAccessException e) { return () -> Pair.of(e.getStatus(), null); } }
From source file:com.formkiq.core.webflow.FlowManager.java
/** * Gets the SessionKey from the Execution Parameter. * @param webflowkey {@link String}/* w w w .ja va2s.c om*/ * @return {@link Pair} */ public static Pair<String, Integer> getExecutionSessionKey(final String webflowkey) { String s = null; Integer e = null; if (StringUtils.hasText(webflowkey)) { TokenizerService ts = new TokenizerServiceImpl(webflowkey); Optional<TokenizerToken> session = ts.nextToken(); Optional<TokenizerToken> sessionNo = ts.nextToken(); Optional<TokenizerToken> event = ts.nextToken(); Optional<TokenizerToken> eventNo = ts.nextToken(); boolean tokensPresent = session.isPresent() && sessionNo.isPresent() && event.isPresent() && eventNo.isPresent(); if (tokensPresent && session.get().getType().equals(TokenType.STRING) && sessionNo.get().getType().equals(TokenType.INTEGER) && event.get().getType().equals(TokenType.STRING) && eventNo.get().getType().equals(TokenType.INTEGER)) { s = session.get().getValue() + sessionNo.get().getValue(); e = Integer.valueOf(eventNo.get().getValue()); } } return Pair.of(s, e); }
From source file:de.tudarmstadt.ukp.dkpro.core.mallet.internal.wordembeddings.MalletEmbeddingsUtils.java
/** * Convert a single line in the expected format ({@code <token> <value1> ... <valueN>} int a pair * holding the token and the corresponding vector. * * @param line a line/*from ww w .ja va 2 s . c o m*/ * @return a {@link Pair} */ private static Pair<String, double[]> lineToEmbedding(String line) { String[] array = line.split(" "); int size = array.length; double[] vector = Arrays.stream(array, 1, size).mapToDouble(Double::parseDouble).toArray(); return Pair.of(array[0], vector); }
From source file:io.knotx.mocks.adapter.MockActionAdapterHandler.java
private Pair<Optional<String>, JsonObject> toTransitionPair(Map.Entry<String, Object> entry) { return Pair.of(Optional.of(entry.getKey()), ((JsonObject) entry.getValue()).getJsonObject("response")); }
From source file:net.community.chest.gitcloud.facade.ConfigUtils.java
/** * Resolves the location of the <code>gitcloud.base</code> location as follows:</BR> * <OL>/*from w w w . j ava 2 s .c om*/ * <LI> * Checks if there is already a definition for the <code>gitcloud.base</code> * property. If so, then uses it * </LI> * * <LI> * Ensures that there is a definition for the <code>catalina.base</code> * property and defines <code>gitcloud.base</code> to be the <code>gitcloud</code> * <U>sub-folder</U> * </LI> * </OL> * @param resolver The {@link PlaceholderResolver} to use for the resolution of the * various required properties * @return A {@link Pair} where the left-hand is the resolved {@link File} location * of <code>gitcloud.base</code> and right-hand is a {@link Boolean} representing * whether the property was already defined (<code>true</code>) or had to * use the <code>catalina.base</code> property (<code>false</code>) */ public static final Pair<File, Boolean> resolveGitcloudBase(PlaceholderResolver resolver) { String baseValue = resolver.resolvePlaceholder(ConfigUtils.GITCLOUD_BASE_PROP); if (!StringUtils.isEmpty(baseValue)) { return Pair.of(new File(baseValue), Boolean.TRUE); } String catalinaBase = resolver.resolvePlaceholder("catalina.base"); if (StringUtils.isEmpty(catalinaBase)) { throw new IllegalStateException("No catalina.base value available"); } return Pair.of(new File(catalinaBase, "gitcloud"), Boolean.FALSE); }
From source file:blusunrize.immersiveengineering.client.models.ModelItemDynamicOverride.java
@Override public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType) { return Pair.of(cameraTransformType == TransformType.GUI ? guiModel : this, itemModel.handlePerspective(cameraTransformType).getRight()); }