public final class ComparatorCompat<T> extends Object implements Comparator<T>
Comparator interface.| Constructor and Description |
|---|
ComparatorCompat(Comparator<? super T> comparator) |
| Modifier and Type | Method and Description |
|---|---|
static <T> ComparatorCompat<T> |
chain(Comparator<T> comparator)
Allows to build comparators with method chaining.
|
Comparator<T> |
comparator()
Deprecated.
As of release 1.1.7, it is unnecessary to call this method.
|
int |
compare(T o1,
T o2) |
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> ComparatorCompat<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> ComparatorCompat<T> |
comparingDouble(ToDoubleFunction<? super T> keyExtractor)
Returns a comparator that uses a function that extracts
a
double sort key to be compared. |
static <T> ComparatorCompat<T> |
comparingInt(ToIntFunction<? super T> keyExtractor)
Returns a comparator that uses a function that extracts
an
int sort key to be compared. |
static <T> ComparatorCompat<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> ComparatorCompat<T> |
nullsFirst()
Returns a comparator that considers
null to be
less than non-null and all non-null values to be equal. |
static <T> ComparatorCompat<T> |
nullsFirst(Comparator<? super T> comparator)
Returns a comparator that considers
null to be less than non-null. |
static <T> ComparatorCompat<T> |
nullsLast()
Returns a comparator that considers
null to be
greater than non-null and all non-null values to be equal. |
static <T> ComparatorCompat<T> |
nullsLast(Comparator<? super T> comparator)
Returns a comparator that considers
null to be greater than non-null. |
ComparatorCompat<T> |
reversed()
Reverses the order of comparator.
|
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.
|
ComparatorCompat<T> |
thenComparing(Comparator<? super T> other)
Adds the given comparator to the chain.
|
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. |
<U extends Comparable<? super U>> |
thenComparing(Function<? super T,? extends U> keyExtractor)
Adds the comparator, that uses a function for extract
a
Comparable sort key, to the chain. |
<U> ComparatorCompat<T> |
thenComparing(Function<? super T,? extends U> keyExtractor,
Comparator<? super U> keyComparator)
Adds the comparator, that uses a function for extract
a sort key, to the chain.
|
ComparatorCompat<T> |
thenComparingDouble(ToDoubleFunction<? super T> keyExtractor)
Adds the comparator, that uses a function for extract
a
double sort key, to the chain. |
ComparatorCompat<T> |
thenComparingInt(ToIntFunction<? super T> keyExtractor)
Adds the comparator, that uses a function for extract
an
int sort key, to the chain. |
ComparatorCompat<T> |
thenComparingLong(ToLongFunction<? super T> keyExtractor)
Adds the comparator, that uses a function for extract
a
long sort key, to the chain. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, equals, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic ComparatorCompat(Comparator<? super T> comparator)
public static <T extends Comparable<? super T>> ComparatorCompat<T> naturalOrder()
naturalOrder in interface Comparator<T>T - the type of the objects compared by the comparatorpublic static <T extends Comparable<? super T>> ComparatorCompat<T> reverseOrder()
reverseOrder in interface Comparator<T>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> ComparatorCompat<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>> ComparatorCompat<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> ComparatorCompat<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> ComparatorCompat<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> ComparatorCompat<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> ComparatorCompat<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> ComparatorCompat<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.nullsFirst in interface Comparator<T>T - the type of the objects compared by the comparatorcomparator - a comparator for comparing non-null valuespublic static <T> ComparatorCompat<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> ComparatorCompat<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.nullsLast in interface Comparator<T>T - the type of the objects compared by the comparatorcomparator - a comparator for comparing non-null valuespublic static <T> ComparatorCompat<T> chain(Comparator<T> comparator)
T - the type of the objects compared by the comparatorcomparator - the comparator to be chainedComparatorCompat instancepublic ComparatorCompat<T> reversed()
reversed in interface Comparator<T>ComparatorCompat instancereverseOrder()public ComparatorCompat<T> thenComparing(Comparator<? super T> other)
thenComparing in interface Comparator<T>other - the other comparator to be used when chained
comparator compares two objects that are equalComparatorCompat instancepublic <U> ComparatorCompat<T> thenComparing(Function<? super T,? extends U> keyExtractor, Comparator<? super U> keyComparator)
U - the type of the sort keykeyExtractor - the function that extracts the sort keykeyComparator - the comparator used to compare the sort keyComparatorCompat instancepublic <U extends Comparable<? super U>> ComparatorCompat<T> thenComparing(Function<? super T,? extends U> keyExtractor)
Comparable sort key, to the chain.U - the type of the sort keykeyExtractor - the function that extracts the sort keyComparatorCompat instancepublic ComparatorCompat<T> thenComparingInt(ToIntFunction<? super T> keyExtractor)
int sort key, to the chain.keyExtractor - the function that extracts the sort keyComparatorCompat instancepublic ComparatorCompat<T> thenComparingLong(ToLongFunction<? super T> keyExtractor)
long sort key, to the chain.keyExtractor - the function that extracts the sort keyComparatorCompat instancepublic ComparatorCompat<T> thenComparingDouble(ToDoubleFunction<? super T> keyExtractor)
double sort key, to the chain.keyExtractor - the function that extracts the sort keyComparatorCompat instancepublic Comparator<T> comparator()
Comparator.public int compare(T o1, T o2)
compare in interface Comparator<T>Copyright © 2018. All rights reserved.