harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r488425 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/HashMap.java test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java
Date Mon, 18 Dec 2006 21:26:46 GMT
Author: tellison
Date: Mon Dec 18 13:26:45 2006
New Revision: 488425

URL: http://svn.apache.org/viewvc?view=rev&rev=488425
Log:
Apply patch HARMONY-1492 ([classlib][luni] Constructor of HashMap throw unexpected exception)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java?view=diff&rev=488425&r1=488424&r2=488425
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java Mon
Dec 18 13:26:45 2006
@@ -269,7 +269,7 @@
      */
     public HashMap(Map<? extends K, ? extends V> map) {
         this(map.size() < 6 ? 11 : map.size() * 2);
-        super.putAll(map);
+        putAllImpl(map);
     }
 
     /**
@@ -512,6 +512,10 @@
      */
     @Override
     public V put(K key, V value) {
+        return putImpl(key, value);
+    }
+    
+    private V putImpl(K key, V value) {
         int index = getModuloHash(key);
         Entry<K,V> entry = findEntry(key, index);
 
@@ -551,11 +555,17 @@
     @Override
     public void putAll(Map<? extends K, ? extends V> map) {
         if (!map.isEmpty()) {
-            int capacity = elementCount + map.size();
-            if (capacity > threshold) {
-                rehash(capacity);
-            }
-            super.putAll(map);
+            putAllImpl(map);
+        }
+    }
+    
+    private void putAllImpl(Map<? extends K, ? extends V> map) {
+        int capacity = elementCount + map.size();
+        if (capacity > threshold) {
+            rehash(capacity);
+        }
+        for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
+            putImpl(entry.getKey(), entry.getValue());
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java?view=diff&rev=488425&r1=488424&r2=488425
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java
Mon Dec 18 13:26:45 2006
@@ -17,12 +17,34 @@
 package org.apache.harmony.luni.tests.java.util;
 
 import java.util.HashMap;
+import java.util.Map;
 
 import junit.framework.TestCase;
 
 import org.apache.harmony.testframework.serialization.SerializationTest;
 
 public class HashMapTest extends TestCase {
+    class SubMap<K, V> extends HashMap<K, V> {
+        public SubMap(Map<? extends K, ? extends V> m) {
+            super(m);
+        }
+
+        public V put(K key, V value) {
+            throw new UnsupportedOperationException();
+        }
+    }
+
+    /**
+     * @tests java.util.HashMap#HashMap(java.util.Map)
+     */
+    public void test_ConstructorLjava_util_Map() {
+        HashMap map = new HashMap();
+        map.put("a", "a");
+        SubMap map2 = new SubMap(map); 
+        assertTrue(map2.containsKey("a"));
+        assertTrue(map2.containsValue("a"));
+    }
+
     /**
      * @tests serialization/deserialization.
      */



Mime
View raw message