public class Comparators extends Object
Modifier and Type | Method and Description |
---|---|
static <T> Comparator<T> |
chain(Comparator<? super T>... c) |
static <T> Comparator<T> |
chain(Comparator<? super T> c1,
Comparator<? super T> c2)
Returns a new
Comparator which is the result of chaining the
given Comparator s. |
static <T> Comparator<T> |
chain(List<Comparator<? super T>> c)
Returns a new
Comparator which is the result of chaining the
given Comparator s. |
static <C extends Comparable> |
getArrayComparator() |
static Comparator<boolean[]> |
getBooleanArrayComparator() |
static <C extends Comparable> |
getListComparator() |
static 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 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 Comparable<? super T>> |
nullSafeNaturalComparator() |
static <T> Comparator<T> |
reverse(Comparator<? super T> c)
Returns a new
Comparator which is the reverse of the
given Comparator . |
public static <T> Comparator<T> chain(Comparator<? super T> c1, 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> Comparator<T> chain(List<Comparator<? super T>> c)
Comparator
which is the result of chaining the
given Comparator
s. Facilitates sorting on multiple keys.@SafeVarargs public static <T> Comparator<T> chain(Comparator<? super T>... c)
public static <T> Comparator<T> reverse(Comparator<? super T> c)
Comparator
which is the reverse of the
given Comparator
.public static <T extends Comparable<? super T>> Comparator<T> nullSafeNaturalComparator()
public static <T extends Comparable<? super T>> int nullSafeCompare(T one, T two)
public static <C extends Comparable> Comparator<List<C>> getListComparator()
public static Comparator getStringRepresentationComparator()
Comparator
that compares objects by comparing their
String
representations, as determined by invoking
toString()
on the objects in question.public static Comparator<boolean[]> getBooleanArrayComparator()
public static <C extends Comparable> Comparator<C[]> getArrayComparator()