@FunctionalInterface public interface SerializableComparator<T> extends Comparator<T>, Serializable
Comparator.| Modifier and Type | Method and Description |
|---|---|
static <T,U extends Comparable<? super U>> |
comparing(SerializableFunction<? super T,? extends U> keyExtractor)
Accepts a function that extracts a
Comparable sort key from a type T, and returns a Comparator<T> that compares by that sort key. |
static <T,U> SerializableComparator<T> |
comparing(SerializableFunction<? super T,? extends U> keyExtractor,
SerializableComparator<? super U> keyComparator)
Accepts a function that extracts a sort key from a type
T, and
returns a SerializableComparator<T> that compares by that sort
key using the specified SerializableComparator. |
static <T> SerializableComparator<T> |
comparingDouble(SerializableToDoubleFunction<? super T> keyExtractor)
Accepts a function that extracts a
double sort key from a type
T, and returns a SerializableComparator<T> that compares
by that sort key. |
static <T> SerializableComparator<T> |
comparingInt(SerializableToIntFunction<? super T> keyExtractor)
Accepts a function that extracts an
int sort key from a type
T, and returns a Comparator<T> that compares by that
sort key. |
static <T> SerializableComparator<T> |
comparingLong(SerializableToLongFunction<? super T> keyExtractor)
Accepts a function that extracts a
long sort key from a type
T, and returns a Comparator<T> that compares by that
sort key. |
static <T extends Comparable<? super T>> |
naturalOrder()
Returns a comparator that compares
Comparable objects in natural
order. |
static <T> SerializableComparator<T> |
nullsFirst(SerializableComparator<? super T> comparator)
Returns a null-friendly comparator that considers
null to be
less than non-null. |
static <T> SerializableComparator<T> |
nullsLast(SerializableComparator<? super T> comparator)
Returns a null-friendly comparator that considers
null to be
greater than non-null. |
default SerializableComparator<T> |
reversed()
Returns a comparator that imposes the reverse ordering of this
comparator.
|
static <T extends Comparable<? super T>> |
reverseOrder()
Returns a comparator that imposes the reverse of the natural
ordering.
|
default SerializableComparator<T> |
thenComparing(SerializableComparator<? super T> other)
Returns a lexicographic-order comparator with another comparator.
|
default <U extends Comparable<? super U>> |
thenComparing(SerializableFunction<? super T,? extends U> keyExtractor)
Returns a lexicographic-order comparator with a function that
extracts a
Comparable sort key. |
default <U> SerializableComparator<T> |
thenComparing(SerializableFunction<? super T,? extends U> keyExtractor,
SerializableComparator<? super U> keyComparator)
Returns a lexicographic-order comparator with a function that
extracts a key to be compared with the given
SerializableComparator. |
default SerializableComparator<T> |
thenComparingDouble(SerializableToDoubleFunction<? super T> keyExtractor)
Returns a lexicographic-order comparator with a function that
extracts a
double sort key. |
default SerializableComparator<T> |
thenComparingInt(SerializableToIntFunction<? super T> keyExtractor)
Returns a lexicographic-order comparator with a function that
extracts an
int sort key. |
default SerializableComparator<T> |
thenComparingLong(SerializableToLongFunction<? super T> keyExtractor)
Returns a lexicographic-order comparator with a function that
extracts a
long sort key. |
compare, comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, nullsFirst, nullsLast, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongdefault SerializableComparator<T> reversed()
reversed in interface Comparator<T>default SerializableComparator<T> thenComparing(SerializableComparator<? super T> other)
SerializableComparator considers two elements equal, i.e.
compare(a, b) == 0, other is used to determine the order.other - the other comparator to be used when this comparator
compares two objects that are equal.NullPointerException - if the argument is null.String based on the length
and then case-insensitive natural ordering, the comparator can be
composed using following code,
SerializableComparator<String> cmp = SerializableComparator.comparingInt(String::length)
.thenComparing(String.CASE_INSENSITIVE_ORDER);
default <U> SerializableComparator<T> thenComparing(SerializableFunction<? super T,? extends U> keyExtractor, SerializableComparator<? super U> keyComparator)
SerializableComparator.U - the type of the sort keykeyExtractor - the function used to extract the sort keykeyComparator - the SerializableComparator used to compare the sort keyNullPointerException - if either argument is null.comparing(SerializableFunction, SerializableComparator),
thenComparing(SerializableComparator)thenComparing(comparing(keyExtractor, cmp)).default <U extends Comparable<? super U>> SerializableComparator<T> thenComparing(SerializableFunction<? super T,? extends U> keyExtractor)
Comparable sort key.U - the type of the Comparable sort keykeyExtractor - the function used to extract the Comparable sort keyComparable sort key.NullPointerException - if the argument is null.comparing(SerializableFunction),
thenComparing(SerializableComparator)thenComparing(comparing(keyExtractor)).default SerializableComparator<T> thenComparingInt(SerializableToIntFunction<? super T> keyExtractor)
int sort key.keyExtractor - the function used to extract the integer sort keyint sort keyNullPointerException - if the argument is null.comparingInt(SerializableToIntFunction),
thenComparing(SerializableComparator)thenComparing(comparingInt(keyExtractor)).default SerializableComparator<T> thenComparingLong(SerializableToLongFunction<? super T> keyExtractor)
long sort key.keyExtractor - the function used to extract the long sort keylong sort keyNullPointerException - if the argument is null.comparingLong(SerializableToLongFunction),
thenComparing(SerializableComparator)thenComparing(comparingLong(keyExtractor)).default SerializableComparator<T> thenComparingDouble(SerializableToDoubleFunction<? super T> keyExtractor)
double sort key.keyExtractor - the function used to extract the double sort keydouble sort keyNullPointerException - if the argument is null.comparingDouble(SerializableToDoubleFunction),
thenComparing(SerializableComparator)thenComparing(comparingDouble(keyExtractor)).static <T extends Comparable<? super T>> SerializableComparator<T> reverseOrder()
The returned comparator throws NullPointerException when
comparing null.
reverseOrder in interface Comparator<T>T - the Comparable type of element to be comparedComparable objects.Comparablestatic <T extends Comparable<? super T>> SerializableComparator<T> naturalOrder()
Comparable objects in natural
order.
The returned comparator throws NullPointerException when
comparing null.
naturalOrder in interface Comparator<T>T - the Comparable type of element to be comparedComparable objects.Comparablestatic <T> SerializableComparator<T> nullsFirst(SerializableComparator<? super T> comparator)
null to be
less than non-null. When both are null, they are considered
equal. If both are non-null, the specified Comparator is used
to determine the order. If the specified comparator is null,
then the returned comparator considers all non-null values to be equal.T - the type of the elements to be comparedcomparator - a SerializableComparator for comparing non-null valuesnull to be less than
non-null, and compares non-null objects with the supplied
SerializableComparator.static <T> SerializableComparator<T> nullsLast(SerializableComparator<? super T> comparator)
null to be
greater than non-null. When both are null, they are considered
equal. If both are non-null, the specified Comparator is used
to determine the order. If the specified comparator is null,
then the returned comparator considers all non-null values to be equal.T - the type of the elements to be comparedcomparator - a SerializableComparator for comparing non-null valuesnull to be greater than
non-null, and compares non-null objects with the supplied
SerializableComparator.static <T,U> SerializableComparator<T> comparing(SerializableFunction<? super T,? extends U> keyExtractor, SerializableComparator<? super U> keyComparator)
T, and
returns a SerializableComparator<T> that compares by that sort
key using the specified SerializableComparator.
The returned comparator is serializable.
T - the type of element to be comparedU - the type of the sort keykeyExtractor - the function used to extract the sort keykeyComparator - the SerializableComparator used to compare the sort keySerializableComparatorNullPointerException - if either argument is nullSerializableComparator that compares
Person objects by their last name ignoring case differences,
SerializableComparator<Person> cmp = SerializableComparator.comparing(
Person::getLastName,
String.CASE_INSENSITIVE_ORDER);
static <T,U extends Comparable<? super U>> SerializableComparator<T> comparing(SerializableFunction<? super T,? extends U> keyExtractor)
Comparable sort key from a type T, and returns a Comparator<T> that compares by that sort key.T - the type of element to be comparedU - the type of the Comparable sort keykeyExtractor - the function used to extract the Comparable sort keyNullPointerException - if the argument is nullSerializableComparator that compares
Person objects by their last name,
Comparator<Person> byLastName = Comparator.comparing(Person::getLastName);
static <T> SerializableComparator<T> comparingInt(SerializableToIntFunction<? super T> keyExtractor)
int sort key from a type
T, and returns a Comparator<T> that compares by that
sort key.T - the type of element to be comparedkeyExtractor - the function used to extract the integer sort keyNullPointerException - if the argument is nullcomparing(SerializableFunction)static <T> SerializableComparator<T> comparingLong(SerializableToLongFunction<? super T> keyExtractor)
long sort key from a type
T, and returns a Comparator<T> that compares by that
sort key.T - the type of element to be comparedkeyExtractor - the function used to extract the long sort keyNullPointerException - if the argument is nullcomparing(SerializableFunction)static <T> SerializableComparator<T> comparingDouble(SerializableToDoubleFunction<? super T> keyExtractor)
double sort key from a type
T, and returns a SerializableComparator<T> that compares
by that sort key.T - the type of element to be comparedkeyExtractor - the function used to extract the double sort keyNullPointerException - if the argument is nullcomparing(SerializableFunction)Copyright © 2019. All rights reserved.