|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.collections.ComparatorUtils
Provides convenient static utility methods for Comparator
objects.
Most of the utility 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.
Note that every method in this class allows you to specify
null
instead of a comparator, in which case
NATURAL_COMPARATOR
will be used.
Field Summary | |
static java.util.Comparator |
NATURAL_COMPARATOR
Comparator for natural sort order. |
Method Summary | |
static java.util.Comparator |
chainedComparator(java.util.Collection comparators)
Gets a comparator that compares using a collection of Comparator s. |
static java.util.Comparator |
chainedComparator(java.util.Comparator[] comparators)
Gets a comparator that compares using an array of Comparator s. |
static java.util.Comparator |
chainedComparator(java.util.Comparator comparator1,
java.util.Comparator comparator2)
Gets a comparator that compares using two Comparator s. |
static java.lang.Object |
max(java.lang.Object o1,
java.lang.Object o2,
java.util.Comparator comparator)
Returns the smaller of the given objects according to the given comparator. |
static java.lang.Object |
min(java.lang.Object o1,
java.lang.Object o2,
java.util.Comparator comparator)
Returns the smaller of the given objects according to the given comparator. |
static java.util.Comparator |
naturalComparator()
Gets a comparator that uses the natural order of the objects. |
static java.util.Comparator |
nullHighComparator(java.util.Comparator comparator)
Gets a Comparator that controls the comparison of null values. |
static java.util.Comparator |
nullLowComparator(java.util.Comparator comparator)
Gets a Comparator that controls the comparison of null values. |
static java.util.Comparator |
reversedComparator(java.util.Comparator comparator)
Gets a comparator that reverses the order of the given comparator. |
static java.util.Comparator |
transformedComparator(java.util.Comparator comparator,
Transformer transformer)
Gets a Comparator that passes transformed objects to the given comparator. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.util.Comparator NATURAL_COMPARATOR
ComparableComparator.getInstance()
Method Detail |
public static java.util.Comparator naturalComparator()
public static java.util.Comparator chainedComparator(java.util.Comparator comparator1, java.util.Comparator comparator2)
Comparator
s.
The second comparator is used if the first comparator returns that equal.
comparator1
- the first comparator to use, not nullcomparator2
- the first comparator to use, not null
java.lang.NullPointerException
- if either comparator is nullpublic static java.util.Comparator chainedComparator(java.util.Comparator[] comparators)
Comparator
s.
The second comparator is used if the first comparator returns that equal and so on.
java.lang.NullPointerException
- if comparators array is null or contains a nullpublic static java.util.Comparator chainedComparator(java.util.Collection comparators)
Comparator
s.
The second comparator is used if the first comparator returns that equal and so on.
comparators
- the comparators to use, not null or empty or contain nulls
java.lang.NullPointerException
- if comparators collection is null or contains a null
java.lang.ClassCastException
- if the comparators collection contains the wrong object typepublic static java.util.Comparator reversedComparator(java.util.Comparator comparator)
comparator
- the comparator whose order to reverse
ReverseComparator
public static java.util.Comparator nullLowComparator(java.util.Comparator 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 java.util.Comparator nullHighComparator(java.util.Comparator 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 java.util.Comparator transformedComparator(java.util.Comparator comparator, Transformer 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 java.lang.Object min(java.lang.Object o1, java.lang.Object o2, java.util.Comparator comparator)
o1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to use
public static java.lang.Object max(java.lang.Object o1, java.lang.Object o2, java.util.Comparator comparator)
o1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to use
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |