org.springframework.core.convert.converter

## Class ConvertingComparator<S,T>

- java.lang.Object
- - org.springframework.core.convert.converter.ConvertingComparator<S,T>

- Type Parameters:
    `S` - the source type
    `T` - the target type
  All Implemented Interfaces:
    Comparator<S>

      public class ConvertingComparator<S,T>
      extends Object
      implements Comparator<S>

  A `Comparator` that converts values before they are compared. The specified `Converter` will be used to convert each value before it passed to the underlying `Comparator`.
  Since:
    3.2
  Author:
    Phillip Webb

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConvertingComparator(Comparator<T> comparator, ConversionService conversionService, Class<? extends T> targetType)` Create a new `ComparableComparator` instance.
    `ConvertingComparator(Comparator<T> comparator, Converter<S,T> converter)` Create a new `ConvertingComparator` instance.
    `ConvertingComparator(Converter<S,T> converter)` Create a new `ConvertingComparator` instance.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compare(S o1, S o2)`
    `static <K,V> ConvertingComparator<Map.Entry<K,V>,K>` | `mapEntryKeys(Comparator<K> comparator)` Create a new `ConvertingComparator` that compares `map * entries` based on their `keys`.
    `static <K,V> ConvertingComparator<Map.Entry<K,V>,V>` | `mapEntryValues(Comparator<V> comparator)` Create a new `ConvertingComparator` that compares `map entries` based on their `values`.

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

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

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

      `comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- - ### Constructor Detail

    - #### ConvertingComparator

          public ConvertingComparator(Converter<S,T> converter)

      Create a new `ConvertingComparator` instance.
      Parameters:
        `converter` - the converter

    - #### ConvertingComparator

          public ConvertingComparator(Comparator<T> comparator,
                                      Converter<S,T> converter)

      Create a new `ConvertingComparator` instance.
      Parameters:
        `comparator` - the underlying comparator used to compare the converted values
        `converter` - the converter

    - #### ConvertingComparator

          public ConvertingComparator(Comparator<T> comparator,
                                      ConversionService conversionService,
                                      Class<? extends T> targetType)

      Create a new `ComparableComparator` instance.
      Parameters:
        `comparator` - the underlying comparator
        `conversionService` - the conversion service
        `targetType` - the target type

  - ### Method Detail

    - #### compare

          public int compare(S o1,
                             S o2)

      Specified by:
        `compare` in interface `Comparator<S>`

    - #### mapEntryKeys

          public static <K,V> ConvertingComparator<Map.Entry<K,V>,K> mapEntryKeys(Comparator<K> comparator)

      Create a new `ConvertingComparator` that compares `map * entries` based on their `keys`.
      Parameters:
        `comparator` - the underlying comparator used to compare keys
      Returns:
        a new `ConvertingComparator` instance

    - #### mapEntryValues

          public static <K,V> ConvertingComparator<Map.Entry<K,V>,V> mapEntryValues(Comparator<V> comparator)

      Create a new `ConvertingComparator` that compares `map entries` based on their `values`.
      Parameters:
        `comparator` - the underlying comparator used to compare values
      Returns:
        a new `ConvertingComparator` instance