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:
java.io.Serializable
,java.util.Comparator<I>
public class TransformingComparator<I,O> extends java.lang.Object implements java.util.Comparator<I>, java.io.Serializable
Decorates another Comparator with transformation behavior. That is, the return value from the transform operation will be passed to the decoratedcompare
method.This class is Serializable from Commons Collections 4.0.
- Since:
- 2.1
- See Also:
Transformer
,ComparableComparator
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description TransformingComparator(Transformer<? super I,? extends O> transformer)
Constructs an instance with the given Transformer and aComparableComparator
.TransformingComparator(Transformer<? super I,? extends O> transformer, java.util.Comparator<O> decorated)
Constructs an instance with the given Transformer and Comparator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(I obj1, I obj2)
Returns the result of comparing the values from the transform operation.boolean
equals(java.lang.Object object)
Returnstrue
iff that Object is is aComparator
whose ordering is known to be equivalent to mine.int
hashCode()
Implement a hash code for this comparator that is consistent withequals
.
-
-
-
Constructor Detail
-
TransformingComparator
public TransformingComparator(Transformer<? super I,? extends O> transformer)
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, java.util.Comparator<O> decorated)
Constructs an instance with the given Transformer and Comparator.- Parameters:
transformer
- what will transform the arguments tocompare
decorated
- the decorated Comparator
-
-
Method Detail
-
compare
public int compare(I obj1, I obj2)
Returns the result of comparing the values from the transform operation.- Specified by:
compare
in interfacejava.util.Comparator<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
public int hashCode()
Implement a hash code for this comparator that is consistent withequals
.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code for this comparator.
-
equals
public boolean equals(java.lang.Object object)
Returnstrue
iff that Object is is aComparator
whose ordering is known to be equivalent to mine.This implementation returns
true
iffthat
is aTransformingComparator
whose attributes are equal to mine.- Specified by:
equals
in interfacejava.util.Comparator<I>
- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- the object to compare to- Returns:
- true if equal
-
-