I have a ComplexObject with multiple fields and I want to say this:
x
exists on both, move on to the next compare
in the comparison chain.compare
in the comparison chain. I'm not sure how to do this, because as far as I can tell
.compare(c1.getX(), c2.getX(), Ordering.arbitrary().nullsLast())
will
Is there a way I can use Guava's ComparisonChain
or Ordering
class to achieve what I want? Or is there a better way to think about solving this problem?
Given your answer to my comment, just do a boolean comparison.
.compare(c1.getX() == null, c2.getX() == null)
And given your revised reply, if your class has a method
public XType getX() {...}
then consider making XType
implement Comparable<XType>
or providing a Comparator<XType>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With