public class Comparators extends Object
| Constructor and Description |
|---|
Comparators() |
| 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 Comparators. |
static <T> Comparator<T> |
chain(List<Comparator<? super T>> c)
Returns a new
Comparator which is the result of chaining the
given Comparators. |
static <T extends Comparable<? super T>> |
nullSafeComparator(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> 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 Comparators. 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 Comparators. Facilitates sorting on multiple keys.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>> int nullSafeComparator(T one, T two)