You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2010/02/17 18:29:41 UTC

svn commit: r911099 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/util: UtilObject.java test/UtilObjectTests.java

Author: doogie
Date: Wed Feb 17 17:29:41 2010
New Revision: 911099

URL: http://svn.apache.org/viewvc?rev=911099&view=rev
Log:
Add support for arrays to doHashCode.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilObjectTests.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java?rev=911099&r1=911098&r2=911099&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java Wed Feb 17 17:29:41 2010
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.ofbiz.base.util;
 
+import java.lang.reflect.Array;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -179,6 +180,14 @@
 
     public static int doHashCode(Object o1) {
         if (o1 == null) return 0;
+        if (o1.getClass().isArray()) {
+            int length = Array.getLength(o1);
+            int result = 0;
+            for (int i = 0; i < length; i++) {
+                result += doHashCode(Array.get(o1, i));
+            }
+            return result;
+        }
         return o1.hashCode();
     }
 

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilObjectTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilObjectTests.java?rev=911099&r1=911098&r2=911099&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilObjectTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilObjectTests.java Wed Feb 17 17:29:41 2010
@@ -276,6 +276,9 @@
         UtilObject.doHashCode(this);
         UtilObject.doHashCode(null);
         UtilObject.doHashCode(0);
+        UtilObject.doHashCode(new Object[] { this, Object.class });
+        UtilObject.doHashCode(new Object[] { null, Object.class });
+        UtilObject.doHashCode(new int[] { 1, 3 });
     }
 
     public interface TestFactoryIntf extends Factory<Object, Set<String>> {