Closed GoogleCodeExporter closed 9 years ago
Hi, James. To implement this method, of course, we need to decide whether
nulls are
less than all objects or greater than all objects. We'd probably end up with
Objects.compareNullGreatest() and Objects.compareNullLeast() to let the caller
choose. It also makes sense to go from a static compare() method to a
Comparator to
allow use as a Collection ordering, etc. In fact, in the Comparators class, we
have
nullGreatestOrder() and nullLeastOrder(). Calling
nullGreatestOrder().compare(c1,
c2) or nullLeastOrder().compare(c1, c2) should do what you want.
Original comment by cpov...@google.com
on 31 Oct 2008 at 2:34
Aha thats cool - sorry I'd missed those! Many thanks!
I wonder if its worth adding a couple of trivial static helper methods so its
easier for folks to find these helper
methods more easily? e.g. if I have 2 comparables I could just do
{{{
boolean Comparables.compareNullGreatest(c1, c2);
boolean Comparables.compareNullLeast(c1, c2);
}}}
Am used to finding the static methods by typing HelperClass.X (where X is the
first character of the method
(new/equals/compare etc) so it'd make it a tad easier for folks to find these
methods in IDEs.
Not a huge biggie though. I'd just never thought of searching for all methods
in Comparables. that starts with
"n" for null :)
Original comment by james.st...@gmail.com
on 31 Oct 2008 at 2:47
I don't think null-friendly comparison is done on the same on the order of
magnitude
as null-friendly equality and null-friendly hashing are, so I don't think this
warrants adding.
Original comment by kevin...@gmail.com
on 31 Oct 2008 at 4:29
I was looking for it some time ago.
Original comment by earwin@gmail.com
on 3 Nov 2008 at 9:57
Original comment by kevin...@gmail.com
on 29 Dec 2008 at 8:38
Original issue reported on code.google.com by
james.st...@gmail.com
on 31 Oct 2008 at 7:28