Java Comparator.compare
Compares its two arguments for order. Returns a negatvie integer , zero , or a positive integer as the first argument is less than , equal to , or greater than the second.
比较两个参数的顺序。返回一个负数,零,正数,分别对应着 第一个参数 小于,等于,大于第二个参数。
In the foregoing description , the notation sgn(expressior) designates the mathematical signum funcion, which is defined to return one of -1,0,or 1 according to whether the value of expression in negative , zero or positive.
在前面的描述中,符号sgn(expressior)指定这个数学符号函数,该函数被定义为根据表达式的值是负的,零还是正数来返回-1,0,1;
The implementor must ensure that sgn(compare(x,y)) == -sgn(compare(y,x)) for all x and y. (This implies that compare(x,y) must throw an exception if and only if compare(y,x) throws an exception.)
实现这个接口是必须确保所有的x和y的sgn(compare(x,y))== -sgn(compare(y,x)) . 这也就意味着compare(x,y)必须要在且仅在compare(y,x)抛出异常时抛出异常。
The implementor must also ensure that the relation is transitive:((compare(x,y)>0)&&(compare(y,z)>0)) implies compare(x,z)>0.
实现这个接口也需要确保实现下面这个关系传递:((compare(x,y)>0)&&(compare(y,z)>0)) implies compare(x,z)>0.
Finally, the implementor must ensure the compare(x,y) == 0 implies that sgn(compare(x,z)) == sgn(compare(y,z)) for all z.
最后,实现者必须确保compare(x,y) == 0 也就意味着所有的z都要保证,(compare(x,z) == sgn(compare(y,z)))
It is generally the case, but not strictly required that (compare(x,y)0)(x.equals(y)).Generally speaking, any comparator that violates this condition should clearly indicate this fact. The recommended language is “Note: this comparator imposes orderings that are inconsistent with equals”
一般是这样,但不是严格要求(compare(x,y)==0)=(x.equals(y))。一般来说,任何违反这个条件的比较器都应该清楚地指出这个事实。建议使用的语言是“注意:这个比较器强加的顺序与equals不一致”