DATATYPE - The data type to be compared@NotThreadSafe public abstract class AbstractComparator<DATATYPE> extends Object implements ISerializableComparator<DATATYPE>
| Constructor and Description |
|---|
AbstractComparator()
Comparator with default sort order and no nested comparator.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compare(DATATYPE aElement1,
DATATYPE aElement2) |
Comparator<? super DATATYPE> |
getNestedComparator() |
ESortOrder |
getSortOrder() |
boolean |
isNullValuesComeFirst() |
protected abstract int |
mainCompare(DATATYPE aElement1,
DATATYPE aElement2) |
AbstractComparator<DATATYPE> |
setNestedComparator(Comparator<? super DATATYPE> aNestedComparator)
Set a nested comparator to be invoked if the comparison result of this
comparator is 0.
|
AbstractComparator<DATATYPE> |
setNullValuesComeFirst(boolean bNullValuesComeFirst)
Change the sort position of
null values. |
AbstractComparator<DATATYPE> |
setSortOrder(ESortOrder eSortOrder)
Call this to enable sorting after the constructor was invoked.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic AbstractComparator()
@Nonnull public final ESortOrder getSortOrder()
null.@Nonnull public final AbstractComparator<DATATYPE> setSortOrder(@Nonnull ESortOrder eSortOrder)
eSortOrder - The sort order to use. May not be null.public final boolean isNullValuesComeFirst()
true if null values are to be ordered
before non-null values, false if
null are to be sorted after non-null
values.@Nonnull public final AbstractComparator<DATATYPE> setNullValuesComeFirst(boolean bNullValuesComeFirst)
null values.bNullValuesComeFirst - true if null values should come first,
false if null values should go last.@Nonnull public final Comparator<? super DATATYPE> getNestedComparator()
null.@Nonnull public final AbstractComparator<DATATYPE> setNestedComparator(@Nullable Comparator<? super DATATYPE> aNestedComparator)
aNestedComparator - The nested comparator to be invoked, when the main comparison
resulted in 0. May be null.protected abstract int mainCompare(@Nonnull DATATYPE aElement1, @Nonnull DATATYPE aElement2)
aElement1 - First element to compare. Never null.aElement2 - Second element to compare. Never null.public final int compare(DATATYPE aElement1, DATATYPE aElement2)
compare in interface Comparator<DATATYPE>Copyright © 2014–2015 Philip Helger. All rights reserved.