commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1056520 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java
Date Fri, 07 Jan 2011 21:24:12 GMT
Author: niallp
Date: Fri Jan  7 21:24:12 2011
New Revision: 1056520

URL: http://svn.apache.org/viewvc?rev=1056520&view=rev
Log:
LANG-667 Simplify compare() method - thanks to Julien Aymé

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java?rev=1056520&r1=1056519&r2=1056520&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java Fri
Jan  7 21:24:12 2011
@@ -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);
     }
     
     /**



Mime
View raw message