| Method from org.apache.commons.collections.ComparatorUtils Detail: |
public static Comparator booleanComparator(boolean trueFirst) {
return BooleanComparator.getBooleanComparator(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. |
public static Comparator chainedComparator(Comparator[] comparators) {
ComparatorChain chain = new ComparatorChain();
for (int i = 0; i < comparators.length; i++) {
if (comparators[i] == null) {
throw new NullPointerException("Comparator cannot be null");
}
chain.addComparator(comparators[i]);
}
return chain;
}
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) {
return chainedComparator(
(Comparator[]) comparators.toArray(new Comparator[comparators.size()])
);
}
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 Comparator chainedComparator(Comparator comparator1,
Comparator comparator2) {
return chainedComparator(new Comparator[] {comparator1, comparator2});
}
|
public static Object max(Object o1,
Object o2,
Comparator comparator) {
if (comparator == null) {
comparator = NATURAL_COMPARATOR;
}
int c = comparator.compare(o1, o2);
return (c > 0) ? o1 : o2;
}
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) {
if (comparator == null) {
comparator = NATURAL_COMPARATOR;
}
int c = comparator.compare(o1, o2);
return (c < 0) ? o1 : o2;
}
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() {
return NATURAL_COMPARATOR;
}
Gets a comparator that uses the natural order of the objects. |
public static Comparator nullHighComparator(Comparator comparator) {
if (comparator == null) {
comparator = NATURAL_COMPARATOR;
}
return new NullComparator(comparator, true);
}
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. |
public static Comparator nullLowComparator(Comparator comparator) {
if (comparator == null) {
comparator = NATURAL_COMPARATOR;
}
return new NullComparator(comparator, false);
}
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. |
public static Comparator reversedComparator(Comparator comparator) {
if (comparator == null) {
comparator = NATURAL_COMPARATOR;
}
return new ReverseComparator(comparator);
}
Gets a comparator that reverses the order of the given comparator. |
public static Comparator transformedComparator(Comparator comparator,
Transformer transformer) {
if (comparator == null) {
comparator = NATURAL_COMPARATOR;
}
return new TransformingComparator(transformer, comparator);
}
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. |