org.apache.commons.collections
Class ComparatorUtils
java.lang.Object
org.apache.commons.collections.ComparatorUtils
public class ComparatorUtils
extends java.lang.Object
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.
static Comparator | chainedComparator(Collection comparators) - Gets a comparator that compares using a collection of
Comparator s.
|
static Comparator | chainedComparator(Comparator comparator1, Comparator comparator2) - Gets a comparator that compares using two
Comparator s.
|
static Comparator | chainedComparator(Comparator[] comparators) - Gets a comparator that compares using an array of
Comparator s.
|
static Object | max(Object o1, Object o2, Comparator comparator) - Returns the smaller of the given objects according to the given
comparator.
|
static Object | min(Object o1, Object o2, Comparator comparator) - Returns the smaller of the given objects according to the given
comparator.
|
static Comparator | naturalComparator() - Gets a comparator that uses the natural order of the objects.
|
static Comparator | nullHighComparator(Comparator comparator) - Gets a Comparator that controls the comparison of
null values.
|
static Comparator | nullLowComparator(Comparator comparator) - Gets a Comparator that controls the comparison of
null values.
|
static Comparator | reversedComparator(Comparator comparator) - Gets a comparator that reverses the order of the given
comparator.
|
static Comparator | transformedComparator(Comparator comparator, Transformer transformer) - Gets a Comparator that passes transformed objects to the given comparator.
|
NATURAL_COMPARATOR
public static final Comparator NATURAL_COMPARATOR
Comparator for natural sort order.
chainedComparator
public static Comparator chainedComparator(Collection comparators)
Gets a comparator that compares using a collection of
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
- a combination comparator over the comparators
chainedComparator
public static Comparator chainedComparator(Comparator comparator1,
Comparator comparator2)
Gets a comparator that compares using two
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
- a combination comparator over the comparators
chainedComparator
public static Comparator chainedComparator(Comparator[] comparators)
Gets a comparator that compares using an array of
Comparator
s.
The second comparator is used if the first comparator returns
that equal and so on.
- a combination comparator over the comparators
max
public static Object max(Object o1,
Object o2,
Comparator comparator)
Returns the smaller of the given objects according to the given
comparator.
o1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to use
- the smaller of the two objects
min
public static Object min(Object o1,
Object o2,
Comparator comparator)
Returns the smaller of the given objects according to the given
comparator.
o1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to use
- the smaller of the two objects
naturalComparator
public static Comparator naturalComparator()
Gets a comparator that uses the natural order of the objects.
- a comparator which uses natural order
nullHighComparator
public static Comparator nullHighComparator(Comparator comparator)
Gets a Comparator that controls the comparison of
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
- a version of that comparator that allows nulls
nullLowComparator
public static Comparator nullLowComparator(Comparator comparator)
Gets a Comparator that controls the comparison of
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
- a version of that comparator that allows nulls
reversedComparator
public static Comparator reversedComparator(Comparator comparator)
Gets a comparator that reverses the order of the given
comparator.
comparator
- the comparator whose order to reverse
- a comparator who reverses that order
transformedComparator
public static Comparator transformedComparator(Comparator comparator,
Transformer transformer)
Gets a Comparator that passes transformed objects to the given comparator.
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
- a comparator that transforms its input objects before comparing them
Copyright © 2001-2004 Apache Software Foundation. Documenation generated ${TODAY}.