public class Comparators
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <T> java.util.Comparator<T> |
chain(java.util.Comparator<? super T> c1,
java.util.Comparator<? super T> c2)
Returns a new
Comparator which is the result of chaining the
given Comparator s. |
static <T> java.util.Comparator<T> |
chain(java.util.Comparator<T>... c) |
static <T> java.util.Comparator<T> |
chain(java.util.List<java.util.Comparator<? super T>> c)
Returns a new
Comparator which is the result of chaining the
given Comparator s. |
static <C extends java.lang.Comparable> |
getArrayComparator() |
static java.util.Comparator<boolean[]> |
getBooleanArrayComparator() |
static <C extends java.lang.Comparable> |
getListComparator() |
static java.util.Comparator |
getStringRepresentationComparator()
A
Comparator that compares objects by comparing their
String representations, as determined by invoking
toString() on the objects in question. |
static <T extends java.lang.Comparable<? super T>> |
nullSafeCompare(T one,
T two)
Returns a consistent ordering over two elements even if one of them is null
(as long as compareTo() is stable, of course).
|
static <T extends java.lang.Comparable<? super T>> |
nullSafeNaturalComparator() |
static <T> java.util.Comparator<T> |
reverse(java.util.Comparator<? super T> c)
Returns a new
Comparator which is the reverse of the
given Comparator . |
public static <T> java.util.Comparator<T> chain(java.util.Comparator<? super T> c1, java.util.Comparator<? super T> c2)
Comparator
which is the result of chaining the
given Comparator
s. If the first Comparator
considers two objects unequal, its result is returned; otherwise, the
result of the second Comparator
is returned. Facilitates
sorting on primary and secondary keys.public static <T> java.util.Comparator<T> chain(java.util.List<java.util.Comparator<? super T>> c)
Comparator
which is the result of chaining the
given Comparator
s. Facilitates sorting on multiple keys.@SafeVarargs public static <T> java.util.Comparator<T> chain(java.util.Comparator<T>... c)
public static <T> java.util.Comparator<T> reverse(java.util.Comparator<? super T> c)
Comparator
which is the reverse of the
given Comparator
.public static <T extends java.lang.Comparable<? super T>> java.util.Comparator<T> nullSafeNaturalComparator()
public static <T extends java.lang.Comparable<? super T>> int nullSafeCompare(T one, T two)
public static <C extends java.lang.Comparable> java.util.Comparator<java.util.List<C>> getListComparator()
public static java.util.Comparator getStringRepresentationComparator()
Comparator
that compares objects by comparing their
String
representations, as determined by invoking
toString()
on the objects in question.public static java.util.Comparator<boolean[]> getBooleanArrayComparator()
public static <C extends java.lang.Comparable> java.util.Comparator<C[]> getArrayComparator()