Interface SerializableComparator<T>
-
- All Superinterfaces:
java.util.Comparator<T>,java.io.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.
@FunctionalInterface public interface SerializableComparator<T> extends java.util.Comparator<T>, java.io.SerializableSerializable version ofComparator.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static <T,U extends java.lang.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 java.lang.Comparable<? super T>>
SerializableComparator<T>naturalOrder()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 java.lang.Comparable<? super T>>
SerializableComparator<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 java.lang.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.
-
-
-
Method Detail
-
reversed
default SerializableComparator<T> reversed()
Returns a comparator that imposes the reverse ordering of this comparator.- Specified by:
reversedin interfacejava.util.Comparator<T>- Returns:
- a comparator that imposes the reverse ordering of this comparator.
- Since:
- 1.8
-
thenComparing
default SerializableComparator<T> thenComparing(SerializableComparator<? super T> other)
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:
java.lang.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:
java.lang.NullPointerException- if either argument is null.- Since:
- 1.8
- See Also:
comparing(SerializableFunction, SerializableComparator),thenComparing(SerializableComparator)
-
thenComparing
default <U extends java.lang.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:
java.lang.NullPointerException- if the argument is null.- Since:
- 1.8
- See Also:
comparing(SerializableFunction),thenComparing(SerializableComparator)
-
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:
java.lang.NullPointerException- if the argument is null.- Since:
- 1.8
- See Also:
comparingInt(SerializableToIntFunction),thenComparing(SerializableComparator)
-
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:
java.lang.NullPointerException- if the argument is null.- Since:
- 1.8
- See Also:
comparingLong(SerializableToLongFunction),thenComparing(SerializableComparator)
-
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:
java.lang.NullPointerException- if the argument is null.- Since:
- 1.8
- See Also:
comparingDouble(SerializableToDoubleFunction),thenComparing(SerializableComparator)
-
reverseOrder
static <T extends java.lang.Comparable<? super T>> SerializableComparator<T> 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:
Comparable
-
naturalOrder
static <T extends java.lang.Comparable<? super T>> SerializableComparator<T> 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:
Comparable
-
nullsFirst
static <T> SerializableComparator<T> nullsFirst(SerializableComparator<? super T> comparator)
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
static <T> SerializableComparator<T> nullsLast(SerializableComparator<? super T> comparator)
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:
java.lang.NullPointerException- if either argument is null- Since:
- 1.8
-
comparing
static <T,U extends java.lang.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:
java.lang.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:
java.lang.NullPointerException- if the argument is null- Since:
- 1.8
- See Also:
comparing(SerializableFunction)
-
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:
java.lang.NullPointerException- if the argument is null- Since:
- 1.8
- See Also:
comparing(SerializableFunction)
-
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:
java.lang.NullPointerException- if the argument is null- Since:
- 1.8
- See Also:
comparing(SerializableFunction)
-
-