public final class ComparatorUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T extends java.lang.Comparable<T>> |
comparingNullsFirst()
Builds a comparator that can be used to compare and sort instances of any type that extends
Comparable. |
static <T,R extends java.lang.Comparable<R>> |
comparingNullsFirst(java.util.function.Function<? super T,? extends R> keyExtractor)
Builds a comparator that can be used to compare and sort instances of any type, provided that the
keyExtractor function retrieves an instance of Comparable from them. |
static <T extends java.lang.Comparable<T>> |
comparingNullsLast()
Builds a comparator that can be used to compare and sort instances of any type that extends
Comparable. |
static <T,R extends java.lang.Comparable<R>> |
comparingNullsLast(java.util.function.Function<? super T,? extends R> keyExtractor)
Builds a comparator that can be used to compare and sort instances of any type, provided that the
keyExtractor function retrieves an instance of Comparable from them. |
public static <T extends java.lang.Comparable<T>> java.util.Comparator<T> comparingNullsFirst()
Comparable. The comparator sorts in a way that null values come before all non-null ones.T - The type of the elements to be compared, extending the Comparable interface.public static <T,R extends java.lang.Comparable<R>> java.util.Comparator<T> comparingNullsFirst(java.util.function.Function<? super T,? extends R> keyExtractor)
keyExtractor function retrieves an instance of Comparable from them. The comparator
sorts in a way that null values come before all non-null ones. Note that, because this method takes a
function as its first parameter, that any of the function building methods from MapperUtils are fair game
here.T - The type of the elements to be compared.R - The type of the key value to be extracted, which must extend the Comparable interface.keyExtractor - An extractor function that retrieves a key value from a target element, the value being an
instance of Comparable, which will be compared based on its natural order, with nulls being
evaluated as less than non-nulls.public static <T extends java.lang.Comparable<T>> java.util.Comparator<T> comparingNullsLast()
Comparable. The comparator sorts in a way that null values come after all non-null ones.T - The type of the elements to be compared, extending the Comparable interface.public static <T,R extends java.lang.Comparable<R>> java.util.Comparator<T> comparingNullsLast(java.util.function.Function<? super T,? extends R> keyExtractor)
keyExtractor function retrieves an instance of Comparable from them. The comparator
sorts in a way that null values come after all non-null ones. Note that, because this method takes a
function as its first parameter, that any of the function building methods from MapperUtils are fair game
here.T - The type of the elements to be compared.R - The type of the key value to be extracted, which must extend the Comparable interface.keyExtractor - An extractor function that retrieves a key value from a target element, the value being an
instance of Comparable, which will be compared based on its natural order, with nulls being
evaluated as greater than non-nulls.