Interface SerializableComparator<T>
- All Superinterfaces:
Comparator<T>,Serializable
- All Known Implementing Classes:
SerializableComparatorWrapperClass
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Serializable version of
Comparator.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,U extends Comparable<? super U>>
SerializableComparator<T> comparing(SerializableFunction<? super T, ? extends U> keyExtractor) Accepts a function that extracts aComparablesort key from a typeT, and returns aComparator<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 typeT, and returns aSerializableComparator<T>that compares by that sort key using the specifiedSerializableComparator.static <T> SerializableComparator<T> comparingDouble(SerializableToDoubleFunction<? super T> keyExtractor) Accepts a function that extracts adoublesort key from a typeT, and returns aSerializableComparator<T>that compares by that sort key.static <T> SerializableComparator<T> comparingInt(SerializableToIntFunction<? super T> keyExtractor) Accepts a function that extracts anintsort key from a typeT, and returns aComparator<T>that compares by that sort key.static <T> SerializableComparator<T> comparingLong(SerializableToLongFunction<? super T> keyExtractor) Accepts a function that extracts alongsort key from a typeT, and returns aComparator<T>that compares by that sort key.static <T extends Comparable<? super T>>
SerializableComparator<T> Returns a comparator that comparesComparableobjects in natural order.static <T> SerializableComparator<T> nullsFirst(SerializableComparator<? super T> comparator) Returns a null-friendly comparator that considersnullto be less than non-null.static <T> SerializableComparator<T> nullsLast(SerializableComparator<? super T> comparator) Returns a null-friendly comparator that considersnullto 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>>
SerializableComparator<T> 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>>
SerializableComparator<T> thenComparing(SerializableFunction<? super T, ? extends U> keyExtractor) Returns a lexicographic-order comparator with a function that extracts aComparablesort 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 givenSerializableComparator.default SerializableComparator<T> thenComparingDouble(SerializableToDoubleFunction<? super T> keyExtractor) Returns a lexicographic-order comparator with a function that extracts adoublesort key.default SerializableComparator<T> thenComparingInt(SerializableToIntFunction<? super T> keyExtractor) Returns a lexicographic-order comparator with a function that extracts anintsort key.default SerializableComparator<T> thenComparingLong(SerializableToLongFunction<? super T> keyExtractor) Returns a lexicographic-order comparator with a function that extracts alongsort key.Methods inherited from interface java.util.Comparator
compare, equals, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Method Details
-
reversed
Returns a comparator that imposes the reverse ordering of this comparator.- Specified by:
reversedin interfaceComparator<T>- Returns:
- a comparator that imposes the reverse ordering of this comparator.
- Since:
- 1.8
-
thenComparing
Returns a lexicographic-order comparator with another comparator. If thisSerializableComparatorconsiders two elements equal, i.e.compare(a, b) == 0,otheris used to determine the order.- Parameters:
other- the other comparator to be used when this comparator compares two objects that are equal.- Returns:
- a lexicographic-order comparator composed of this and then the other comparator
- Throws:
NullPointerException- if the argument is null.- Since:
- 1.8
-
thenComparing
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 givenSerializableComparator.- Type Parameters:
U- the type of the sort key- Parameters:
keyExtractor- the function used to extract the sort keykeyComparator- theSerializableComparatorused to compare the sort key- Returns:
- a lexicographic-order comparator composed of this comparator and then comparing on the key extracted by the keyExtractor function
- Throws:
NullPointerException- if either argument is null.- Since:
- 1.8
- See Also:
-
thenComparing
default <U extends Comparable<? super U>> SerializableComparator<T> thenComparing(SerializableFunction<? super T, ? extends U> keyExtractor) Returns a lexicographic-order comparator with a function that extracts aComparablesort key.- Type Parameters:
U- the type of theComparablesort key- Parameters:
keyExtractor- the function used to extract theComparablesort key- Returns:
- a lexicographic-order comparator composed of this and then the
Comparablesort key. - Throws:
NullPointerException- if the argument is null.- Since:
- 1.8
- See Also:
-
thenComparingInt
default SerializableComparator<T> thenComparingInt(SerializableToIntFunction<? super T> keyExtractor) Returns a lexicographic-order comparator with a function that extracts anintsort key.- Parameters:
keyExtractor- the function used to extract the integer sort key- Returns:
- a lexicographic-order comparator composed of this and then the
intsort key - Throws:
NullPointerException- if the argument is null.- Since:
- 1.8
- See Also:
-
thenComparingLong
default SerializableComparator<T> thenComparingLong(SerializableToLongFunction<? super T> keyExtractor) Returns a lexicographic-order comparator with a function that extracts alongsort key.- Parameters:
keyExtractor- the function used to extract the long sort key- Returns:
- a lexicographic-order comparator composed of this and then the
longsort key - Throws:
NullPointerException- if the argument is null.- Since:
- 1.8
- See Also:
-
thenComparingDouble
default SerializableComparator<T> thenComparingDouble(SerializableToDoubleFunction<? super T> keyExtractor) Returns a lexicographic-order comparator with a function that extracts adoublesort key.- Parameters:
keyExtractor- the function used to extract the double sort key- Returns:
- a lexicographic-order comparator composed of this and then the
doublesort key - Throws:
NullPointerException- if the argument is null.- Since:
- 1.8
- See Also:
-
reverseOrder
Returns a comparator that imposes the reverse of the natural ordering.The returned comparator throws
NullPointerExceptionwhen comparingnull.- Type Parameters:
T- theComparabletype of element to be compared- Returns:
- a comparator that imposes the reverse of the natural
ordering on
Comparableobjects. - Since:
- 1.8
- See Also:
-
naturalOrder
Returns a comparator that comparesComparableobjects in natural order.The returned comparator throws
NullPointerExceptionwhen comparingnull.- Type Parameters:
T- theComparabletype of element to be compared- Returns:
- a comparator that imposes the natural ordering on
Comparableobjects. - Since:
- 1.8
- See Also:
-
nullsFirst
Returns a null-friendly comparator that considersnullto be less than non-null. When both arenull, they are considered equal. If both are non-null, the specifiedComparatoris used to determine the order. If the specified comparator isnull, then the returned comparator considers all non-null values to be equal.- Type Parameters:
T- the type of the elements to be compared- Parameters:
comparator- aSerializableComparatorfor comparing non-null values- Returns:
- a comparator that considers
nullto be less than non-null, and compares non-null objects with the suppliedSerializableComparator. - Since:
- 1.8
-
nullsLast
Returns a null-friendly comparator that considersnullto be greater than non-null. When both arenull, they are considered equal. If both are non-null, the specifiedComparatoris used to determine the order. If the specified comparator isnull, then the returned comparator considers all non-null values to be equal.- Type Parameters:
T- the type of the elements to be compared- Parameters:
comparator- aSerializableComparatorfor comparing non-null values- Returns:
- a comparator that considers
nullto be greater than non-null, and compares non-null objects with the suppliedSerializableComparator. - Since:
- 1.8
-
comparing
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 typeT, and returns aSerializableComparator<T>that compares by that sort key using the specifiedSerializableComparator.The returned comparator is serializable.
- Type Parameters:
T- the type of element to be comparedU- the type of the sort key- Parameters:
keyExtractor- the function used to extract the sort keykeyComparator- theSerializableComparatorused to compare the sort key- Returns:
- a comparator that compares by an extracted key using the
specified
SerializableComparator - Throws:
NullPointerException- if either argument is null- Since:
- 1.8
-
comparing
static <T,U extends Comparable<? super U>> SerializableComparator<T> comparing(SerializableFunction<? super T, ? extends U> keyExtractor) Accepts a function that extracts aComparablesort key from a typeT, and returns aComparator<T>that compares by that sort key.- Type Parameters:
T- the type of element to be comparedU- the type of theComparablesort key- Parameters:
keyExtractor- the function used to extract theComparablesort key- Returns:
- a comparator that compares by an extracted key
- Throws:
NullPointerException- if the argument is null- Since:
- 1.8
-
comparingInt
static <T> SerializableComparator<T> comparingInt(SerializableToIntFunction<? super T> keyExtractor) Accepts a function that extracts anintsort key from a typeT, and returns aComparator<T>that compares by that sort key.- Type Parameters:
T- the type of element to be compared- Parameters:
keyExtractor- the function used to extract the integer sort key- Returns:
- a comparator that compares by an extracted key
- Throws:
NullPointerException- if the argument is null- Since:
- 1.8
- See Also:
-
comparingLong
static <T> SerializableComparator<T> comparingLong(SerializableToLongFunction<? super T> keyExtractor) Accepts a function that extracts alongsort key from a typeT, and returns aComparator<T>that compares by that sort key.- Type Parameters:
T- the type of element to be compared- Parameters:
keyExtractor- the function used to extract the long sort key- Returns:
- a comparator that compares by an extracted key
- Throws:
NullPointerException- if the argument is null- Since:
- 1.8
- See Also:
-
comparingDouble
static <T> SerializableComparator<T> comparingDouble(SerializableToDoubleFunction<? super T> keyExtractor) Accepts a function that extracts adoublesort key from a typeT, and returns aSerializableComparator<T>that compares by that sort key.- Type Parameters:
T- the type of element to be compared- Parameters:
keyExtractor- the function used to extract the double sort key- Returns:
- a comparator that compares by an extracted key
- Throws:
NullPointerException- if the argument is null- Since:
- 1.8
- See Also:
-