final class DataSorter extends BasicSorter<BaseDataType>
BasicSorter
, used to sort instances of
BaseDataType
. Direction of the sort is specified upon
construction. Unknown value sorts high in an ascending sort.
Instances of this class should be retrieved using the static method getInstance(boolean)
.
Modifier and Type | Field and Description |
---|---|
private static DataSorter |
ASCENDER
Shared instance of an ascending
DataSorter |
private static DataSorter |
DESCENDER
Shared instance of an descending
DataSorter |
Constructor and Description |
---|
DataSorter(boolean ascending) |
Modifier and Type | Method and Description |
---|---|
int |
compare(BaseDataType d1,
BaseDataType d2)
Compare two
BaseDataType instances to determine relative
sort order. |
static DataSorter |
getInstance(boolean ascending)
Helper method to retrieve an instance of this class which sorts in the
specified direction.
|
equals, getDirection, hashCode
private static final DataSorter ASCENDER
DataSorter
private static final DataSorter DESCENDER
DataSorter
public static DataSorter getInstance(boolean ascending)
ascending
- true
if sort should be ascending;
false
if it should be descending.public int compare(BaseDataType d1, BaseDataType d2)
BaseDataType
instances to determine relative
sort order. The comparison uses the natural order of the objects,
except that unknown value always sorts high in an ascending sort. The
result is inverted for descending sorts (meaning unknown value sorts low
in a descending sort.compare
in interface java.util.Comparator<BaseDataType>
compare
in class BasicSorter<BaseDataType>
d1
- First value to compare. May be unknown, but must not be
null
.d2
- Second value to compare. May be unknown, but must not be
null
.d1
> d2
;
negative value if d1
< d2
;
0
if d1
and d2
sort
equivalently.