| java.lang.Object org.apache.commons.collections.ComparatorUtils
ComparatorUtils | public class ComparatorUtils (Code) | | 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.
since: Commons Collections 2.1 version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $ author: Paul Jack author: Stephen Colebourne |
Constructor Summary | |
public | ComparatorUtils() ComparatorUtils should not normally be instantiated. |
Method Summary | |
public static Comparator | booleanComparator(boolean trueFirst) Gets a Comparator that can sort Boolean objects.
The parameter specifies whether true or false is sorted first.
The comparator throws NullPointerException if a null value is compared.
Parameters: trueFirst - when true , sort true Booleans beforefalse Booleans. | public static Comparator | chainedComparator(Comparator comparator1, Comparator comparator2) Gets a comparator that compares using two
Comparator s. | public static Comparator | chainedComparator(Comparator[] 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. | public static Comparator | chainedComparator(Collection 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. | public static Object | max(Object o1, Object o2, Comparator comparator) Returns the larger of the given objects according to the given
comparator, returning the second object if the comparator
returns equal. | public static Object | min(Object o1, Object o2, Comparator comparator) Returns the smaller of the given objects according to the given
comparator, returning the second object if the comparator
returns equal. | public static Comparator | naturalComparator() Gets a comparator that uses the natural order of the objects. | 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. | 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. | public static Comparator | reversedComparator(Comparator comparator) Gets a comparator that reverses the order of the given comparator. | public static Comparator | transformedComparator(Comparator comparator, Transformer transformer) Gets a Comparator that passes transformed objects to the given comparator. |
ComparatorUtils | public ComparatorUtils()(Code) | | ComparatorUtils should not normally be instantiated.
|
booleanComparator | public static Comparator booleanComparator(boolean trueFirst)(Code) | | Gets a Comparator that can sort Boolean objects.
The parameter specifies whether true or false is sorted first.
The comparator throws NullPointerException if a null value is compared.
Parameters: trueFirst - when true , sort true Booleans beforefalse Booleans. a comparator that sorts booleans |
chainedComparator | public static Comparator chainedComparator(Comparator comparator1, Comparator comparator2)(Code) | | Gets a comparator that compares using two
Comparator s.
The second comparator is used if the first comparator returns equal.
Parameters: comparator1 - the first comparator to use, not null Parameters: comparator2 - the first comparator to use, not null a ComparatorChain formed from the two comparators throws: NullPointerException - if either comparator is null See Also: ComparatorChain |
chainedComparator | public static Comparator chainedComparator(Comparator[] comparators)(Code) | | Gets a comparator that compares using an array of
Comparator s, applied
in sequence until one returns not equal or the array is exhausted.
Parameters: comparators - the comparators to use, not null or empty or containing nulls a ComparatorChain formed from the input comparators throws: NullPointerException - if comparators array is null or contains a null See Also: ComparatorChain |
chainedComparator | public static Comparator chainedComparator(Collection comparators)(Code) | | 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.
Parameters: comparators - the comparators to use, not null or empty or containing nulls a ComparatorChain formed from the input comparators throws: NullPointerException - if comparators collection is null or contains a null throws: ClassCastException - if the comparators collection contains the wrong object type See Also: ComparatorChain |
max | public static Object max(Object o1, Object o2, Comparator comparator)(Code) | | Returns the larger of the given objects according to the given
comparator, returning the second object if the comparator
returns equal.
Parameters: o1 - the first object to compare Parameters: o2 - the second object to compare Parameters: comparator - the sort order to use the larger of the two objects |
min | public static Object min(Object o1, Object o2, Comparator comparator)(Code) | | Returns the smaller of the given objects according to the given
comparator, returning the second object if the comparator
returns equal.
Parameters: o1 - the first object to compare Parameters: o2 - the second object to compare Parameters: comparator - the sort order to use the smaller of the two objects |
naturalComparator | public static Comparator naturalComparator()(Code) | | Gets a comparator that uses the natural order of the objects.
a comparator which uses natural order |
nullHighComparator | public static Comparator nullHighComparator(Comparator comparator)(Code) | | 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.
Parameters: comparator - the comparator that wants to allow nulls a version of that comparator that allows nulls See Also: NullComparator |
nullLowComparator | public static Comparator nullLowComparator(Comparator comparator)(Code) | | 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.
Parameters: comparator - the comparator that wants to allow nulls a version of that comparator that allows nulls See Also: NullComparator |
reversedComparator | public static Comparator reversedComparator(Comparator comparator)(Code) | | Gets a comparator that reverses the order of the given comparator.
Parameters: comparator - the comparator to reverse a comparator that reverses the order of the input comparator See Also: ReverseComparator |
transformedComparator | public static Comparator transformedComparator(Comparator comparator, Transformer transformer)(Code) | | 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.
Parameters: comparator - the sort order to use Parameters: transformer - the transformer to use a comparator that transforms its input objects before comparing them See Also: TransformingComparator |
|
|