Comparator instances. For many other helpful
comparator utilities, see either Comparator itself (for Java 8 or later), or com.google.common.collect.Ordering (otherwise).
OrderingIn light of the significant enhancements to Comparator in Java 8, the overwhelming
majority of usages of Ordering can be written using only built-in JDK APIs. This class is
intended to "fill the gap" and provide those features of Ordering not already provided by
the JDK.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static <T> Comparator | emptiesFirst(Comparator<? super T> valueComparator)
Returns a comparator of |
| public static <T> Comparator | emptiesLast(Comparator<? super T> valueComparator)
Returns a comparator of |
| public static <T extends @Nullable Object> Collector | greatest(int k, Comparator<? super T> comparator)
Returns a |
| public static <T extends @Nullable Object> boolean | isInOrder(Iterable<? extends T> iterable, Comparator<T> comparator)
Returns |
| public static <T extends @Nullable Object> boolean | isInStrictOrder(Iterable<? extends T> iterable, Comparator<T> comparator)
Returns |
| public static <T extends @Nullable Object> Collector | least(int k, Comparator<? super T> comparator)
Returns a |
| public static <T extends @Nullable Object, S extends T> Comparator | lexicographical(Comparator<T> comparator)
Returns a new comparator which sorts iterables by comparing corresponding elements pairwise until a nonzero result is found; imposes "dictionary order." If the end of one iterable is reached, but not the other, the shorter iterable is considered to be less than the longer one. |
| public static <T extends Comparable | max(T
first value to compare, returned if greater than or equal to b. a, T second value to compare. b)Returns the maximum of the two values. |
| public static <T extends @Nullable Object> T | max(T
first value to compare, returned if greater than or equal to b. a, T second value to compare. b, Comparator<T> comparator)Returns the maximum of the two values, according to the given comparator. |
| public static <T extends Comparable | min(T
first value to compare, returned if less than or equal to b. a, T second value to compare. b)Returns the minimum of the two values. |
| public static <T extends @Nullable Object> T | min(T
first value to compare, returned if less than or equal to b a, T second value to compare. b, Comparator<T> comparator)Returns the minimum of the two values, according to the given comparator. |
| Comparators | back to summary |
|---|---|
| private Comparators() | |
| emptiesFirst | back to summary |
|---|---|
| public static <T> Comparator Returns a comparator of
| |
| emptiesLast | back to summary |
|---|---|
| public static <T> Comparator Returns a comparator of
| |
| greatest | back to summary |
|---|---|
| public static <T extends @Nullable Object> Collector Returns a For example:
This
| |
| isInOrder | back to summary |
|---|---|
| public static <T extends @Nullable Object> boolean isInOrder(Iterable<? extends T> iterable, Comparator<T> comparator) Returns | |
| isInStrictOrder | back to summary |
|---|---|
| public static <T extends @Nullable Object> boolean isInStrictOrder(Iterable<? extends T> iterable, Comparator<T> comparator) Returns | |
| least | back to summary |
|---|---|
| public static <T extends @Nullable Object> Collector Returns a For example:
This
| |
| lexicographical | back to summary |
|---|---|
| public static <T extends @Nullable Object, S extends T> Comparator Returns a new comparator which sorts iterables by comparing corresponding elements pairwise
until a nonzero result is found; imposes "dictionary order." If the end of one iterable is
reached, but not the other, the shorter iterable is considered to be less than the longer one.
For example, a lexicographical natural ordering over integers considers Note that | |
| max | back to summary |
|---|---|
| public static <T extends Comparable Returns the maximum of the two values. If the values compare as 0, the first is returned. The recommended solution for finding the
| |
| max | back to summary |
|---|---|
| public static <T extends @Nullable Object> T max(T a, T b, Comparator<T> comparator) Returns the maximum of the two values, according to the given comparator. If the values compare as equal, the first is returned. The recommended solution for finding the
| |
| min | back to summary |
|---|---|
| public static <T extends Comparable Returns the minimum of the two values. If the values compare as 0, the first is returned. The recommended solution for finding the
| |
| min | back to summary |
|---|---|
| public static <T extends @Nullable Object> T min(T a, T b, Comparator<T> comparator) Returns the minimum of the two values, according to the given comparator. If the values compare as equal, the first is returned. The recommended solution for finding the
| |