public final class ComparatorCompat extends Object
Comparator interface.| Modifier and Type | Class and Description |
|---|---|
static class |
ComparatorCompat.Chain<T>
Class that helps to build new comparators.
|
| Modifier and Type | Method and Description |
|---|---|
static <T> ComparatorCompat.Chain<T> |
chain(Comparator<T> comparator)
Returns a
ComparatorCompat.Chain class instance for build comparators. |
static <T,U extends Comparable<? super U>> |
comparing(Function<? super T,? extends U> keyExtractor)
Returns a comparator that uses a function that extracts
a
Comparable sort key to be compared. |
static <T,U> Comparator<T> |
comparing(Function<? super T,? extends U> keyExtractor,
Comparator<? super U> keyComparator)
Returns a comparator that uses a function that extracts a sort key
to be compared with the specified comparator.
|
static <T> Comparator<T> |
comparingDouble(ToDoubleFunction<? super T> keyExtractor)
Returns a comparator that uses a function that extracts
a
double sort key to be compared. |
static <T> Comparator<T> |
comparingInt(ToIntFunction<? super T> keyExtractor)
Returns a comparator that uses a function that extracts
an
int sort key to be compared. |
static <T> Comparator<T> |
comparingLong(ToLongFunction<? super T> keyExtractor)
Returns a comparator that uses a function that extracts
a
long sort key to be compared. |
static <T extends Comparable<? super T>> |
naturalOrder()
Returns a comparator with natural order.
|
static <T> Comparator<T> |
nullsFirst()
Returns a comparator that considers
null to be
less than non-null and all non-null values to be equal. |
static <T> Comparator<T> |
nullsFirst(Comparator<? super T> comparator)
Returns a comparator that considers
null to be less than non-null. |
static <T> Comparator<T> |
nullsLast()
Returns a comparator that considers
null to be
greater than non-null and all non-null values to be equal. |
static <T> Comparator<T> |
nullsLast(Comparator<? super T> comparator)
Returns a comparator that considers
null to be greater than non-null. |
static <T> Comparator<T> |
reversed(Comparator<T> comparator)
Returns a comparator that reverses the order of the specified comparator.
|
static <T extends Comparable<? super T>> |
reverseOrder()
Returns a comparator with reverse order.
|
static <T> Comparator<T> |
thenComparing(Comparator<? super T> c1,
Comparator<? super T> c2)
Returns a comparator that uses
c2 comparator
if c1 comparator considers two elements equal. |
public static <T extends Comparable<? super T>> Comparator<T> naturalOrder()
T - the type of the objects compared by the comparatorpublic static <T extends Comparable<? super T>> Comparator<T> reverseOrder()
T - the type of the objects compared by the comparatorCollections.reverseOrder()public static <T> Comparator<T> reversed(Comparator<T> comparator)
null, this method is equivalent
to reverseOrder().T - the type of the objects compared by the comparatorcomparator - a comparator to be reversedNullPointerException - if comparator is nullCollections.reverseOrder(java.util.Comparator)public static <T> Comparator<T> thenComparing(Comparator<? super T> c1, Comparator<? super T> c2)
c2 comparator
if c1 comparator considers two elements equal.T - the type of the objects compared by the comparatorsc1 - a first comparatorc2 - a second comparatorNullPointerException - if c1 or c2 is nullpublic static <T,U> Comparator<T> comparing(Function<? super T,? extends U> keyExtractor, Comparator<? super U> keyComparator)
T - the type of the objects compared by the comparatorU - the type of the sort keykeyExtractor - the function that extracts the sort keykeyComparator - the comparator used to compare the sort keyNullPointerException - if keyExtractor or keyComparator is nullpublic static <T,U extends Comparable<? super U>> Comparator<T> comparing(Function<? super T,? extends U> keyExtractor)
Comparable sort key to be compared.T - the type of the objects compared by the comparatorU - the type of the sort keykeyExtractor - the function that extracts the sort keyNullPointerException - if keyExtractor is nullpublic static <T> Comparator<T> comparingInt(ToIntFunction<? super T> keyExtractor)
int sort key to be compared.T - the type of the objects compared by the comparatorkeyExtractor - the function that extracts the sort keyNullPointerException - if keyExtractor is nullpublic static <T> Comparator<T> comparingLong(ToLongFunction<? super T> keyExtractor)
long sort key to be compared.T - the type of the objects compared by the comparatorkeyExtractor - the function that extracts the sort keyNullPointerException - if keyExtractor is nullpublic static <T> Comparator<T> comparingDouble(ToDoubleFunction<? super T> keyExtractor)
double sort key to be compared.T - the type of the objects compared by the comparatorkeyExtractor - the function that extracts the sort keyNullPointerException - if keyExtractor is nullpublic static <T> Comparator<T> nullsFirst()
null to be
less than non-null and all non-null values to be equal.T - the type of the objects compared by the comparatorpublic static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator)
null to be less than non-null.
If the specified comparator is null, then the returned
comparator considers all non-null values to be equal.T - the type of the objects compared by the comparatorcomparator - a comparator for comparing non-null valuespublic static <T> Comparator<T> nullsLast()
null to be
greater than non-null and all non-null values to be equal.T - the type of the objects compared by the comparatorpublic static <T> Comparator<T> nullsLast(Comparator<? super T> comparator)
null to be greater than non-null.
If the specified comparator is null, then the returned
comparator considers all non-null values to be equal.T - the type of the objects compared by the comparatorcomparator - a comparator for comparing non-null valuespublic static <T> ComparatorCompat.Chain<T> chain(Comparator<T> comparator)
ComparatorCompat.Chain class instance for build comparators.T - the type of the objects compared by the comparatorcomparator - the comparator to be chainedChain instanceCopyright © 2017. All rights reserved.