Class TransformingComparator<I,O>
java.lang.Object
org.apache.commons.collections4.comparators.TransformingComparator<I,O>
- Type Parameters:
I- the input type to the transformerO- the output type from the transformer
- All Implemented Interfaces:
Serializable, Comparator<I>
Decorates another Comparator with transformation behavior. That is, the
return value from the transform operation will be passed to the decorated
compare method.
This class is Serializable from Commons Collections 4.0.
- Since:
- 2.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Comparator<O> The decorated comparator.private static final longSerialization version from Collections 4.0.private final Transformer<? super I, ? extends O> The transformer being used. -
Constructor Summary
ConstructorsConstructorDescriptionTransformingComparator(Transformer<? super I, ? extends O> transformer) Constructs an instance with the given Transformer and aComparableComparator.TransformingComparator(Transformer<? super I, ? extends O> transformer, Comparator<O> decorated) Constructs an instance with the given Transformer and Comparator. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the result of comparing the values from the transform operation.booleanReturnstrueiff that Object is is aComparatorwhose ordering is known to be equivalent to mine.inthashCode()Implement a hash code for this comparator that is consistent withequals.Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization version from Collections 4.0.- See Also:
-
decorated
The decorated comparator. -
transformer
The transformer being used.
-
-
Constructor Details
-
TransformingComparator
Constructs an instance with the given Transformer and aComparableComparator.- Parameters:
transformer- what will transform the arguments tocompare
-
TransformingComparator
public TransformingComparator(Transformer<? super I, ? extends O> transformer, Comparator<O> decorated) Constructs an instance with the given Transformer and Comparator.- Parameters:
transformer- what will transform the arguments tocomparedecorated- the decorated Comparator
-
-
Method Details
-
compare
Returns the result of comparing the values from the transform operation.- Specified by:
comparein interfaceComparator<I>- Parameters:
obj1- the first object to transform then compareobj2- the second object to transform then compare- Returns:
- negative if obj1 is less, positive if greater, zero if equal
-
hashCode
-
equals
Returnstrueiff that Object is is aComparatorwhose ordering is known to be equivalent to mine.This implementation returns
trueiffthatis aTransformingComparatorwhose attributes are equal to mine.- Specified by:
equalsin interfaceComparator<I>- Overrides:
equalsin classObject- Parameters:
object- the object to compare to- Returns:
- true if equal
-