T
- A type which extends/implements Comparablepublic class BasicSorter<T extends java.lang.Comparable>
extends java.lang.Object
implements java.util.Comparator<T>, java.io.Serializable
Comparator
, used to sort instances of
Comparable
s in ascending or descending order. Direction of
the sort is specified upon construction.Modifier and Type | Field and Description |
---|---|
private int |
direction
Multiplier used to adjust (possibly invert) sorting
|
Modifier | Constructor and Description |
---|---|
protected |
BasicSorter(boolean ascending)
Constructor which stores the sort direction.
|
Modifier and Type | Method and Description |
---|---|
int |
compare(T d1,
T d2)
Compare two
Comparable instances to determine relative
sort order. |
boolean |
equals(java.lang.Object o)
Test for equality between this comparator and another.
|
protected int |
getDirection()
Report the direction in which this sorter sorts its data.
|
int |
hashCode()
Calculate a hash code for this object.
|
private final int direction
protected BasicSorter(boolean ascending)
ascending
- true
if sort should be ascending;
false
if it should be descending.public int compare(T d1, T d2)
Comparable
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<T extends java.lang.Comparable>
d1
- First value to compare. Must not be null
.d2
- Second value to compare. Must not be null
.d1
> d2
;
negative value if d1
< d2
;
0
if d1
and d2
sort
equivalently.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in interface java.util.Comparator<T extends java.lang.Comparable>
equals
in class java.lang.Object
true
if objects are equal, else
false
.protected int getDirection()