Class AbstractSortOrderComparator<T>
- java.lang.Object
-
- com.globalmentor.collections.comparators.AbstractSortOrderComparator<T>
-
- Type Parameters:
T
- The type of objects that may be compared by this comparator.
- All Implemented Interfaces:
SortOrderComparator<T>
,java.util.Comparator<T>
- Direct Known Subclasses:
AbstractChainedSortOrderComparator
,AbstractCollatedSortOrderComparator
,SerialDelegateComparator
,ValuedComparator
public abstract class AbstractSortOrderComparator<T> extends java.lang.Object implements SortOrderComparator<T>
A comparator that can sort in ascending or descending order.- Author:
- Garret Wilson
- See Also:
SortOrder
-
-
Constructor Summary
Constructors Constructor Description AbstractSortOrderComparator(SortOrder sortOrder)
Sort order constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compare(T object1, T object2)
This implementation performs an identity comparison and then delegates tocompareImpl(Object, Object)
, returning a negative version of the result ifgetSortOrder()
isSortOrder.DESCENDING
.protected abstract int
compareImpl(T object1, T object2)
Implementation to compare two objects for order.SortOrder
getSortOrder()
-
-
-
Constructor Detail
-
AbstractSortOrderComparator
public AbstractSortOrderComparator(SortOrder sortOrder)
Sort order constructor.- Parameters:
sortOrder
- The order in which to perform comparisons.- Throws:
java.lang.NullPointerException
- if the given sort order isnull
.
-
-
Method Detail
-
getSortOrder
public SortOrder getSortOrder()
- Specified by:
getSortOrder
in interfaceSortOrderComparator<T>
- Returns:
- The order in which to perform comparisons.
-
compare
public final int compare(T object1, T object2)
This implementation performs an identity comparison and then delegates tocompareImpl(Object, Object)
, returning a negative version of the result ifgetSortOrder()
isSortOrder.DESCENDING
.- Specified by:
compare
in interfacejava.util.Comparator<T>
-
compareImpl
protected abstract int compareImpl(T object1, T object2)
Implementation to compare two objects for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Implementations do not need to perform special checks for identity, as thecompare(Object, Object)
implementation will do this.- 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.
-
-