public class ToStringComparator<T> extends Object implements Comparator<T>, Serializable
Comparator
interface which uses
the result of the toString
method to compare the objects.
Ie. by using this comparator objects are sorted according to the
toString()
values.
Note: this comparator may impose orderings that are inconsistent with equals.
Modifier and Type | Field and Description |
---|---|
private boolean |
descending |
private static long |
serialVersionUID |
Constructor and Description |
---|
ToStringComparator(boolean descending)
Create a new comparator.
|
Modifier and Type | Method and Description |
---|---|
int |
compare(T o1,
T o2) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
private static final long serialVersionUID
private final boolean descending
public ToStringComparator(boolean descending)
descending
- TRUE to sort objects in descending order (z--a),
FALSE to sort the objects in ascending order (a--z)public int compare(T o1, T o2)
compare
in interface Comparator<T>