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:
parent
11a6dd26e3
commit
b92907c109
|
@ -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);
|
||||
if (c1 == c2) {
|
||||
return 0;
|
||||
} else if (c1 == null) {
|
||||
return (nullGreater ? 1 : -1);
|
||||
} else if (c2 == null) {
|
||||
return (nullGreater ? -1 : 1);
|
||||
}
|
||||
} else {
|
||||
result = c1.compareTo(c2);
|
||||
}
|
||||
return result;
|
||||
return c1.compareTo(c2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue