List of usage examples for org.apache.commons.lang3.tuple Triple getLeft
public abstract L getLeft();
Gets the left element from this triple.
From source file:edu.nyu.tandon.tool.BinnedRawHits.java
private static void dumpPosthits(BinnedRawHits query, long numDocs, boolean endRun) { Collections.sort(query.postHits); ImmutableTriple<Integer, Integer, Integer> t; Triple<Integer, Integer, Integer> lastT = new MutableTriple<>(-1, -1, -1); int hits = 0; for (int i = 0; i < query.postHits.size(); i++) { t = query.postHits.get(i);// ww w . j av a 2s .com if (t.compareTo(lastT) != 0) { if (hits > 0) { // format: doc, term, , rank, #hits query.outputPH.printf("%d,%d,%d,%d\n", lastT.getLeft(), lastT.getMiddle(), lastT.getRight(), hits); } hits = 0; lastT = t; } hits++; } query.postHits.clear(); if (query.outputDH != System.out) { query.outputPH.close(); } if (!endRun) { try { query.outputPH = new PrintStream(new FastBufferedOutputStream( new FileOutputStream(outputName + "-" + phBatch++ + ".ph.txt"))); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
From source file:hu.mta.sztaki.lpds.cloud.simulator.iaas.statenotifications.VMStateChangeNotificationHandler.java
/** * The event handling mechanism for VM state change notifications * /*from w w w .j av a 2s. co m*/ * @param onObject * The listener to send the event to * @param stateData * a data triplet containing the VM and its the past and future * states. */ @Override public void sendNotification(final StateChange onObject, Triple<VirtualMachine, State, State> stateData) { onObject.stateChanged(stateData.getLeft(), stateData.getMiddle(), stateData.getRight()); }
From source file:fr.landel.utils.assertor.helper.HelperAssertor.java
/** * The combine function (the main method). This method is called by each end * steps./*from ww w . ja va2s .c o m*/ * * <p> * What is matcher mode: it's an Assertor starting with * "{@code Assertor.matcher}...". In this mode, only one variable can be * checked through "{@code on(object)}" method. The aim of this is to create * the validation steps before in another method or in a static way to * improve performance. * </p> * * @param step * the last step * @param object * the object to test (only in matcher mode) * @param marcherMode * if it's in matcher mode (set with "on" method) * @param loadMessage * if the message has to beloaded and formated * @param <T> * the type of checked object * @return the result * @throws IllegalArgumentException * if in matcher mode and object is not set */ public static <T> ResultAssertor combine(final StepAssertor<T> step, final Object object, final boolean marcherMode, final boolean loadMessage) { final List<StepAssertor<?>> steps = validatesAndReverse(step, marcherMode); boolean not = false; boolean valid = true; PairIso<Boolean> resultValid; EnumOperator operator = null; final MessagesAssertor messages = new MessagesAssertor(); Object obj; final Object matcherObject; boolean checked = false; EnumType type = null; ParameterAssertor<?> param = null; final List<ParameterAssertor<?>> parameters = new ArrayList<>(); Optional<Pair<Boolean, MessagesAssertor>> dontNeedCheck = Optional.empty(); // get the object to check // in matcher mode, two ways are available to inject the object: // - first: directly through the combine function boolean inMatcherMode = marcherMode; if (inMatcherMode) { obj = object; // - second: } else if (EnumStep.PREDICATE_OBJECT.equals(step.getStepType())) { obj = step.getObject(); inMatcherMode = true; } else { obj = null; } // create a temporary variable for sub steps (in matcher mode) matcherObject = obj; for (StepAssertor<?> s : steps) { if (s.getStepType() == null) { continue; } switch (s.getStepType()) { // the first step of an Assertor in predicate mode (ex: // Assertor.ofNumber...) case PREDICATE: type = s.getType(); if (EnumType.UNKNOWN.equals(type)) { type = EnumType.getType(obj); } param = new ParameterAssertor<>(obj, type, true); parameters.add(param); break; // the first step of an Assertor (ex: Assertor.that(object)...) case CREATION: obj = s.getObject(); type = s.getType(); checked = s.isChecked(); param = new ParameterAssertor<>(obj, type, checked); parameters.add(param); break; // the validation step case ASSERTION: parameters.addAll(s.getParameters()); // if precondition returns false, we end all treatments if (!HelperAssertor.preCheck(s, obj)) { return HelperAssertor.getPreconditionMessage(s, param, parameters, loadMessage); } else { resultValid = HelperAssertor.validatesAndGetMessage(s, param, obj, valid, not, operator, messages, loadMessage); valid = resultValid.getRight(); } if (operator != null && !valid) { dontNeedCheck = checkValidityAndOperator(resultValid.getLeft(), operator, messages, loadMessage); } not = false; break; // the combining step between two validation steps case OPERATOR: operator = s.getOperator(); dontNeedCheck = checkValidityAndOperator(valid, operator, messages, loadMessage); break; // the not step to reverse the next validation step case NOT: not = not ^ s.isNot(); break; // the object provided by the mapper case PROPERTY: if (s.getMapper().isPresent()) { operator = s.getOperator(); obj = s.getMapper().get().apply(obj); type = s.getType(); checked = s.isChecked(); param = new ParameterAssertor<>(obj, type, checked); parameters.add(param); dontNeedCheck = checkValidityAndOperator(valid, operator, messages, loadMessage); } else { throw new IllegalStateException("property cannot be null"); } break; // the other object to validate case OBJECT: operator = s.getOperator(); obj = s.getObject(); type = s.getType(); checked = s.isChecked(); param = new ParameterAssertor<>(obj, type, checked); parameters.add(param); dontNeedCheck = checkValidityAndOperator(valid, operator, messages, loadMessage); break; // the sub step to emulate parenthesis in a check (ex: // Assertor.that(2).isZero().or(Assertor.that(2).isGTE(1).and().isLTE(10))) case SUB: if (s.getSubStep().isPresent()) { dontNeedCheck = checkValidityAndOperator(valid, s.getOperator(), messages, loadMessage); if (!dontNeedCheck.isPresent()) { final Triple<Boolean, EnumOperator, ResultAssertor> output = HelperAssertor.managesSub(s, matcherObject, inMatcherMode, parameters, valid, operator, messages, loadMessage); if (output.getRight() != null) { return output.getRight(); } else { valid = output.getLeft(); operator = output.getMiddle(); } } } break; // sub assertor step to check sub properties case SUB_ASSERTOR: if (s.getSubAssertor().isPresent()) { operator = s.getOperator(); dontNeedCheck = checkValidityAndOperator(valid, operator, messages, loadMessage); if (!dontNeedCheck.isPresent()) { final Step<?, ?> stepSubAssertor = Objects.requireNonNull( s.getSubAssertor().get().apply(obj), "Sub assertor mapper cannot be null"); final ResultAssertor intermediateResult = combine(stepSubAssertor.getStep(), null, inMatcherMode, loadMessage); valid = intermediateResult.isPrecondition() && isValid(valid, intermediateResult.isValid(), operator); parameters.addAll(intermediateResult.getParameters()); if (!valid && loadMessage && intermediateResult.getMessages() != null) { if (messages.isNotEmpty()) { messages.append(operator); } messages.append(intermediateResult.getMessages()); } if (intermediateResult.isPrecondition()) { dontNeedCheck = checkValidityAndOperator(intermediateResult.isValid(), operator, messages, loadMessage); } else { dontNeedCheck = Optional.of(Pair.of(false, intermediateResult.getMessages())); } } } else { throw new IllegalStateException("sub assertor cannot be null"); } break; default: // MATCHER_OBJECT (don't need treatment) } if (dontNeedCheck.isPresent()) { return new ResultAssertor(true, dontNeedCheck.get().getKey(), dontNeedCheck.get().getValue(), parameters); } } return new ResultAssertor(true, valid, messages, parameters); }
From source file:io.github.autsia.crowly.services.geolocation.impl.GeoLocationServiceImpl.java
@Override public GeoCode convertCoordinatesToGeoCode(Triple<Double, Double, Double> location) { return new GeoCode(location.getLeft(), location.getMiddle(), location.getRight().intValue()); }
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 .j av a 2s.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:cherry.goods.telno.TelNoNormalizerImpl.java
private String[] split(String telNo, Triple<Integer, Integer, Integer> triple) { if (telNo.length() <= triple.getLeft()) { return new String[] { telNo }; }/*from ww w . ja v a 2s .c om*/ String first = telNo.substring(0, triple.getLeft()); if (telNo.length() <= triple.getLeft() + triple.getMiddle()) { String second = telNo.substring(triple.getLeft()); return new String[] { first, second }; } String second = telNo.substring(triple.getLeft(), triple.getLeft() + triple.getMiddle()); String third = telNo.substring(triple.getLeft() + triple.getMiddle()); return new String[] { first, second, third }; }
From source file:com.nttec.everychan.ui.gallery.GalleryInitResult.java
@Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(initPosition);/* w w w. j av a 2 s .co m*/ dest.writeInt(shouldWaitForPageLoaded ? 1 : 0); dest.writeInt(attachments.size()); for (Triple<AttachmentModel, String, String> tuple : attachments) { AttachmentModel attachment = tuple.getLeft(); dest.writeInt(attachment.type); dest.writeInt(attachment.size); dest.writeString(attachment.thumbnail); dest.writeString(attachment.path); dest.writeInt(attachment.width); dest.writeInt(attachment.height); dest.writeString(attachment.originalName); dest.writeInt(attachment.isSpoiler ? 1 : 0); dest.writeString(tuple.getMiddle()); dest.writeString(tuple.getRight()); } }
From source file:cherry.goods.telno.TelNoNormalizerImpl.java
@Override public List<String[]> normalize(String telNo) { if (telNo == null) { return null; }//from ww w. j a va 2s . c o m List<Triple<Integer, Integer, Integer>> list = decompose(telNo); if (list == null) { List<String[]> result = new ArrayList<>(1); result.add(new String[] { telNo }); return result; } List<String[]> result = new ArrayList<>(list.size()); for (Triple<Integer, Integer, Integer> triple : list) { if (telNo.length() >= triple.getLeft()) { result.add(split(telNo, triple)); } } return result; }
From source file:blusunrize.immersiveengineering.api.ApiUtils.java
public static Connection raytraceWires(World world, Vec3d start, Vec3d end, @Nullable Connection ignored) { Map<BlockPos, ImmersiveNetHandler.BlockWireInfo> inDim = ImmersiveNetHandler.INSTANCE.blockWireMap .lookup(world.provider.getDimension()); AtomicReference<Connection> ret = new AtomicReference<>(); AtomicDouble minDistSq = new AtomicDouble(Double.POSITIVE_INFINITY); if (inDim != null) { Utils.rayTrace(start, end, world, (pos) -> { if (inDim.containsKey(pos)) { ImmersiveNetHandler.BlockWireInfo info = inDim.get(pos); for (int i = 0; i < 2; i++) { Set<Triple<Connection, Vec3d, Vec3d>> conns = i == 0 ? info.in : info.near; for (Triple<Connection, Vec3d, Vec3d> conn : conns) { Connection c = conn.getLeft(); if (ignored == null || !c.hasSameConnectors(ignored)) { Vec3d startRelative = start.add(-pos.getX(), -pos.getY(), -pos.getZ()); Vec3d across = conn.getRight().subtract(conn.getMiddle()); double t = Utils.getCoeffForMinDistance(startRelative, conn.getMiddle(), across); t = MathHelper.clamp(0, t, 1); Vec3d closest = conn.getMiddle().add(t * across.x, t * across.y, t * across.z); double distSq = closest.squareDistanceTo(startRelative); if (distSq < minDistSq.get()) { ret.set(c); minDistSq.set(distSq); }/*from w w w. j a va2 s . co m*/ } } } } }); } return ret.get(); }
From source file:com.nttec.everychan.ui.gallery.GalleryInitResult.java
public int getParcelSize() { int total = 12; for (Triple<AttachmentModel, String, String> tuple : attachments) { total += 40;/*from w w w . ja v a 2 s . c o m*/ AttachmentModel attachment = tuple.getLeft(); String hash = tuple.getMiddle(); String post = tuple.getRight(); if (attachment.thumbnail != null) total += attachment.thumbnail.length() * 2; if (attachment.path != null) total += attachment.path.length() * 2; if (attachment.originalName != null) total += attachment.originalName.length() * 2; if (hash != null) total += hash.length() * 2; if (post != null) total += post.length() * 2; } return total; }