List of usage examples for org.apache.commons.lang3.tuple Triple of
public static <L, M, R> Triple<L, M, R> of(final L left, final M middle, final R right)
Obtains an immutable triple of from three objects inferring the generic types.
This factory allows the triple to be created using inference to obtain the generic types.
From source file:fr.landel.utils.commons.function.TriSupplierThrowableTest.java
/** * Test method for {@link TriSupplierThrowable#getThrows()}. *//*from w w w . j a va 2s .com*/ @Test public void testGetThrows() { boolean test = false; final String error = "error"; final TriSupplierThrowable<String, String, String, IllegalArgumentException> s1 = () -> Triple.of("l", "m", "r"); final TriSupplierThrowable<String, String, String, IOException> s2 = () -> { if (test) { return Triple.of("l", "m", "r"); } throw new IOException(error); }; try { assertEquals("(l,m,r)", s1.getThrows().toString()); } catch (IllegalArgumentException e) { fail("Supplier failed"); } try { s2.getThrows(); fail("Supplier has to fail"); } catch (IOException e) { assertNotNull(e); assertEquals(error, e.getMessage()); } }
From source file:com.qq.tars.service.SetTriple.java
public Triple getTriple() { return Triple.of(setName, setArea, setGroup); }
From source file:com.act.lcms.v2.fullindex.SearcherTest.java
@Test public void searchIndexInRange() throws Exception { List<TMzI> actual = searcher.searchIndexInRange(Pair.of(100.004, 100.016), Pair.of(1.5, 3.5)); List<Triple<Float, Double, Float>> expected = Arrays.asList(Triple.of(2.0F, 100.005, 10.0F), Triple.of(2.0F, 100.010, 20.0F), Triple.of(2.0F, 100.015, 30.0F), Triple.of(3.0F, 100.010, 100.0F), Triple.of(3.0F, 100.015, 200.0F)); assertEquals("Searcher returned expected number of TMzI tuples", expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { Triple<Float, Double, Float> e = expected.get(i); TMzI a = actual.get(i);//from w w w. ja v a2s .co m assertEquals("Time matches expected", e.getLeft(), a.getTime(), FP_TOLERANCE); assertEquals("M/z matches expected", e.getMiddle(), a.getMz(), FP_TOLERANCE); assertEquals("Intensity matches expected", e.getRight(), a.getIntensity(), FP_TOLERANCE); } }
From source file:de.ellpeck.actuallyadditions.mod.blocks.BlockGreenhouseGlass.java
public static Triple<BlockPos, IBlockState, IGrowable> firstBlock(World world, BlockPos glassPos) { BlockPos.MutableBlockPos mut = new BlockPos.MutableBlockPos(glassPos); while (true) { mut.setPos(mut.getX(), mut.getY() - 1, mut.getZ()); if (mut.getY() < 0) return null; IBlockState state = world.getBlockState(mut); if (state.isOpaqueCube() || state.getBlock() instanceof IGrowable) { if (state.getBlock() instanceof IGrowable) return Triple.of(mut.toImmutable(), state, (IGrowable) state.getBlock()); else/*from w ww. j av a2s .c o m*/ return null; } } }
From source file:com.uber.hoodie.common.util.collection.converter.HoodieRecordConverter.java
@Override public byte[] getBytes(HoodieRecord hoodieRecord) { try {//from w ww . j ava 2 s . c o m // Need to initialize this to 0 bytes since deletes are handled by putting an empty record in HoodieRecord byte[] val = new byte[0]; if (hoodieRecord.getData().getInsertValue(schema).isPresent()) { val = HoodieAvroUtils .avroToBytes((GenericRecord) hoodieRecord.getData().getInsertValue(schema).get()); } byte[] currentLocation = hoodieRecord.getCurrentLocation() != null ? SerializationUtils.serialize(hoodieRecord.getCurrentLocation()) : new byte[0]; byte[] newLocation = hoodieRecord.getNewLocation().isPresent() ? SerializationUtils.serialize((HoodieRecordLocation) hoodieRecord.getNewLocation().get()) : new byte[0]; // Triple<Pair<RecordKey, PartitionPath>, Pair<oldLocation, newLocation>, data> Triple<Pair<String, String>, Pair<byte[], byte[]>, byte[]> data = Triple.of( Pair.of(hoodieRecord.getKey().getRecordKey(), hoodieRecord.getKey().getPartitionPath()), Pair.of(currentLocation, newLocation), val); return SerializationUtils.serialize(data); } catch (IOException io) { throw new HoodieNotSerializableException("Cannot serialize value to bytes", io); } }
From source file:edu.umd.umiacs.clip.tools.math.StatisticalTests.java
private static Triple<Double, Double, Double> pRecPrecF1(int pos, int tpboth, int tp0only, int tp1only, int fpboth, int fp0only, int fp1only) { double delta_f1 = Math.abs(f1(tp0only + tpboth, fp0only + fpboth, pos - (tp0only + tpboth)) - f1(tp1only + tpboth, fp1only + fpboth, pos - (tp1only + tpboth))); double delta_rec = Math.abs( rec(tp0only + tpboth, pos - (tp0only + tpboth)) - rec(tp1only + tpboth, pos - (tp1only + tpboth))); double delta_prec = Math .abs(prec(tp0only + tpboth, fp0only + fpboth) - prec(tp1only + tpboth, fp1only + fpboth)); AtomicInteger nc_f1 = new AtomicInteger(); AtomicInteger nc_rec = new AtomicInteger(); AtomicInteger nc_prec = new AtomicInteger(); range(0, NT).forEach(j -> {/*from ww w . ja va2 s . c om*/ int tp[] = nextPair(tp0only, tp1only, tpboth); int fp[] = nextPair(fp0only, fp1only, fpboth); if (Math.abs(f1(tp[0], fp[0], pos - tp[0]) - f1(tp[1], fp[1], pos - tp[1])) > delta_f1) { nc_f1.incrementAndGet(); } if (Math.abs(rec(tp[0], pos - tp[0]) - rec(tp[1], pos - tp[1])) > delta_rec) { nc_rec.incrementAndGet(); } if (Math.abs(prec(tp[0], fp[0]) - prec(tp[1], fp[1])) > delta_prec) { nc_prec.incrementAndGet(); } }); return Triple.of((nc_rec.get() + 1.) / (NT + 1), (nc_prec.get() + 1.) / (NT + 1), (nc_f1.get() + 1.) / (NT + 1)); }
From source file:ivorius.ivtoolkit.maze.components.MazeComponentConnector.java
private static <M extends WeightedMazeComponent<C>, C> void addAllExits( MazeComponentPlacementStrategy<M, C> placementStrategy, Deque<Triple<MazeRoom, MazeRoomConnection, C>> exitStack, Set<Map.Entry<MazeRoomConnection, C>> entries) { for (Map.Entry<MazeRoomConnection, C> exit : entries) { if (placementStrategy.shouldContinue(exit.getKey().getLeft())) exitStack.add(Triple.of(exit.getKey().getLeft(), exit.getKey(), exit.getValue())); if (placementStrategy.shouldContinue(exit.getKey().getRight())) exitStack.add(Triple.of(exit.getKey().getRight(), exit.getKey(), exit.getValue())); }/*from ww w . j ava 2 s . c o m*/ }
From source file:com.vmware.identity.openidconnect.server.LoginProcessor.java
public Triple<PersonUser, SessionID, LoginMethod> process() throws LoginException { String sessionIdString = this.httpRequest.getCookieValue(SessionManager.getSessionCookieName(this.tenant)); if (sessionIdString != null) { SessionID sessionId = new SessionID(sessionIdString); SessionManager.Entry entry = this.sessionManager.get(sessionId); if (entry != null) { return Triple.of(entry.getPersonUser(), sessionId, (LoginMethod) null); }//from ww w . j av a2s. co m } String loginString = this.httpRequest.getParameters().get(REQUEST_LOGIN_PARAMETER); if (loginString == null) { return Triple.of((PersonUser) null, (SessionID) null, (LoginMethod) null); } String[] parts = loginString.split(" "); if (parts[0].isEmpty()) { throw new LoginException("invalid login string", localize(ErrorMessage.BAD_REQUEST)); } LoginMethod loginMethod; try { loginMethod = LoginMethod.parse(parts[0]); } catch (ParseException e) { throw new LoginException("invalid login method", localize(ErrorMessage.BAD_REQUEST), e); } PersonUser personUser; switch (loginMethod) { case PASSWORD: personUser = processPasswordLogin(loginString); break; case PERSON_USER_CERTIFICATE: personUser = processPersonUserCertificateLogin(); break; case GSS_TICKET: personUser = processGssTicketLogin(loginString); break; case SECURID: personUser = processSecurIDLogin(loginString); break; default: throw new IllegalStateException("unexpected login method: " + loginMethod); } return Triple.of(personUser, new SessionID(), loginMethod); }
From source file:com.replaymod.replaystudio.pathing.serialize.LegacyTimelineConverter.java
@SuppressWarnings("unchecked") private static Timeline convert(PathingRegistry registry, KeyframeSet keyframeSet) { Timeline timeline = registry.createTimeline(); Property timestamp = timeline.getProperty("timestamp"); Property cameraPosition = timeline.getProperty("camera:position"); Property cameraRotation = timeline.getProperty("camera:rotation"); Path timePath = timeline.createPath(); Path positionPath = timeline.createPath(); for (Keyframe<AdvancedPosition> positionKeyframe : keyframeSet.positionKeyframes) { AdvancedPosition value = positionKeyframe.value; com.replaymod.replaystudio.pathing.path.Keyframe keyframe = getKeyframe(positionPath, positionKeyframe.realTimestamp); keyframe.setValue(cameraPosition, Triple.of(value.x, value.y, value.z)); keyframe.setValue(cameraRotation, Triple.of(value.yaw, value.pitch, value.roll)); if (value instanceof SpectatorData) { // TODO Spectator keyframes }/*ww w. j a va2 s . com*/ } for (Keyframe<TimestampValue> timeKeyframe : keyframeSet.timeKeyframes) { TimestampValue value = timeKeyframe.value; com.replaymod.replaystudio.pathing.path.Keyframe keyframe = getKeyframe(timePath, timeKeyframe.realTimestamp); keyframe.setValue(timestamp, (int) value.value); } Interpolator timeInterpolator = new LinearInterpolator(); timeInterpolator.registerProperty(timestamp); timePath.getSegments().forEach(s -> s.setInterpolator(timeInterpolator)); Interpolator positionInterpolator = new CubicSplineInterpolator(); positionInterpolator.registerProperty(cameraPosition); positionInterpolator.registerProperty(cameraRotation); positionPath.getSegments().forEach(s -> s.setInterpolator(positionInterpolator)); return timeline; }
From source file:mtsar.processors.task.InverseCountAllocator.java
List<Integer> filterTasks(Map<Integer, Integer> counts) {
return counts.entrySet().stream().map(entry -> Triple.of(entry.getKey(), entry.getValue(), Math.random()))
.sorted(INVERSE_COUNT).map(Triple::getLeft).collect(Collectors.toList());
}