_Original issue created by philip.zeyliger on 2011-02-21 at 11:04 PM_
Currently ComparisonChain.start().compare(null, null) will throw a NPE. This is reasonable, of course, but sometimes it's useful to compare objects that have some of their fields unset, with null appearing at the beginning or the end.
How do people feel about supporting a compareNullableNullFirst() that does something reasonable along these lines? (Compare Objects.equals(), which is useful for handling equality with the possibility of null.)
_Original comment posted by philip.zeyliger on 2011-02-21 at 11:06 PM_
Note that https://github.com/google/guava/issues/500 is similar, but it's about documentation. I propose adding a method here; not amending the documentation.
_Original comment posted by cgdecker on 2011-02-22 at 02:30 AM_
You can already compare Comparable values that may be null like this:
compare(a, b, Ordering.natural().nullsFirst())
This approach is flexible and the example from the class documentation uses it. I'm guessing this won't be changed.
Status: WorkingAsIntended
_Original comment posted by kevinb9n on 2011-02-22 at 05:14 AM_
Yup. We'd have no idea how to compare (null, nonnull).
_Original comment posted by philip.zeyliger on 2011-02-22 at 06:16 AM_
Thanks! Ordering.natural().nullsFirst() will do the trick.
Most helpful comment
_Original comment posted by cgdecker on 2011-02-22 at 02:30 AM_
You can already compare Comparable values that may be null like this:
This approach is flexible and the example from the class documentation uses it. I'm guessing this won't be changed.
Status:
WorkingAsIntended