public final class ComparatorCompat<T>
extends java.lang.Object
implements java.util.Comparator<T>
Comparator interface.| Constructor and Description |
|---|
ComparatorCompat(java.util.Comparator<? super T> comparator) |
| Modifier and Type | Method and Description |
|---|---|
static <T> ComparatorCompat<T> |
chain(java.util.Comparator<T> comparator)
Allows to build comparators with method chaining.
|
java.util.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 java.lang.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,
java.util.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 java.lang.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(java.util.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(java.util.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> java.util.Comparator<T> |
reversed(java.util.Comparator<T> comparator)
Returns a comparator that reverses the order of the specified comparator.
|
static <T extends java.lang.Comparable<? super T>> |
reverseOrder()
Returns a comparator with reverse order.
|
ComparatorCompat<T> |
thenComparing(java.util.Comparator<? super T> other)
Adds the given comparator to the chain.
|
static <T> java.util.Comparator<T> |
thenComparing(java.util.Comparator<? super T> c1,
java.util.Comparator<? super T> c2)
Returns a comparator that uses
c2 comparator
if c1 comparator considers two elements equal. |
<U extends java.lang.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,
java.util.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. |
public ComparatorCompat(@NotNull
java.util.Comparator<? super T> comparator)
@NotNull public static <T extends java.lang.Comparable<? super T>> ComparatorCompat<T> naturalOrder()
naturalOrder in interface java.util.Comparator<T>T - the type of the objects compared by the comparator@NotNull public static <T extends java.lang.Comparable<? super T>> ComparatorCompat<T> reverseOrder()
reverseOrder in interface java.util.Comparator<T>T - the type of the objects compared by the comparatorCollections.reverseOrder()@NotNull
public static <T> java.util.Comparator<T> reversed(@Nullable
java.util.Comparator<T> comparator)
null, this method is equivalent
to reverseOrder().T - the type of the objects compared by the comparatorcomparator - a comparator to be reversedjava.lang.NullPointerException - if comparator is nullCollections.reverseOrder(java.util.Comparator)@NotNull
public static <T> java.util.Comparator<T> thenComparing(@NotNull
java.util.Comparator<? super T> c1,
@NotNull
java.util.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 comparatorjava.lang.NullPointerException - if c1 or c2 is null@NotNull public static <T,U> ComparatorCompat<T> comparing(@NotNull Function<? super T,? extends U> keyExtractor, @NotNull java.util.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 keyjava.lang.NullPointerException - if keyExtractor or keyComparator is null@NotNull public static <T,U extends java.lang.Comparable<? super U>> ComparatorCompat<T> comparing(@NotNull 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 keyjava.lang.NullPointerException - if keyExtractor is null@NotNull public static <T> ComparatorCompat<T> comparingInt(@NotNull 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 keyjava.lang.NullPointerException - if keyExtractor is null@NotNull public static <T> ComparatorCompat<T> comparingLong(@NotNull 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 keyjava.lang.NullPointerException - if keyExtractor is null@NotNull public static <T> ComparatorCompat<T> comparingDouble(@NotNull 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 keyjava.lang.NullPointerException - if keyExtractor is null@NotNull public 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 comparator@NotNull public static <T> ComparatorCompat<T> nullsFirst(@Nullable java.util.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 java.util.Comparator<T>T - the type of the objects compared by the comparatorcomparator - a comparator for comparing non-null values@NotNull public 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 comparator@NotNull public static <T> ComparatorCompat<T> nullsLast(@Nullable java.util.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 java.util.Comparator<T>T - the type of the objects compared by the comparatorcomparator - a comparator for comparing non-null values@NotNull public static <T> ComparatorCompat<T> chain(@NotNull java.util.Comparator<T> comparator)
T - the type of the objects compared by the comparatorcomparator - the comparator to be chainedComparatorCompat instance@NotNull public ComparatorCompat<T> reversed()
reversed in interface java.util.Comparator<T>ComparatorCompat instancereverseOrder()@NotNull public ComparatorCompat<T> thenComparing(@NotNull java.util.Comparator<? super T> other)
thenComparing in interface java.util.Comparator<T>other - the other comparator to be used when chained
comparator compares two objects that are equalComparatorCompat instance@NotNull public <U> ComparatorCompat<T> thenComparing(@NotNull Function<? super T,? extends U> keyExtractor, @NotNull java.util.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 instance@NotNull public <U extends java.lang.Comparable<? super U>> ComparatorCompat<T> thenComparing(@NotNull 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 instance@NotNull public ComparatorCompat<T> thenComparingInt(@NotNull ToIntFunction<? super T> keyExtractor)
int sort key, to the chain.keyExtractor - the function that extracts the sort keyComparatorCompat instance@NotNull public ComparatorCompat<T> thenComparingLong(@NotNull ToLongFunction<? super T> keyExtractor)
long sort key, to the chain.keyExtractor - the function that extracts the sort keyComparatorCompat instance@NotNull public ComparatorCompat<T> thenComparingDouble(@NotNull ToDoubleFunction<? super T> keyExtractor)
double sort key, to the chain.keyExtractor - the function that extracts the sort keyComparatorCompat instance@NotNull public java.util.Comparator<T> comparator()
Comparator.