Class DefaultOrderComparator<T>
- java.lang.Object
-
- com.globalmentor.collections.comparators.DefaultOrderComparator<T>
-
- All Implemented Interfaces:
java.util.Comparator<T>
public class DefaultOrderComparator<T> extends java.lang.Object implements java.util.Comparator<T>
A comparator that compares object according to their default order, as specified in a list.Derived classes may use this comparison algorithm as a default fallback.
- Author:
- Garret Wilson
-
-
Constructor Summary
Constructors Constructor Description DefaultOrderComparator(java.util.List<T> defaultOrderList)
Constructs a comparator to compare objects based upon the order in which they appear in a given list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(T object1, T object2)
Compares actions by the order in which the appear in the default order list.protected java.util.List<T>
getDefaultOrderList()
-
-
-
Constructor Detail
-
DefaultOrderComparator
public DefaultOrderComparator(java.util.List<T> defaultOrderList)
Constructs a comparator to compare objects based upon the order in which they appear in a given list.- Parameters:
defaultOrderList
- The list that determines the default order of the objects. This must not a different list than any list being sorted.- Throws:
java.lang.NullPointerException
- if the given list isnull
-
-
Method Detail
-
getDefaultOrderList
protected java.util.List<T> getDefaultOrderList()
- Returns:
- The list that determines the default order of the objects.
-
compare
public int compare(T object1, T object2)
Compares actions by the order in which the appear in the default order list.- Specified by:
compare
in interfacejava.util.Comparator<T>
- Parameters:
object1
- The first object to be compared.object2
- The second object to be compared.- Returns:
- A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
- Throws:
java.lang.ClassCastException
- if the arguments' types prevent them from being compared by this comparator.java.lang.IllegalArgumentException
- if one of the objects is not in the default order list.- See Also:
getDefaultOrderList()
-
-