|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.collections15.comparators.ComparatorUtils
public class ComparatorUtils
Provides convenient static utility methods for Comparator
objects.
comparators
package. This class merely provides a convenient
central place if you have use for more than one class in the
comparators
subpackage.
Constructor Summary | |
---|---|
protected |
ComparatorUtils()
Protected constructor prevents direct instantiation, but allows users to extend this library to provide their own augmented static library class. |
Method Summary | ||
---|---|---|
static java.util.Comparator<java.lang.Boolean> |
booleanComparator(boolean trueFirst)
Gets a Comparator that can sort Boolean
objects. |
|
static
|
chainedComparator(java.util.Collection<java.util.Comparator<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
|
max(T o1,
T o2)
Returns the larger of the given objects according to the given comparator, returning the second object if the comparator returns equal. |
|
static
|
max(T o1,
T o2,
java.util.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)
Returns the smaller of the given objects according to the natural sort order of the objects, returning the second object if the comparator returns equal. |
|
static
|
min(T o1,
T o2,
java.util.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
|
naturalComparator()
Gets a comparator that uses the natural order of the objects. |
|
static
|
nullHighComparator()
Gets a Comparator that controls the comparison of null
values. |
|
static
|
nullHighComparator(java.util.Comparator<T> comparator)
Gets a Comparator that controls the comparison of null
values. |
|
static
|
nullLowComparator()
Gets a Comparator that controls the comparison of null
values. |
|
static
|
nullLowComparator(java.util.Comparator<T> comparator)
Gets a Comparator that controls the comparison of null
values. |
|
static
|
reversedComparator()
Gets a Comparator whose ordering is based on the reverse of
the natural ordering of the compared objects. |
|
static
|
reversedComparator(java.util.Comparator<T> comparator)
Gets a Comparator that reverses the order of a specified
comparator. |
|
static
|
transformedComparator(java.util.Comparator<O> comparator,
Transformer<I,O> transformer)
Gets a Comparator that passes transformed objects to the given comparator. |
|
static
|
transformedComparator(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 |
Constructor Detail |
---|
protected ComparatorUtils()
Method Detail |
---|
public static <T extends java.lang.Comparable> java.util.Comparator<T> naturalComparator()
public static <T> java.util.Comparator<T> chainedComparator(java.util.Collection<java.util.Comparator<T>> comparators)
Comparator
s, applied in (default iterator) sequence until
one returns not equal or the collection is exhausted.
comparators
- The Comparators
to use. Cannot be
null
or contains any null
elements. May be empty.
Comparator
that chains together the input
Comparator
s. When comparing two object, it will
iterate through the chain, comparing the objects using each
comparator in turn, and returning the first non-zero result. If
the chain is exhausted and none of the Comparator
s
returns a non-zero value, zero is returned.
java.lang.IllegalArgumentException
- If comparators
is
null
or contains a
null
. It may be empty,
however.public static <T extends java.lang.Comparable> java.util.Comparator<T> reversedComparator()
Comparator
whose ordering is based on the reverse of
the natural ordering of the compared objects.
Comparator
whose ordering is based on the reverse
of the natural ordering of the compared objects.ReverseComparator
public static <T> java.util.Comparator<T> reversedComparator(java.util.Comparator<T> comparator)
Comparator
that reverses the order of a specified
comparator.
comparator
- The Comparator
for which a reversed
ordering is required.
Comparator
whose ordering is the reverse of the
specified input Comparator
.
java.lang.IllegalArgumentException
- Thrown if the specified Comparator
is null
.ReverseComparator
public static java.util.Comparator<java.lang.Boolean> booleanComparator(boolean trueFirst)
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.
trueFirst
- when true
, sort true Boolean
values before false
ones.when
false
, sort true Boolean
values after false
ones.
Comparator
that sorts Boolean
s.public static <T> java.util.Comparator<T> nullLowComparator(java.util.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 extends java.lang.Comparable> java.util.Comparator<T> nullLowComparator()
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 according to their natural ordering.
NullComparator
public static <T> java.util.Comparator<T> nullHighComparator(java.util.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 <T extends java.lang.Comparable> java.util.Comparator<T> nullHighComparator()
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 according to their natural ordering.
NullComparator
public static <I,O extends java.lang.Comparable> java.util.Comparator<I> transformedComparator(Transformer<I,O> transformer)
transformer
- the transformer to use
TransformingComparator
public static <I,O> java.util.Comparator<I> transformedComparator(java.util.Comparator<O> comparator, Transformer<I,O> transformer)
comparator
- the sort order to usetransformer
- the transformer to use
TransformingComparator
public static <T> T min(T o1, T o2, java.util.Comparator<T> comparator)
o1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to use
public static <T extends java.lang.Comparable> T min(T o1, T o2)
o1
- the first object to compareo2
- the second object to compare
public static <T> T max(T o1, T o2, java.util.Comparator<T> comparator)
o1
- the first object to compareo2
- the second object to comparecomparator
- the sort order to use
public static <T extends java.lang.Comparable> T max(T o1, T o2)
o1
- the first object to compareo2
- the second object to compare
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |