java - Rules to implement compare method -
like compareto, have "reflexive, antisymmetric , transitive", there rules implement compare method?? thanks
from comparator api:
the implementor must ensure sgn(compare(x, y)) == -sgn(compare(y, x)) x , y. (this implies compare(x, y) must throw exception if , if compare(y, x) throws exception.) the implementor must ensure relation transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0. finally, implementor must ensure compare(x, y)==0 implies sgn(compare(x, z))==sgn(compare(y, z)) z. it case, not strictly required (compare(x, y)==0) == (x.equals(y)). speaking, comparator violates status should indicate fact. recommended language "note: comparator imposes orderings inconsistent equals." java compare rules comparator compareto
No comments:
Post a Comment