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
ConstructorDescriptionConvertingComparator
(Comparator<T> comparator, ConversionService conversionService, Class<? extends T> targetType) Create a newConvertingComparator
instance.ConvertingComparator
(Comparator<T> comparator, Converter<S, T> converter) Create a newConvertingComparator
instance.ConvertingComparator
(Converter<S, T> converter) Create a newConvertingComparator
instance. -
Method Summary
Modifier and TypeMethodDescriptionint
static <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, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
ConvertingComparator
Create a newConvertingComparator
instance.- Parameters:
converter
- the converter
-
ConvertingComparator
Create a newConvertingComparator
instance.- 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 newConvertingComparator
instance.- Parameters:
comparator
- the underlying comparatorconversionService
- the conversion servicetargetType
- the target type
-
-
Method Details
-
compare
- Specified by:
compare
in interfaceComparator<S>
-
mapEntryKeys
- Parameters:
comparator
- the underlying comparator used to compare keys- Returns:
- a new
ConvertingComparator
instance
-
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
ConvertingComparator
instance
-