[
https://issues.apache.org/jira/browse/LANG-667?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12978693#action_12978693
]
Julien Aymé commented on LANG-667:
----------------------------------
Even is this method does break the contract of Comparable, it is really usefull
when comparing many fields of two comparable beans (which may be null):
{code}
public int compareTo(Bean other) {
int c = ObjectUtils.compare(this.getField1(), other.getField1());
if (c != 0) {
return c;
}
c = ObjectUtils.compare(this.getField2(), other.getField2());
if (c != 0) {
return c;
}
return ObjectUtils.compare(this.getField3(), other.getField3());
}
{code}
I don't want to be forced to handle null on field1, 2, or 3 for the 2 beans
(and that's why in my projects I already have this method added to ObjectUtils).
I propose that we add a javadoc comment stating that the method breaks the
Comparable contract.
> Add a Null-safe compare() method to ObjectUtils
> -----------------------------------------------
>
> Key: LANG-667
> URL: https://issues.apache.org/jira/browse/LANG-667
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.5
> Reporter: Niall Pemberton
> Assignee: Niall Pemberton
> Priority: Minor
> Fix For: 3.0
>
>
> Add a Null-safe compare() method to ObjectUtils
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.