Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this
object is less than, equal to, or greater than the specified object.
为排序将对象与指定的对象进行比较,根据比较的结果是小于,等于或者是大于而返回一个负数,零或者正数。
In the foregoing description, the notation sgn(expression) designates the mathematical signum function, which is defined to
return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive. 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.)
在前述中,符号sgn(expression)指出:数学函数必须根据表达式expression的值是负数,0,或者正数而返回一个-1,0,或者是1。实现该接口
者必须确保对于任意的对象x,y都有x.compareTo(y)) == -sgn(y.compareTo(x)成立。(这暗示如果x.compareTo(y)会抛出异常的话,那么
x.compareTo(x),也必须抛出一个异常。)
The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo
(z)>0
实现者必须确保关系是传递的:即(x.compareTo(y)>0 && y.compareTo(z)>0)意味着x.compareTo(z)>0成立。
Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all
z.
最后,实现者必须确保x.compareTo(y)==0可以得到对于任意的z可以使得sgn(x.compareTo(z)) == sgn(y.compareTo(z))成立
It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any
class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended
language is "Note: this class has a natural ordering that is inconsistent with equals."
虽然不是非常的需要,但是必须强调的是,(x.compareTo(y)==0) ==(x.equals(y))。一般说来,任何实现了Compareable接口,但是违背了这
种情况的类必须清楚的指出这一点。指出的语句如下:“注释,该类具有和equals()方法不同的自然排序方法。