public class ComparatorUtils
extends java.lang.Object
Comparator
objects.
Most of the functionality in this class can also be found in the
comparators
package. This class merely provides a
convenient central place if you have use for more than one class
in the comparators
subpackage.
Modifier and Type | Field and Description |
---|---|
static java.util.Comparator |
NATURAL_COMPARATOR
Comparator for natural sort order.
|
Modifier and Type | Method and Description |
---|---|
static java.util.Comparator<java.lang.Boolean> |
booleanComparator(boolean trueFirst)
Gets a Comparator that can sort Boolean objects.
|
static <E> java.util.Comparator<E> |
chainedComparator(java.util.Collection<java.util.Comparator<E>> comparators)
Gets a comparator that compares using a collection of
Comparator s,
applied in (default iterator) sequence until one returns not equal or the
collection is exhausted. |
static <E> java.util.Comparator<E> |
chainedComparator(java.util.Comparator<E>... comparators)
Gets a comparator that compares using an array of
Comparator s, applied
in sequence until one returns not equal or the array is exhausted. |
static <E> E |
max(E o1,
E o2,
java.util.Comparator<E> comparator)
Returns the larger of the given objects according to the given
comparator, returning the second object if the comparator
returns equal.
|
static <E> E |
min(E o1,
E o2,
java.util.Comparator<E> comparator)
Returns the smaller of the given objects according to the given
comparator, returning the second object if the comparator
returns equal.
|
static <E extends java.lang.Comparable<? super E>> |
naturalComparator()
Gets a comparator that uses the natural order of the objects.
|
static <E> java.util.Comparator<E> |
nullHighComparator(java.util.Comparator<E> comparator)
Gets a Comparator that controls the comparison of
null values. |
static <E> java.util.Comparator<E> |
nullLowComparator(java.util.Comparator<E> comparator)
Gets a Comparator that controls the comparison of
null values. |
static <E> java.util.Comparator<E> |
reversedComparator(java.util.Comparator<E> comparator)
Gets a comparator that reverses the order of the given comparator.
|
static <I,O> java.util.Comparator<I> |
transformedComparator(java.util.Comparator<O> comparator,
Transformer<? super I,? extends O> transformer)
Gets a Comparator that passes transformed objects to the given comparator.
|
public static final java.util.Comparator NATURAL_COMPARATOR
public static <E extends java.lang.Comparable<? super E>> java.util.Comparator<E> naturalComparator()
E
- the object type to comparepublic static <E> java.util.Comparator<E> chainedComparator(java.util.Comparator<E>... comparators)
Comparator
s, applied
in sequence until one returns not equal or the array is exhausted.E
- the object type to comparecomparators
- the comparators to use, not null or empty or containing nullsComparatorChain
formed from the input comparatorsjava.lang.NullPointerException
- if comparators array is null or contains a nullComparatorChain
public static <E> java.util.Comparator<E> chainedComparator(java.util.Collection<java.util.Comparator<E>> comparators)
Comparator
s,
applied in (default iterator) sequence until one returns not equal or the
collection is exhausted.E
- the object type to comparecomparators
- the comparators to use, not null or empty or containing nullsComparatorChain
formed from the input comparatorsjava.lang.NullPointerException
- if comparators collection is null or contains a nulljava.lang.ClassCastException
- if the comparators collection contains the wrong object typeComparatorChain
public static <E> java.util.Comparator<E> reversedComparator(java.util.Comparator<E> comparator)
E
- the object type to comparecomparator
- the comparator to reverseReverseComparator
public static java.util.Comparator<java.lang.Boolean> booleanComparator(boolean trueFirst)
The parameter specifies whether true or false is sorted first.
The comparator throws NullPointerException if a null value is compared.
trueFirst
- when true
, sort
true
Boolean
s before
false
Boolean
s.public static <E> java.util.Comparator<E> nullLowComparator(java.util.Comparator<E> comparator)
null
values.
The returned comparator will consider a null value to be less than any nonnull value, and equal to any other null value. Two nonnull values will be evaluated with the given comparator.
E
- the object type to comparecomparator
- the comparator that wants to allow nullsNullComparator
public static <E> java.util.Comparator<E> nullHighComparator(java.util.Comparator<E> comparator)
null
values.
The returned comparator will consider a null value to be greater than any nonnull value, and equal to any other null value. Two nonnull values will be evaluated with the given comparator.
E
- the object type to comparecomparator
- the comparator that wants to allow nullsNullComparator
public static <I,O> java.util.Comparator<I> transformedComparator(java.util.Comparator<O> comparator, Transformer<? super I,? extends O> transformer)
Objects passed to the returned comparator will first be transformed by the given transformer before they are compared by the given comparator.
I
- the input object type of the transformed comparatorO
- the object type of the decorated comparatorcomparator
- the sort order to usetransformer
- the transformer to useTransformingComparator
public static <E> E min(E o1, E o2, java.util.Comparator<E> comparator)
E
- the object type to compareo1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to usepublic static <E> E max(E o1, E o2, java.util.Comparator<E> comparator)
E
- the object type to compareo1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to use"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"