default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function, Comparator<? super U> comparator){ return foldLeft(BinaryOperator.minBy(new Comparator<T>() { @Override public int compare(T o1, T o2) { return comparator.compare(function.apply(o1),function.apply(o2)); } })); } default Option<T> mode(){
private TileEntity getClosest(Set<TileSignature> tiles, BlockPos pos, boolean remoteCheck, int limit) { return tiles.stream() .filter(ts -> ts.isRemote() == remoteCheck) .map(TileSignature::getTile) .filter(t -> !t.isInvalid()) .filter(t -> t.getPos().distanceSq(pos) <= limit * limit) .reduce(BinaryOperator.minBy(Comparator.comparing(t -> t.getPos().distanceSq(pos), Double::compare))) .orElse(null); }
@Override public Optional<T> min(Comparator<? super T> comparator) { return reduce(BinaryOperator.minBy(comparator)); }
/** * Returns the minimum element of this collection according to the provided * {@code Comparator}. This is a special case of a * <a href="package-summary.html#Reduction">reduction</a>. * * @param comparator a <a href="package-summary.html#NonInterference">non-interfering</a>, <a href="package-summary.html#Statelessness">stateless</a> {@code Comparator} to compare elements of this collection * @return an {@code Option} describing the minimum element of this collection, * or an empty {@code Option} if the collection is empty * @throws NullPointerException if the minimum element is null */ public default Option<E> min(Comparator<? super E> comparator) { return reduce(BinaryOperator.minBy(comparator)); }
default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function, Comparator<? super U> comparator){ return foldLeft(BinaryOperator.minBy(new Comparator<T>() { @Override public int compare(T o1, T o2) { return comparator.compare(function.apply(o1),function.apply(o2)); } })); } default Option<T> mode(){
/** * Returns a {@link TryBinaryOperator} which returns the lesser of two * elements according to the specified {@code Comparator}, if both values are * a {@link Success}. * * @param <T> the type of the input arguments of the comparator * @param comparator a {@code Comparator} for comparing the two values * @return a {@code TryBinaryOperator} which returns the lesser of its * operands, according to the supplied {@code Comparator}, or the * first {@link Failure} if one is encountered. * @throws NullPointerException if the argument is null */ public static <T> TryBinaryOperator<T> minBy(Comparator<? super T> comparator) { return TryBinaryOperator.of(BinaryOperator.minBy(comparator)); }
@Override public BinaryOperator<PhysicalTable> getBetterTableOperator(QueryPlanningConstraint requestConstraint) { List<Comparator<PhysicalTable>> comparators = new ArrayList<>(); if (BardFeatureFlag.PARTIAL_DATA.isOn()) { comparators.add( new PartialTimeComparator(requestConstraint, partialDataHandler)); comparators.add( new VolatileTimeComparator(requestConstraint, partialDataHandler, volatileIntervalsService)); } comparators.add(COMPARE_GRANULARITY); comparators.add(CARDINALITY_COMPARATOR); ChainingComparator<PhysicalTable> tableComparator = new ChainingComparator<>(comparators); return BinaryOperator.minBy(tableComparator); } }