[
https://issues.apache.org/jira/browse/LANG-667?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12978701#action_12978701
]
Julien Aymé commented on LANG-667:
----------------------------------
Regarding the code, I think it would be faster and simpler to understand if we
add a "==" test first:
{code}
public static <T extends Comparable<? super T>> int compare(T c1, T c2, boolean
nullGreater) {
if (c1 == c2) {
return 0;
} else if (c1 == null) {
return nullGreater ? 1 : -1;
} else if (c2 == null) {
return nullGreater ? -1 : 1;
}
return c1.compareTo(c2);
}
{code}
Note: the commited code in rev 1056124 was:
{code}
public static <T extends Comparable<? super T>> int compare(T c1, T c2, boolean
nullGreater) {
int result = 0;
if ((c1 == null) || (c2 == null)) {
if (nullGreater) {
result = (c1 == null ? 1 : 0) - (c2 == null ? 1 : 0);
} else {
result = (c1 == null ? -1 : 0) - (c2 == null ? -1 : 0);
}
} else {
result = c1.compareTo(c2);
}
return result;
}
{code}
> 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.