Working on a sorted list I came to a point I needed to implement a compareTo() function for primitive long values.
I'm not looking for the obvious naive implementation, but was wondering if there's an elegant one-liner code to do that (without creating a new Long(value)).
Maybe something like this:
@Override public int compareTo(MyClass that) {
return (int) ((value - that.value) >>> 32);
}
Can anyone verify that would work and/or suggest another implementation?
(x < y) ? -1 : ((x == y) ? 0 : 1)
right? I'm wondering if there's something that wouldn't require 2 internal if-then calls, assuming it would be more efficient. – Transitory