java - Negate comparison chain -
i wrote like
@override public int compareto(cuboid that) { return -comparisonchain.start() .compare(this.d0, that.d0) .compare(this.d1, that.d1) .compare(this.d2, that.d2) .result(); } to reverse order, negated result, see wrong docs says
ends comparison chain , returns result: value having same sign first nonzero comparison result in chain, or 0 if every result zero.
so integer.min_value allowed return value , negation fails. in source code, can see nothing -1, 0, , +1 gets ever returned, isn't i'd depend on.
instead of negation swap operands. simple , ugly, i'm curious if there's better solution.
i don't know if that's better (personally don't involve floating point operations), send through math#signum:
return -math.signum( .... ); i'd swap operands.
Comments
Post a Comment