public final class Comparators extends Object
Comparators.| Modifier and Type | Method and Description |
|---|---|
static <T> Comparator<T> |
compose(Comparator<? super T>... comparators)
Returns a
Comparator that will call each Comparator
in the given array until one of them returns a non-zero result (will
return 0 if they all return 0). |
static <T> Comparator<T> |
compose(Iterable<? extends Comparator<? super T>> comparators)
Returns a
Comparator that will call each Comparator
in the given Iterable until one of them returns a non-zero
result (will return 0 if they all return 0). |
static <T extends Comparable<? super T>> |
naturalOrder()
Returns a
Comparator that compares Comparable objects
in natural order. |
static <T> Comparator<T> |
reverse(Comparator<T> comparator)
Returns a
Comparator that represents the reverse ordering of
the given one. |
static <T> Comparator<T> |
withNullsFirst(Comparator<T> comparator)
Returns a new
Comparator that considers null values
as less than all other values and compares non-null values
with the given Comparator. |
static <T> Comparator<T> |
withNullsLast(Comparator<T> comparator)
Returns a new
Comparator that considers null values
as greater than all other values and compares non-null values
with the given Comparator. |
public static <T> Comparator<T> compose(Comparator<? super T>... comparators)
Comparator that will call each Comparator
in the given array until one of them returns a non-zero result (will
return 0 if they all return 0).T - the parameters type of the returned Comparator.comparators - the Comparators to compose.Comparator.NullPointerException - if comparators is null
of if it contains a null reference.IllegalArgumentException - if comparators is empty.public static <T> Comparator<T> compose(Iterable<? extends Comparator<? super T>> comparators)
Comparator that will call each Comparator
in the given Iterable until one of them returns a non-zero
result (will return 0 if they all return 0).T - the parameters type of the returned Comparator.comparators - the Comparators to compose.Comparator.NullPointerException - if comparators is null
of if it contains a null reference.IllegalArgumentException - if comparators is empty.public static <T> Comparator<T> reverse(Comparator<T> comparator)
Comparator that represents the reverse ordering of
the given one. Namely, the returned Comparator will return
a negative value if the original returns a positive value and,
conversely, will return a positive value if it returns a negative
value.T - the parameters type of the Comparators.comparator - the comparator to invert.Comparator.NullPointerException - if comparator is null.public static <T extends Comparable<? super T>> Comparator<T> naturalOrder()
Comparator that compares Comparable objects
in natural order. The returned comparator doesn't accept null
values.T - the Comparable type.Comparator that compares Comparable objects.public static <T> Comparator<T> withNullsFirst(Comparator<T> comparator)
Comparator that considers null values
as less than all other values and compares non-null values
with the given Comparator.T - the parameters type of the Comparator.comparator - the non-null values ComparatorComparator.NullPointerException - if comparator is null.public static <T> Comparator<T> withNullsLast(Comparator<T> comparator)
Comparator that considers null values
as greater than all other values and compares non-null values
with the given Comparator.T - the parameters type of the Comparator.comparator - the non-null values Comparator.Comparator.NullPointerException - if comparator is null.Copyright © 2012–2015. All rights reserved.