@Override public int compare(T a, T b) { return forwardOrder.compare(b, a); }
@Override public int compare(@Nullable T left, @Nullable T right) { if (left == right) { return 0; } if (left == null) { return RIGHT_IS_GREATER; } if (right == null) { return LEFT_IS_GREATER; } return ordering.compare(left, right); }
@Override public int compare(@Nullable T left, @Nullable T right) { if (left == right) { return 0; } if (left == null) { return LEFT_IS_GREATER; } if (right == null) { return RIGHT_IS_GREATER; } return ordering.compare(left, right); }
/** * Returns {@code true} if each element in {@code iterable} after the first is greater than or * equal to the element that preceded it, according to this ordering. Note that this is always * true when the iterable has fewer than two elements. * * <p><b>Java 8 users:</b> Use the equivalent {@link Comparators#isInOrder(Iterable, Comparator)} * instead, since the rest of {@code Ordering} is mostly obsolete (as explained in the class * documentation). */ public boolean isOrdered(Iterable<? extends T> iterable) { Iterator<? extends T> it = iterable.iterator(); if (it.hasNext()) { T prev = it.next(); while (it.hasNext()) { T next = it.next(); if (compare(prev, next) > 0) { return false; } prev = next; } } return true; }
/** * Returns {@code true} if each element in {@code iterable} after the first is <i>strictly</i> * greater than the element that preceded it, according to this ordering. Note that this is always * true when the iterable has fewer than two elements. * * <p><b>Java 8 users:</b> Use the equivalent {@link Comparators#isInStrictOrder(Iterable, * Comparator)} instead, since the rest of {@code Ordering} is mostly obsolete (as explained in * the class documentation). */ public boolean isStrictlyOrdered(Iterable<? extends T> iterable) { Iterator<? extends T> it = iterable.iterator(); if (it.hasNext()) { T prev = it.next(); while (it.hasNext()) { T next = it.next(); if (compare(prev, next) >= 0) { return false; } prev = next; } } return true; }
/** * Returns the lesser of the two values according to this ordering. If the values compare as 0, * the first is returned. * * <p><b>Implementation note:</b> this method is invoked by the default implementations of the * other {@code min} overloads, so overriding it will affect their behavior. * * <p><b>Java 8 users:</b> Use {@code Collections.min(Arrays.asList(a, b), thisComparator)} * instead (but note that it does not guarantee which tied minimum element is returned). * * @param a value to compare, returned if less than or equal to b. * @param b value to compare. * @throws ClassCastException if the parameters are not <i>mutually comparable</i> under this * ordering. */ @CanIgnoreReturnValue // TODO(kak): Consider removing this public <E extends T> E min(@Nullable E a, @Nullable E b) { return (compare(a, b) <= 0) ? a : b; }
/** * Returns the greater of the two values according to this ordering. If the values compare as 0, * the first is returned. * * <p><b>Implementation note:</b> this method is invoked by the default implementations of the * other {@code max} overloads, so overriding it will affect their behavior. * * <p><b>Java 8 users:</b> Use {@code Collections.max(Arrays.asList(a, b), thisComparator)} * instead (but note that it does not guarantee which tied maximum element is returned). * * @param a value to compare, returned if greater than or equal to b. * @param b value to compare. * @throws ClassCastException if the parameters are not <i>mutually comparable</i> under this * ordering. */ @CanIgnoreReturnValue // TODO(kak): Consider removing this public <E extends T> E max(@Nullable E a, @Nullable E b) { return (compare(a, b) >= 0) ? a : b; }
@Override public int compare(F left, F right) { return ordering.compare(function.apply(left), function.apply(right)); }
@Override public int compare(CatalogMetadata left, CatalogMetadata right) { return Ordering.natural().compare(left.getCatalogName(), right.getCatalogName()); } };