LANG-667 Simplify compare() method - thanks to Julien Aymé

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1056520 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Niall Pemberton 2011-01-07 21:24:12 +00:00
parent 11a6dd26e3
commit b92907c109
1 changed files with 7 additions and 10 deletions

View File

@ -348,17 +348,14 @@ public class ObjectUtils {
* @see java.util.Comparator#compare(Object, Object)
*/
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);
if (c1 == c2) {
return 0;
} else if (c1 == null) {
return (nullGreater ? 1 : -1);
} else if (c2 == null) {
return (nullGreater ? -1 : 1);
}
return result;
return c1.compareTo(c2);
}
/**