|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.collections.ComparatorUtils
public class ComparatorUtils
Provides convenient static utility methods for 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.
Field Summary | |
---|---|
static Comparator |
NATURAL_COMPARATOR
Comparator for natural sort order. |
Constructor Summary | |
---|---|
ComparatorUtils()
ComparatorUtils should not normally be instantiated. |
Method Summary | ||
---|---|---|
static Comparator<Boolean> |
booleanComparator(boolean trueFirst)
Gets a Comparator that can sort Boolean objects. |
|
static
|
chainedComparator(Collection<T> 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
|
chainedComparator(Comparator<T>[] 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
|
chainedComparator(Comparator<T> comparator1,
Comparator<T> comparator2)
Gets a comparator that compares using two Comparator s. |
|
static
|
max(T o1,
T o2,
Comparator<T> comparator)
Returns the larger of the given objects according to the given comparator, returning the second object if the comparator returns equal. |
|
static
|
min(T o1,
T o2,
Comparator<T> comparator)
Returns the smaller of the given objects according to the given comparator, returning the second object if the comparator returns equal. |
|
static Comparator |
naturalComparator()
Gets a comparator that uses the natural order of the objects. |
|
static
|
nullHighComparator(Comparator<T> comparator)
Gets a Comparator that controls the comparison of null values. |
|
static
|
nullLowComparator(Comparator<T> comparator)
Gets a Comparator that controls the comparison of null values. |
|
static
|
reversedComparator(Comparator<T> comparator)
Gets a comparator that reverses the order of the given comparator. |
|
static
|
transformedComparator(Comparator<I> comparator,
Transformer<I,O> transformer)
Gets a Comparator that passes transformed objects to the given comparator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Comparator NATURAL_COMPARATOR
ComparableComparator.getInstance()
Constructor Detail |
---|
public ComparatorUtils()
Method Detail |
---|
public static Comparator naturalComparator()
public static <T> Comparator<T> chainedComparator(Comparator<T> comparator1, Comparator<T> comparator2)
Comparator
s.
The second comparator is used if the first comparator returns equal.
comparator1
- the first comparator to use, not nullcomparator2
- the first comparator to use, not null
ComparatorChain
formed from the two comparators
NullPointerException
- if either comparator is nullComparatorChain
public static <T> Comparator<T> chainedComparator(Comparator<T>[] comparators)
Comparator
s, applied
in sequence until one returns not equal or the array is exhausted.
comparators
- the comparators to use, not null or empty or containing nulls
ComparatorChain
formed from the input comparators
NullPointerException
- if comparators array is null or contains a nullComparatorChain
public static <T> Comparator<T> chainedComparator(Collection<T> comparators)
Comparator
s,
applied in (default iterator) sequence until one returns not equal or the
collection is exhausted.
comparators
- the comparators to use, not null or empty or containing nulls
ComparatorChain
formed from the input comparators
NullPointerException
- if comparators collection is null or contains a null
ClassCastException
- if the comparators collection contains the wrong object typeComparatorChain
public static <T> Comparator<T> reversedComparator(Comparator<T> comparator)
comparator
- the comparator to reverse
ReverseComparator
public static Comparator<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 <T> Comparator<T> nullLowComparator(Comparator<T> 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.
comparator
- the comparator that wants to allow nulls
NullComparator
public static <T> Comparator<T> nullHighComparator(Comparator<T> 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.
comparator
- the comparator that wants to allow nulls
NullComparator
public static <I,O> Comparator<O> transformedComparator(Comparator<I> comparator, Transformer<I,O> transformer)
Objects passed to the returned comparator will first be transformed by the given transformer before they are compared by the given comparator.
comparator
- the sort order to usetransformer
- the transformer to use
TransformingComparator
public static <T> T min(T o1, T o2, Comparator<T> comparator)
o1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to use
public static <T> T max(T o1, T o2, Comparator<T> comparator)
o1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to use
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |