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:
    java.util.Comparator<S>


    public class ConvertingComparator<S,T>
    extends java.lang.Object
    implements java.util.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 Detail

      • ConvertingComparator

        public ConvertingComparator(Converter<S,T> converter)
        Create a new ConvertingComparator instance.
        Parameters:
        converter - the converter
      • ConvertingComparator

        public ConvertingComparator(java.util.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(java.util.Comparator<T> comparator,
                                    ConversionService conversionService,
                                    java.lang.Class<? extends T> targetType)
        Create a new ConvertingComparator 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 java.util.Comparator<S>
      • mapEntryKeys

        public static <K,V> ConvertingComparator<java.util.Map.Entry<K,V>,K> mapEntryKeys(java.util.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<java.util.Map.Entry<K,V>,V> mapEntryValues(java.util.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