Class ConvertingComparator<S,T>
java.lang.Object
org.springframework.core.convert.converter.ConvertingComparator<S,T>
- Type Parameters:
S- the source typeT- the target type
- All Implemented Interfaces:
Comparator<S>
A
Comparator that converts values before they are compared.
The specified Converter will be used to convert each value
before it is passed to the underlying Comparator.
- Since:
- 3.2
- Author:
- Phillip Webb
-
Constructor Summary
ConstructorsConstructorDescriptionConvertingComparator(Comparator<T> comparator, ConversionService conversionService, Class<? extends T> targetType) Create a newConvertingComparatorinstance.ConvertingComparator(Comparator<T> comparator, Converter<S, T> converter) Create a newConvertingComparatorinstance.ConvertingComparator(Converter<S, T> converter) Create a newConvertingComparatorinstance. -
Method Summary
Modifier and TypeMethodDescriptionintstatic <K,V> ConvertingComparator<Map.Entry<K, V>, K> mapEntryKeys(Comparator<K> comparator) static <K,V> ConvertingComparator<Map.Entry<K, V>, V> mapEntryValues(Comparator<V> comparator) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
ConvertingComparator
Create a newConvertingComparatorinstance.- Parameters:
converter- the converter
-
ConvertingComparator
Create a newConvertingComparatorinstance.- Parameters:
comparator- the underlying comparator used to compare the converted valuesconverter- the converter
-
ConvertingComparator
public ConvertingComparator(Comparator<T> comparator, ConversionService conversionService, Class<? extends T> targetType) Create a newConvertingComparatorinstance.- Parameters:
comparator- the underlying comparatorconversionService- the conversion servicetargetType- the target type
-
-
Method Details
-
compare
- Specified by:
comparein interfaceComparator<S>
-
mapEntryKeys
- Parameters:
comparator- the underlying comparator used to compare keys- Returns:
- a new
ConvertingComparatorinstance
-
mapEntryValues
public static <K,V> ConvertingComparator<Map.Entry<K,V>, mapEntryValuesV> (Comparator<V> comparator) - Parameters:
comparator- the underlying comparator used to compare values- Returns:
- a new
ConvertingComparatorinstance
-