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:ivorius.ivtoolkit.rendering.grid.GridQuadCache.java
protected static <T> void addToCache(Map<QuadContext<T>, CoordGrid> cache, Function<Pair<BlockCoord, ForgeDirection>, T> mapper, ForgeDirection direction, BlockCoord coord) { T t = mapper.apply(Pair.of(coord, direction)); if (t != null) { int[] sAxes = getCacheAxes(direction, coord.x, coord.y, coord.z); addToCache(cache, new QuadContext<>(sAxes[0], direction, t), sAxes[1], sAxes[2]); }/*from w ww . j a v a 2s. co m*/ }
From source file:net.lldp.checksims.algorithm.AlgorithmRunnerTest.java
@Test public void TestRunAlgorithmTwoPairs() throws ChecksimsException { Set<Pair<Submission, Submission>> submissions = setFromElements(Pair.of(a, b), Pair.of(a, c)); Collection<AlgorithmResults> results = AlgorithmRunner.runAlgorithm(submissions, detectNothing, logger); AlgorithmUtils.checkResultsContainsPairs(results, submissions); }
From source file:alfio.manager.CheckInManager.java
public TicketAndCheckInResult confirmOnSitePayment(String eventName, String ticketIdentifier, Optional<String> ticketCode, String user) { return eventRepository.findOptionalByShortName(eventName) .flatMap(e -> confirmOnSitePayment(ticketIdentifier).map((String s) -> Pair.of(s, e))) .map(p -> checkIn(p.getRight().getId(), ticketIdentifier, ticketCode, user)) .orElseGet(() -> new TicketAndCheckInResult(null, new DefaultCheckInResult(CheckInStatus.TICKET_NOT_FOUND, ""))); }
From source file:com.act.lcms.v2.MassChargeCalculatorTest.java
@Test public void testMakeMassChargeMap() throws Exception { List<MassChargeCalculator.MZSource> sources = Arrays.asList( new MassChargeCalculator.MZSource("InChI=1S/C7H7NO2/c8-6-3-1-5(2-4-6)7(9)10/h1-4H,8H2,(H,9,10)"), // PABA new MassChargeCalculator.MZSource("InChI=1S/C7H7NO2/c1-10-7(9)6-3-2-4-8-5-6/h2-5H,1H3")); // Something crazy. MassChargeCalculator.MassChargeMap massChargeMap = MassChargeCalculator.makeMassChargeMap(sources, new HashSet<>(Arrays.asList("M+H", "M+Na"))); Double expectedMonoMass = 137.047679; List<Double> expectedIonMZs = Arrays.asList(138.054979, 160.036879); // M+H and M+Na of PABA // This is package private, but we'll use its ordering to speed testing. List<Double> actualIonMasses = massChargeMap.ionMZsSorted(); assertEqualsWithFPErr("Unique ionic masses match expected list", expectedIonMZs, actualIonMasses); assertEqualsPairWithFPErr("M+H ion mz maps to source mass and ion name", Arrays.asList(Pair.of("M+H", expectedMonoMass)), massChargeMap.ionMZtoMonoMassAndIonName(actualIonMasses.get(0))); assertEqualsPairWithFPErr("M+Na ion mz maps to source mass and ion name", Arrays.asList(Pair.of("M+Na", expectedMonoMass)), massChargeMap.ionMZtoMonoMassAndIonName(actualIonMasses.get(1))); // Test reverse mapping. for (Double ionMZ : actualIonMasses) { assertEquals(String.format("Ionic masses for %f map to two MZSources", ionMZ), new HashSet<>(sources), massChargeMap.ionMZToMZSources(ionMZ)); }/*w ww . ja v a 2 s .c o m*/ // Test iterators cover all values. assertEqualsWithFPErr("Iterable ionMZs match expected", new HashSet<>(expectedIonMZs), StreamSupport.stream(massChargeMap.ionMZIter().spliterator(), false).collect(Collectors.toSet())); assertEqualsWithFPErr("Iterable monoisotopic masses match expected", Collections.singleton(expectedMonoMass), StreamSupport.stream(massChargeMap.monoisotopicMassIter().spliterator(), false) .collect(Collectors.toSet())); assertEquals("Iterable mzSources match expected", new HashSet<>(sources), StreamSupport .stream(massChargeMap.mzSourceIter().spliterator(), false).collect(Collectors.toSet())); }
From source file:de.upb.wdqa.wdvd.ItemDiff.java
public List<Pair<Statement, Statement>> getChangedClaims() { Map<Object, Statement> oldMap = getStatementMap(oldItem.getAllStatements()); Map<Object, Statement> newMap = getStatementMap(newItem.getAllStatements()); MapDiff diff = new MapDiff(oldMap, newMap); Set<Object> changedKeys = diff.getChangedKeys(); List<Pair<Statement, Statement>> result = new ArrayList<Pair<Statement, Statement>>(); for (Object key : changedKeys) { result.add(Pair.of(oldMap.get(key), newMap.get(key))); }/* w w w. ja va 2s. com*/ return result; }
From source file:com.github.rvesse.airline.parser.ParseState.java
public ParseState<T> withOptionValue(OptionMetadata option, String rawValue) { // Pre-validate for (OptionRestriction restriction : option.getRestrictions()) { restriction.preValidate(this, option, rawValue); }// w w w . j a v a2s .c om // Convert value Object value = this.parserConfig.getTypeConverter().convert(option.getTitle(), option.getJavaType(), rawValue); // Post-validate for (OptionRestriction restriction : option.getRestrictions()) { restriction.postValidate(this, option, value); } List<Pair<OptionMetadata, Object>> newOptions = AirlineUtils.listCopy(parsedOptions); newOptions.add(Pair.of(option, value)); return new ParseState<T>(global, parserConfig, group, command, newOptions, locationStack, parsedArguments, currentOption, unparsedInput); }
From source file:net.jaspr.chatalerts.network.message.NetworkMessage.java
public static <T extends Object> void mapHandler(Class<T> type, Reader<T> reader, Writer<T> writer) { handlers.put(type, Pair.of(reader, writer)); }
From source file:com.uber.hoodie.common.util.CompactionUtils.java
/** * Get all pending compaction plans along with their instants * * @param metaClient Hoodie Meta Client/*from w w w. j av a 2 s . c o m*/ */ public static List<Pair<HoodieInstant, HoodieCompactionPlan>> getAllPendingCompactionPlans( HoodieTableMetaClient metaClient) { List<HoodieInstant> pendingCompactionInstants = metaClient.getActiveTimeline() .filterPendingCompactionTimeline().getInstants().collect(Collectors.toList()); return pendingCompactionInstants.stream().map(instant -> { try { HoodieCompactionPlan compactionPlan = AvroUtils .deserializeCompactionPlan(metaClient.getActiveTimeline() .getInstantAuxiliaryDetails( HoodieTimeline.getCompactionRequestedInstant(instant.getTimestamp())) .get()); return Pair.of(instant, compactionPlan); } catch (IOException e) { throw new HoodieException(e); } }).collect(Collectors.toList()); }
From source file:com.Da_Technomancer.crossroads.API.packets.Message.java
private static <T extends Object> void map(Class<T> type, Reader<T> reader, Writer<T> writer) { handlers.put(type, Pair.of(reader, writer)); }
From source file:com.teradata.tempto.internal.hadoop.hdfs.WebHDFSClient.java
@Override public void delete(String path, String username) { Pair[] params = { Pair.of("recursive", "true") }; HttpDelete removeFileOrDirectoryRequest = new HttpDelete(buildUri(path, username, "DELETE", params)); try (CloseableHttpResponse response = httpClient.execute(removeFileOrDirectoryRequest)) { if (response.getStatusLine().getStatusCode() != SC_OK) { throw invalidStatusException("DELETE", path, username, removeFileOrDirectoryRequest, response); }//from w ww . java 2s . c o m logger.debug("Removed file or directory {} - username: {}", path, username); } catch (IOException e) { throw new RuntimeException("Could not remove file or directory " + path + " in hdfs, user: " + username, e); } }