Spring for Android

org.springframework.core.convert.converter
Class ConvertingComparator<S,T>

java.lang.Object
  extended by 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:
2.0
Author:
Phillip Webb

Constructor Summary
ConvertingComparator(java.util.Comparator<T> comparator, ConversionService conversionService, java.lang.Class<? extends T> targetType)
          Create a new ComparableComparator instance.
ConvertingComparator(java.util.Comparator<T> comparator, Converter<S,T> converter)
          Create a new ConvertingComparator instance.
ConvertingComparator(Converter<S,T> converter)
          Create a new ConvertingComparator instance.
 
Method Summary
 int compare(S o1, S o2)
           
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.
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.
 
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
 

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 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 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

Spring for Android