Top Description Fields Constructors Methods
org.apache.commons.collections4.comparators

public Class TransformingComparator<I, O>

extends Object
implements Comparator<I>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.Comparator
Type Parameters
<I>
the input type to the transformer
<O>
the output type from the transformer
Imports
java.io.Serializable, java.util.Comparator, org.apache.commons.collections4.ComparatorUtils, .Transformer

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
org.apache.commons.collections4.Transformer, org.apache.commons.collections4.comparators.ComparableComparator

Field Summary

Modifier and TypeField and Description
private final Comparator<O>
decorated

The decorated comparator.

private static final long
serialVersionUID

Serialization version from Collections 4.0.

private final Transformer<? super I, ? extends O>
transformer

The transformer being used.

Constructor Summary

AccessConstructor and Description
public
TransformingComparator(final Transformer<? super I, ? extends O>
what will transform the arguments to compare
transformer
)

Constructs an instance with the given Transformer and a ComparableComparator.

public
TransformingComparator(final Transformer<? super I, ? extends O>
what will transform the arguments to compare
transformer
,
final Comparator<O>
the decorated Comparator
decorated
)

Constructs an instance with the given Transformer and Comparator.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

negative if obj1 is less, positive if greater, zero if equal
compare
(final I
the first object to transform then compare
obj1
,
final I
the second object to transform then compare
obj2
)

Implements java.util.Comparator.compare.

Returns the result of comparing the values from the transform operation.
public boolean

Returns:

true if equal
equals
(final Object
the object to compare to
object
)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

Returns true iff that Object is is a Comparator whose ordering is known to be equivalent to mine.
public int

Returns:

a hash code for this comparator.
hashCode
()

Overrides java.lang.Object.hashCode.

Implement a hash code for this comparator that is consistent with equals.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

decoratedback to summary
private final Comparator<O> decorated

The decorated comparator.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version from Collections 4.0.

transformerback to summary
private final Transformer<? super I, ? extends O> transformer

The transformer being used.

Constructor Detail

TransformingComparatorback to summary
public TransformingComparator(final Transformer<? super I, ? extends O> transformer)

Constructs an instance with the given Transformer and a ComparableComparator.

Parameters
transformer:Transformer<? super I, ? extends O>

what will transform the arguments to compare

TransformingComparatorback to summary
public TransformingComparator(final Transformer<? super I, ? extends O> transformer, final Comparator<O> decorated)

Constructs an instance with the given Transformer and Comparator.

Parameters
transformer:Transformer<? super I, ? extends O>

what will transform the arguments to compare

decorated:Comparator<O>

the decorated Comparator

Method Detail

compareback to summary
public int compare(final I obj1, final I obj2)

Implements java.util.Comparator.compare.

Returns the result of comparing the values from the transform operation.

Parameters
obj1:I

the first object to transform then compare

obj2:I

the second object to transform then compare

Returns:int

negative if obj1 is less, positive if greater, zero if equal

Annotations
@Override
equalsback to summary
public boolean equals(final Object object)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

Returns true iff that Object is is a Comparator whose ordering is known to be equivalent to mine.

This implementation returns true iff that is a TransformingComparator whose attributes are equal to mine.

Parameters
object:Object

the object to compare to

Returns:boolean

true if equal

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implement a hash code for this comparator that is consistent with equals.

Returns:int

a hash code for this comparator.

Annotations
@Override