[jboss-svn-commits] JBL Code SVN: r7719 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/util test/java/org/drools/util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Nov 20 07:19:48 EST 2006


Author: tirelli
Date: 2006-11-20 07:19:42 -0500 (Mon, 20 Nov 2006)
New Revision: 7719

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/ObjectHashMapTest.java
Log:
Fixing ObjectEntry.hashCode() method

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java	2006-11-20 11:34:39 UTC (rev 7718)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java	2006-11-20 12:19:42 UTC (rev 7719)
@@ -112,6 +112,9 @@
     public static class ObjectEntry
         implements
         Entry {
+
+        private static final long serialVersionUID = -2589987113898296555L;
+
         private Object key;
 
         private Object value;
@@ -145,7 +148,7 @@
         }
 
         public int hashCode() {
-            return this.key.hashCode() ^ this.value.hashCode();
+            return this.hashCode;
         }
 
         public boolean equals(final Object object) {

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/ObjectHashMapTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/ObjectHashMapTest.java	2006-11-20 11:34:39 UTC (rev 7718)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/ObjectHashMapTest.java	2006-11-20 12:19:42 UTC (rev 7719)
@@ -9,7 +9,7 @@
     public void testChechExistsFalse() {
         final ObjectHashMap map = new ObjectHashMap();
         final Cheese stilton = new Cheese( "stilton",
-                                     5 );
+                                           5 );
         map.put( new Integer( 1 ),
                  stilton,
                  false );
@@ -21,9 +21,9 @@
         // we haven't told the map to check if the key exists, so we should end up with two entries.
         // the second one is nolonger reacheable
         final Cheese cheddar = new Cheese( "cheddar",
-                                     5 );
+                                           5 );
         map.put( new Integer( 1 ),
-                 cheddar, 
+                 cheddar,
                  false );
         c = (Cheese) map.get( new Integer( 1 ) );
         assertSame( cheddar,
@@ -55,7 +55,7 @@
     public void testChechExistsTrue() {
         final ObjectHashMap map = new ObjectHashMap();
         final Cheese stilton = new Cheese( "stilton",
-                                     5 );
+                                           5 );
         map.put( new Integer( 1 ),
                  stilton,
                  true );
@@ -67,7 +67,7 @@
         // we haven't told the map to check if the key exists, so we should end up with two entries.
         // the second one is nolonger reacheable
         final Cheese cheddar = new Cheese( "cheddar",
-                                     5 );
+                                           5 );
         map.put( new Integer( 1 ),
                  cheddar );
         c = (Cheese) map.get( new Integer( 1 ) );
@@ -104,4 +104,32 @@
             fail( "Map is empty, there should be no iteration" );
         }
     }
+
+    public void testStringData() {
+        ObjectHashMap map = new ObjectHashMap();
+        assertNotNull( map );
+        int count = 1000;
+        for ( int idx = 0; idx < count; idx++ ) {
+            String key = "key" + idx;
+            String val = "value" + idx;
+            map.put( key,
+                     val );
+            assertEquals( val,
+                          map.get( key ) );
+        }
+    }
+
+    public void testIntegerData() {
+        ObjectHashMap map = new ObjectHashMap();
+        assertNotNull( map );
+        int count = 1000;
+        for ( int idx = 0; idx < count; idx++ ) {
+            Integer key = new Integer( idx );
+            Integer val = new Integer( idx );
+            map.put( key,
+                     val );
+            assertEquals( val,
+                          map.get( key ) );
+        }
+    }
 }




More information about the jboss-svn-commits mailing list