List of usage examples for java.util Comparator compare
int compare(T o1, T o2);
From source file:at.gridtec.lambda4j.operator.binary.ThrowableByteBinaryOperator.java
/** * Returns a {@link ThrowableByteBinaryOperator} which returns the greater of two elements according to the * specified {@code Comparator}.//from w w w . ja v a 2 s . co m * * @param <X> The type of the throwable to be thrown by this operator * @param comparator A {@code Comparator} for comparing the two values * @return A {@code ThrowableByteBinaryOperator} which returns the greater of its operands, according to the * supplied {@code Comparator}. * @throws NullPointerException If given argument is {@code null} * @see BinaryOperator#maxBy(Comparator) */ @Nonnull static <X extends Throwable> ThrowableByteBinaryOperator<X> maxBy(@Nonnull final Comparator<Byte> comparator) { Objects.requireNonNull(comparator); return (value1, value2) -> comparator.compare(value1, value2) >= 0 ? value1 : value2; }
From source file:at.gridtec.lambda4j.operator.binary.ThrowableFloatBinaryOperator.java
/** * Returns a {@link ThrowableFloatBinaryOperator} which returns the lesser of two elements according to the * specified {@code Comparator}./*from ww w . j a v a 2s. c om*/ * * @param <X> The type of the throwable to be thrown by this operator * @param comparator A {@code Comparator} for comparing the two values * @return A {@code ThrowableFloatBinaryOperator} which returns the lesser of its operands, according to the * supplied {@code Comparator}. * @throws NullPointerException If given argument is {@code null} * @see BinaryOperator#minBy(Comparator) */ @Nonnull static <X extends Throwable> ThrowableFloatBinaryOperator<X> minBy( @Nonnull final Comparator<Float> comparator) { Objects.requireNonNull(comparator); return (value1, value2) -> comparator.compare(value1, value2) <= 0 ? value1 : value2; }
From source file:at.gridtec.lambda4j.operator.binary.ThrowableFloatBinaryOperator.java
/** * Returns a {@link ThrowableFloatBinaryOperator} which returns the greater of two elements according to the * specified {@code Comparator}.//from w w w . j a v a 2 s . com * * @param <X> The type of the throwable to be thrown by this operator * @param comparator A {@code Comparator} for comparing the two values * @return A {@code ThrowableFloatBinaryOperator} which returns the greater of its operands, according to the * supplied {@code Comparator}. * @throws NullPointerException If given argument is {@code null} * @see BinaryOperator#maxBy(Comparator) */ @Nonnull static <X extends Throwable> ThrowableFloatBinaryOperator<X> maxBy( @Nonnull final Comparator<Float> comparator) { Objects.requireNonNull(comparator); return (value1, value2) -> comparator.compare(value1, value2) >= 0 ? value1 : value2; }
From source file:at.gridtec.lambda4j.operator.binary.ThrowableShortBinaryOperator.java
/** * Returns a {@link ThrowableShortBinaryOperator} which returns the lesser of two elements according to the * specified {@code Comparator}.//from w w w.ja va2s .c o m * * @param <X> The type of the throwable to be thrown by this operator * @param comparator A {@code Comparator} for comparing the two values * @return A {@code ThrowableShortBinaryOperator} which returns the lesser of its operands, according to the * supplied {@code Comparator}. * @throws NullPointerException If given argument is {@code null} * @see BinaryOperator#minBy(Comparator) */ @Nonnull static <X extends Throwable> ThrowableShortBinaryOperator<X> minBy( @Nonnull final Comparator<Short> comparator) { Objects.requireNonNull(comparator); return (value1, value2) -> comparator.compare(value1, value2) <= 0 ? value1 : value2; }
From source file:at.gridtec.lambda4j.operator.binary.ThrowableShortBinaryOperator.java
/** * Returns a {@link ThrowableShortBinaryOperator} which returns the greater of two elements according to the * specified {@code Comparator}.// ww w . j av a2 s. c o m * * @param <X> The type of the throwable to be thrown by this operator * @param comparator A {@code Comparator} for comparing the two values * @return A {@code ThrowableShortBinaryOperator} which returns the greater of its operands, according to the * supplied {@code Comparator}. * @throws NullPointerException If given argument is {@code null} * @see BinaryOperator#maxBy(Comparator) */ @Nonnull static <X extends Throwable> ThrowableShortBinaryOperator<X> maxBy( @Nonnull final Comparator<Short> comparator) { Objects.requireNonNull(comparator); return (value1, value2) -> comparator.compare(value1, value2) >= 0 ? value1 : value2; }
From source file:at.gridtec.lambda4j.operator.binary.ThrowableCharBinaryOperator.java
/** * Returns a {@link ThrowableCharBinaryOperator} which returns the lesser of two elements according to the specified * {@code Comparator}.// w ww .j a va 2 s .c om * * @param <X> The type of the throwable to be thrown by this operator * @param comparator A {@code Comparator} for comparing the two values * @return A {@code ThrowableCharBinaryOperator} which returns the lesser of its operands, according to the supplied * {@code Comparator}. * @throws NullPointerException If given argument is {@code null} * @see BinaryOperator#minBy(Comparator) */ @Nonnull static <X extends Throwable> ThrowableCharBinaryOperator<X> minBy( @Nonnull final Comparator<Character> comparator) { Objects.requireNonNull(comparator); return (value1, value2) -> comparator.compare(value1, value2) <= 0 ? value1 : value2; }
From source file:at.gridtec.lambda4j.operator.binary.ThrowableCharBinaryOperator.java
/** * Returns a {@link ThrowableCharBinaryOperator} which returns the greater of two elements according to the * specified {@code Comparator}.//from w w w . j av a 2s . c om * * @param <X> The type of the throwable to be thrown by this operator * @param comparator A {@code Comparator} for comparing the two values * @return A {@code ThrowableCharBinaryOperator} which returns the greater of its operands, according to the * supplied {@code Comparator}. * @throws NullPointerException If given argument is {@code null} * @see BinaryOperator#maxBy(Comparator) */ @Nonnull static <X extends Throwable> ThrowableCharBinaryOperator<X> maxBy( @Nonnull final Comparator<Character> comparator) { Objects.requireNonNull(comparator); return (value1, value2) -> comparator.compare(value1, value2) >= 0 ? value1 : value2; }
From source file:org.jcurl.math.CurveCombined.java
/** * Search only part of a list.//from w ww. ja va 2s.co m * * @param a * @param fromIndex * @param toIndex * @param key * @param comp * * @return found index */ static <E> int binarySearch(final List<E> a, final int fromIndex, final int toIndex, final E key, final Comparator<? super E> comp) { if (fromIndex > toIndex) throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); if (fromIndex < 0) throw new ArrayIndexOutOfBoundsException(fromIndex); if (toIndex > a.size()) throw new ArrayIndexOutOfBoundsException(toIndex); int low = fromIndex; int high = toIndex - 1; while (low <= high) { final int mid = low + high >>> 1; final E midVal = a.get(mid); final int cmp = comp.compare(midVal, key); if (cmp < 0) low = mid + 1; else if (cmp > 0) high = mid - 1; else return mid; // done } return -(low + 1); // no such key }
From source file:org.apache.jackrabbit.oak.plugins.document.util.Utils.java
/** * Returns the revision which is considered more recent or {@code null} if * both revisions are {@code null}. The implementation will return the first * revision if both are considered equal. The comparison is done using the * provided comparator./*from www . ja v a 2s .c om*/ * * @param a the first revision (or {@code null}). * @param b the second revision (or {@code null}). * @param c the comparator. * @return the revision considered more recent. */ @CheckForNull public static Revision max(@Nullable Revision a, @Nullable Revision b, @Nonnull Comparator<Revision> c) { if (a == null) { return b; } else if (b == null) { return a; } return c.compare(a, b) >= 0 ? a : b; }
From source file:org.apache.jackrabbit.oak.plugins.document.util.Utils.java
/** * Returns the revision which is considered older or {@code null} if * both revisions are {@code null}. The implementation will return the first * revision if both are considered equal. The comparison is done using the * provided comparator.// ww w. j ava 2 s . com * * @param a the first revision (or {@code null}). * @param b the second revision (or {@code null}). * @param c the comparator. * @return the revision considered more recent. */ @CheckForNull public static Revision min(@Nullable Revision a, @Nullable Revision b, @Nonnull Comparator<Revision> c) { if (a == null) { return b; } else if (b == null) { return a; } return c.compare(a, b) <= 0 ? a : b; }