empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1393941 - /empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java
Date Thu, 04 Oct 2012 07:41:09 GMT
Author: doebele
Date: Thu Oct  4 07:41:08 2012
New Revision: 1393941

URL: http://svn.apache.org/viewvc?rev=1393941&view=rev
Log:
EMPIREDB-171
improved compareEqual() method using the Comparable interface.

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java?rev=1393941&r1=1393940&r2=1393941&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/ObjectUtils.java Thu
Oct  4 07:41:08 2012
@@ -97,6 +97,7 @@ public final class ObjectUtils
      * 
      * @return true if both objects are equal or false otherwise
      */
+    @SuppressWarnings("unchecked")
     public static boolean compareEqual(Object o1, Object o2)
     {
         // Check for Null Values
@@ -104,7 +105,12 @@ public final class ObjectUtils
             return (o1==o2);
         // Check classes
         if (o1.getClass().equals(o2.getClass()))
-            return o1.equals(o2);
+        {   // Check if object implements comparable
+            if (o1 instanceof Comparable)
+                return (((Comparable<Object>)o1).compareTo(o2)==0);
+            else
+                return o1.equals(o2);
+        }
         // Classes don't match
         // Use equal check first
         if (o1.equals(o2) || o2.equals(o1))



Mime
View raw message