Package org.apache.commons.collections4.comparators

# Class TransformingComparator<I,O>

java.lang.Object
org.apache.commons.collections4.comparators.TransformingComparator<I,O>

Type Parameters:
  `I` - the type of the input to the function
  `O` - the type of the result of the function

All Implemented Interfaces:
  `Serializable`, `Comparator<I>`

public class TransformingComparator<I,O> extends Object implements Comparator<I>, Serializable
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:
  - `Transformer`
  - `ComparableComparator`
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TransformingComparator(Transformer<? super I,? extends O> transformer)`
  Constructs an instance with the given Transformer and a `ComparableComparator`.
  `TransformingComparator(Transformer<? super I,? extends O> transformer, Comparator<O> decorated)`
  Constructs an instance with the given Transformer and Comparator.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `compare(I obj1, I obj2)`
  Returns the result of comparing the values from the transform operation.
  `boolean`
  `equals(Object object)`
  Returns `true` iff that Object is a `Comparator` whose ordering is known to be equivalent to mine.
  `int`
  `hashCode()`
  Implement a hash code for this comparator that is consistent with `equals`.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface java.util.Comparator

  `reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- ## Constructor Details

  - ### TransformingComparator

    public TransformingComparator(Transformer<? super I,? extends O> transformer)
    Constructs an instance with the given Transformer and a `ComparableComparator`.
    Parameters:
      `transformer` - what will transform the arguments to `compare`

  - ### 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 to `compare`
      `decorated` - the decorated Comparator

- ## Method Details

  - ### compare

    public int compare(I obj1, I obj2)
    Returns the result of comparing the values from the transform operation.
    Specified by:
      `compare` in interface `Comparator<I>`
    Parameters:
      `obj1` - the first object to transform then compare
      `obj2` - the second object to transform then compare
    Returns:
      negative if obj1 is less, positive if greater, zero if equal

  - ### equals

    public boolean equals(Object object)
    Returns `true` iff that Object is a `Comparator` whose ordering is known to be equivalent to mine.

    This implementation returns `true` iff `<em>that</em>` is a `TransformingComparator` whose attributes are equal to mine.

    Specified by:
      `equals` in interface `Comparator<I>`
    Overrides:
      `equals` in class `Object`
    Parameters:
      `object` - the object to compare to
    Returns:
      true if equal

  - ### hashCode

    public int hashCode()
    Implement a hash code for this comparator that is consistent with `equals`.
    Overrides:
      `hashCode` in class `Object`
    Returns:
      a hash code for this comparator.