Class ReverseOrdering<T>

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator<T>

    final class ReverseOrdering<T>
    extends Ordering<T>
    implements java.io.Serializable
    An ordering that uses the reverse of a given order.
    • Constructor Detail

      • ReverseOrdering

        ReverseOrdering​(Ordering<? super T> forwardOrder)
    • Method Detail

      • compare

        public int compare​(T a,
                           T b)
        Specified by:
        compare in interface java.util.Comparator<T>
        Specified by:
        compare in class Ordering<T>
      • reverse

        public <S extends TOrdering<S> reverse()
        Description copied from class: Ordering
        Returns the reverse of this ordering; the Ordering equivalent to Collections.reverseOrder(Comparator).

        Java 8 users: Use thisComparator.reversed() instead.

        Overrides:
        reverse in class Ordering<T>
      • min

        public <E extends T> E min​(E a,
                                   E b)
        Description copied from class: Ordering
        Returns the lesser of the two values according to this ordering. If the values compare as 0, the first is returned.

        Implementation note: this method is invoked by the default implementations of the other min overloads, so overriding it will affect their behavior.

        Note: Consider using Comparators.min(a, b, thisComparator) instead. If thisComparator is Ordering.natural(), then use Comparators.min(a, b).

        Overrides:
        min in class Ordering<T>
        Parameters:
        a - value to compare, returned if less than or equal to b.
        b - value to compare.
      • min

        public <E extends T> E min​(E a,
                                   E b,
                                   E c,
                                   E... rest)
        Description copied from class: Ordering
        Returns the least of the specified values according to this ordering. If there are multiple least values, the first of those is returned.

        Java 8 users: Use Collections.min(Arrays.asList(a, b, c...), thisComparator) instead (but note that it does not guarantee which tied minimum element is returned).

        Overrides:
        min in class Ordering<T>
        Parameters:
        a - value to compare, returned if less than or equal to the rest.
        b - value to compare
        c - value to compare
        rest - values to compare
      • min

        public <E extends T> E min​(java.util.Iterator<E> iterator)
        Description copied from class: Ordering
        Returns the least of the specified values according to this ordering. If there are multiple least values, the first of those is returned. The iterator will be left exhausted: its hasNext() method will return false.

        Java 8 users: Use Streams.stream(iterator).min(thisComparator).get() instead (but note that it does not guarantee which tied minimum element is returned).

        Overrides:
        min in class Ordering<T>
        Parameters:
        iterator - the iterator whose minimum element is to be determined
      • min

        public <E extends T> E min​(java.lang.Iterable<E> iterable)
        Description copied from class: Ordering
        Returns the least of the specified values according to this ordering. If there are multiple least values, the first of those is returned.

        Java 8 users: If iterable is a Collection, use Collections.min(collection, thisComparator) instead. Otherwise, use Streams.stream(iterable).min(thisComparator).get() instead. Note that these alternatives do not guarantee which tied minimum element is returned)

        Overrides:
        min in class Ordering<T>
        Parameters:
        iterable - the iterable whose minimum element is to be determined
      • max

        public <E extends T> E max​(E a,
                                   E b)
        Description copied from class: Ordering
        Returns the greater of the two values according to this ordering. If the values compare as 0, the first is returned.

        Implementation note: this method is invoked by the default implementations of the other max overloads, so overriding it will affect their behavior.

        Note: Consider using Comparators.max(a, b, thisComparator) instead. If thisComparator is Ordering.natural(), then use Comparators.max(a, b).

        Overrides:
        max in class Ordering<T>
        Parameters:
        a - value to compare, returned if greater than or equal to b.
        b - value to compare.
      • max

        public <E extends T> E max​(E a,
                                   E b,
                                   E c,
                                   E... rest)
        Description copied from class: Ordering
        Returns the greatest of the specified values according to this ordering. If there are multiple greatest values, the first of those is returned.

        Java 8 users: Use Collections.max(Arrays.asList(a, b, c...), thisComparator) instead (but note that it does not guarantee which tied maximum element is returned).

        Overrides:
        max in class Ordering<T>
        Parameters:
        a - value to compare, returned if greater than or equal to the rest.
        b - value to compare
        c - value to compare
        rest - values to compare
      • max

        public <E extends T> E max​(java.util.Iterator<E> iterator)
        Description copied from class: Ordering
        Returns the greatest of the specified values according to this ordering. If there are multiple greatest values, the first of those is returned. The iterator will be left exhausted: its hasNext() method will return false.

        Java 8 users: Use Streams.stream(iterator).max(thisComparator).get() instead (but note that it does not guarantee which tied maximum element is returned).

        Overrides:
        max in class Ordering<T>
        Parameters:
        iterator - the iterator whose maximum element is to be determined
      • max

        public <E extends T> E max​(java.lang.Iterable<E> iterable)
        Description copied from class: Ordering
        Returns the greatest of the specified values according to this ordering. If there are multiple greatest values, the first of those is returned.

        Java 8 users: If iterable is a Collection, use Collections.max(collection, thisComparator) instead. Otherwise, use Streams.stream(iterable).max(thisComparator).get() instead. Note that these alternatives do not guarantee which tied maximum element is returned)

        Overrides:
        max in class Ordering<T>
        Parameters:
        iterable - the iterable whose maximum element is to be determined
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object object)
        Specified by:
        equals in interface java.util.Comparator<T>
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object