public class SortIndexComparator<T extends Sorted> extends java.lang.Object implements java.util.Comparator<T>
Note: this comparator can impose orderings that are inconsistent with equals.
In order to overcome the inconsistency with equals this comparator allows the introduction of a sub-comparator which is applied in cases of equality. I.e. if the two compared objects have the same sorting index and they would be regarded as equal by this comparator, instead of 0 the result of the sub-comparator's comparison is returned.
Note 2: If the subcomparator is not consistent with this comparator, this can lead to wrong results! For example, if this comparator returns compare(o2, o3) < 0 and is undefined on other both (o1, o3) and (o1, o2), and the subcomparator returns compare(o1, o2) < 0 and compare(o3, o1) < 0, then it is impossible to predict if a sorting algorithm might return the ordering (o1, o2, o3) or (o3, o1, o2), or (o2, o3, o1).
|Modifier and Type||Field and Description|
|Constructor and Description|
Creates a new SortIndexComparator object.
|Modifier and Type||Method and Description|
Compares its two arguments for order according to their sort indices.
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public SortIndexComparator(java.util.Comparator<? super T> sameIndexSubComparator)
sameIndexSubComparator- if two objects with the same sort index are compared, the given sub-comparator is applied (if not null).