Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
Arrays of Objects that implement this interface can be sorted automatically by List.sort. Objects of these classes can also be used as keys in SortedMap objects or elements in SortedSet objects without the need to specify a Comparator.
A Comparator c imposes a total ordering on class C if and only if e1.compare2(e2)==0 implies that e1.equals(e2) for every e1 and e2 of class C. This is mentioned here because some applications that call for a comparator will require that the comparator impose a total ordering (such as SortedMap and SortedSet).
Method Summary | |
int | compareTo(Object o)
|
Method Detail |
public int compareTo(Object o)
The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)
The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.
The implementer must also ensure that x.equals(y) implies that x.compareTo(y)==0. Note that the converse is not necessarily true (e.g., BigDecimal). If the converse is false, the natural ordering for this class is not total.
Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
o
- the Object
to be compared.
Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |