You may wish to implement your own compareTo method for a particular class. In that case there are certain algebraic conditions that you must ensure, namely that
x.compareTo(y) is positive if and only if
y.compareTo(x) is negative, and conversely, and that if either is 0 so is the other.
The second implies that the order relation is transitive:
It is not required that to be equal in the ordering two objects should
in fact be equal. Nonetheless the jdk reommends that
x.compareTo(y) should have the value
if and only if
x.equals(y) is true. An implementation which violates this condition is
encouraged to give a clear indication of the fact by saying
Note: this class has a natural ordering that is inconsistent with equals.Equality of two objects should imply that they are equal in the ordering. But do not be inhibited from using an ordering in which distinct objects may be equal in the ordering, if it serves a useful purpose.