Class ComparatorUtils
- java.lang.Object
-
- org.apache.commons.collections.ComparatorUtils
-
@Deprecated(since="2021-04-30") public class ComparatorUtils extends java.lang.Object
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.Provides convenient static utility methods forComparator
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 thecomparators
subpackage.- Since:
- Commons Collections 2.1
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Comparator
NATURAL_COMPARATOR
Deprecated.Comparator for natural sort order.
-
Constructor Summary
Constructors Constructor Description ComparatorUtils()
Deprecated.ComparatorUtils should not normally be instantiated.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.util.Comparator
booleanComparator(boolean trueFirst)
Deprecated.Gets a Comparator that can sort Boolean objects.static java.util.Comparator
chainedComparator(java.util.Collection comparators)
Deprecated.Gets a comparator that compares using a collection ofComparator
s, applied in (default iterator) sequence until one returns not equal or the collection is exhausted.static java.util.Comparator
chainedComparator(java.util.Comparator[] comparators)
Deprecated.Gets a comparator that compares using an array ofComparator
s, applied in sequence until one returns not equal or the array is exhausted.static java.util.Comparator
chainedComparator(java.util.Comparator comparator1, java.util.Comparator comparator2)
Deprecated.Gets a comparator that compares using twoComparator
s.static java.lang.Object
max(java.lang.Object o1, java.lang.Object o2, java.util.Comparator comparator)
Deprecated.Returns the larger of the given objects according to the given comparator, returning the second object if the comparator returns equal.static java.lang.Object
min(java.lang.Object o1, java.lang.Object o2, java.util.Comparator comparator)
Deprecated.Returns the smaller of the given objects according to the given comparator, returning the second object if the comparator returns equal.static java.util.Comparator
naturalComparator()
Deprecated.Gets a comparator that uses the natural order of the objects.static java.util.Comparator
nullHighComparator(java.util.Comparator comparator)
Deprecated.Gets a Comparator that controls the comparison ofnull
values.static java.util.Comparator
nullLowComparator(java.util.Comparator comparator)
Deprecated.Gets a Comparator that controls the comparison ofnull
values.static java.util.Comparator
reversedComparator(java.util.Comparator comparator)
Deprecated.Gets a comparator that reverses the order of the given comparator.static java.util.Comparator
transformedComparator(java.util.Comparator comparator, Transformer transformer)
Deprecated.Gets a Comparator that passes transformed objects to the given comparator.
-
-
-
Field Detail
-
NATURAL_COMPARATOR
public static final java.util.Comparator NATURAL_COMPARATOR
Deprecated.Comparator for natural sort order.- See Also:
ComparableComparator.getInstance()
-
-
Method Detail
-
naturalComparator
public static java.util.Comparator naturalComparator()
Deprecated.Gets a comparator that uses the natural order of the objects.- Returns:
- a comparator which uses natural order
-
chainedComparator
public static java.util.Comparator chainedComparator(java.util.Comparator comparator1, java.util.Comparator comparator2)
Deprecated.Gets a comparator that compares using twoComparator
s.The second comparator is used if the first comparator returns equal.
- Parameters:
comparator1
- the first comparator to use, not nullcomparator2
- the first comparator to use, not null- Returns:
- a
ComparatorChain
formed from the two comparators - Throws:
java.lang.NullPointerException
- if either comparator is null- See Also:
ComparatorChain
-
chainedComparator
public static java.util.Comparator chainedComparator(java.util.Comparator[] comparators)
Deprecated.Gets a comparator that compares using an array ofComparator
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- Returns:
- a
ComparatorChain
formed from the input comparators - Throws:
java.lang.NullPointerException
- if comparators array is null or contains a null- See Also:
ComparatorChain
-
chainedComparator
public static java.util.Comparator chainedComparator(java.util.Collection comparators)
Deprecated.Gets a comparator that compares using a collection ofComparator
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- Returns:
- a
ComparatorChain
formed from the input comparators - Throws:
java.lang.NullPointerException
- if comparators collection is null or contains a nulljava.lang.ClassCastException
- if the comparators collection contains the wrong object type- See Also:
ComparatorChain
-
reversedComparator
public static java.util.Comparator reversedComparator(java.util.Comparator comparator)
Deprecated.Gets a comparator that reverses the order of the given comparator.- Parameters:
comparator
- the comparator to reverse- Returns:
- a comparator that reverses the order of the input comparator
- See Also:
ReverseComparator
-
booleanComparator
public static java.util.Comparator booleanComparator(boolean trueFirst)
Deprecated.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
- whentrue
, sorttrue
Boolean
s beforefalse
Boolean
s.- Returns:
- a comparator that sorts booleans
-
nullLowComparator
public static java.util.Comparator nullLowComparator(java.util.Comparator comparator)
Deprecated.Gets a Comparator that controls the comparison ofnull
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- Returns:
- a version of that comparator that allows nulls
- See Also:
NullComparator
-
nullHighComparator
public static java.util.Comparator nullHighComparator(java.util.Comparator comparator)
Deprecated.Gets a Comparator that controls the comparison ofnull
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- Returns:
- a version of that comparator that allows nulls
- See Also:
NullComparator
-
transformedComparator
public static java.util.Comparator transformedComparator(java.util.Comparator comparator, Transformer transformer)
Deprecated.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 usetransformer
- the transformer to use- Returns:
- a comparator that transforms its input objects before comparing them
- See Also:
TransformingComparator
-
min
public static java.lang.Object min(java.lang.Object o1, java.lang.Object o2, java.util.Comparator comparator)
Deprecated.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 compareo2
- the second object to comparecomparator
- the sort order to use- Returns:
- the smaller of the two objects
-
max
public static java.lang.Object max(java.lang.Object o1, java.lang.Object o2, java.util.Comparator comparator)
Deprecated.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 compareo2
- the second object to comparecomparator
- the sort order to use- Returns:
- the larger of the two objects
-
-