Class SerialDelegateComparator<T>
java.lang.Object
com.globalmentor.collections.comparators.AbstractSortOrderComparator<T>
com.globalmentor.collections.comparators.SerialDelegateComparator<T>
- Type Parameters:
T
- The type of objects that may be compared by this comparator.
- All Implemented Interfaces:
SortOrderComparator<T>
,Comparator<T>
A comparator that can perform comparisons based upon a sequence of other comparators. The last comparator in the sequence should unambiguously distinguish
non-equal objects.
If this comparator is used in descending order mode, delegate comparators that implement SortOrderComparator
should be used in ascending mode, as
this comparator will sort in reverse order automatically; otherwise, the descending orders will cancel each other out and each sub-comparison will be
performed in ascending order.
Descending order for this comparator does not mean that the delegates will be traversed in reverse order.
- Author:
- Garret Wilson
-
Constructor Summary
ConstructorDescriptionSerialDelegateComparator
(SortOrder sortOrder, Comparator<? super T>... comparators) Sort order constructor and comparators constructor.SerialDelegateComparator
(Comparator<? super T>... comparators) Comparators constructor for ascending order sorting. -
Method Summary
Modifier and TypeMethodDescriptionint
compareImpl
(T object1, T object2) Implementation to compare two objects for order.Methods inherited from class com.globalmentor.collections.comparators.AbstractSortOrderComparator
compare, getSortOrder
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
-
SerialDelegateComparator
Comparators constructor for ascending order sorting. The last comparator in the sequence should unambiguously distinguish non-equal objects.- Parameters:
comparators
- The delegate comparators.- Throws:
NullPointerException
- if the given sort order and/or comparators isnull
.IllegalArgumentException
- if no comparators are given.
-
SerialDelegateComparator
Sort order constructor and comparators constructor. The last comparator in the sequence should unambiguously distinguish non-equal objects.- Parameters:
sortOrder
- The order in which to perform comparisons.comparators
- The delegate comparators.- Throws:
NullPointerException
- if the given sort order and/or comparators isnull
.IllegalArgumentException
- if no comparators are given.
-
-
Method Details
-
compareImpl
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 theAbstractSortOrderComparator.compare(Object, Object)
implementation will do this.- Specified by:
compareImpl
in classAbstractSortOrderComparator<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.
-