org.springframework.util.comparator
Class InstanceComparator<T>
java.lang.Object
org.springframework.util.comparator.InstanceComparator<T>
- Type Parameters:
T
- the type of objects being compared
- All Implemented Interfaces:
- java.util.Comparator<T>
public class InstanceComparator<T>
- extends java.lang.Object
- implements java.util.Comparator<T>
Compares objects based on an arbitrary class order. Allows objects to be sorted based
on the types of class that they inherit, for example: this comparator can be used to
sort a list Number
s such that Long
s occur before Integer
s.
Only the specified instanceOrder
classes are considered during comparison.
If two objects are both instances of the ordered type this comparator will return a
0
. Consider combining with a CompoundComparator
if additional sorting
is required.
- Since:
- 2.0
- Author:
- Phillip Webb
- See Also:
CompoundComparator
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 |
InstanceComparator
public InstanceComparator(java.lang.Class<?>... instanceOrder)
- Create a new
InstanceComparator
instance.
- Parameters:
instanceOrder
- the ordered list of classes that should be used when comparing
objects. Classes earlier in the list will be be given a higher priority.
compare
public int compare(T o1,
T o2)
- Specified by:
compare
in interface java.util.Comparator<T>