harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r538071 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/AbstractMap.java test/java/tests/api/java/util/AbstractMapTest.java
Date Tue, 15 May 2007 07:09:10 GMT
Author: pyang
Date: Tue May 15 00:09:10 2007
New Revision: 538071

URL: http://svn.apache.org/viewvc?view=rev&rev=538071
Log:
Apply patch for HARMONY-3865([classlib][luni] AbstractMap seems to have a flawed equals method)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractMapTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java?view=diff&rev=538071&r1=538070&r2=538071
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java
Tue May 15 00:09:10 2007
@@ -142,9 +142,14 @@
 
             try {
                 while (it.hasNext()) {
-                    if (!objectSet.contains(it.next())) {
-                        return false;
+                    Entry<K, V> entry = it.next();
+                    K key = entry.getKey();
+                    V value = entry.getValue();
+                    Object obj = map.get(key);
+                    if( null != obj ) {
+                            return obj.equals(value);
                     }
+                    return ( obj == value );
                 }
             } catch (ClassCastException cce) {
                 return false;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractMapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractMapTest.java?view=diff&rev=538071&r1=538070&r2=538071
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractMapTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractMapTest.java
Tue May 15 00:09:10 2007
@@ -18,15 +18,19 @@
 package tests.api.java.util;
 
 import java.util.AbstractMap;
+import java.util.AbstractSet;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.IdentityHashMap;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.Vector;
 import java.util.WeakHashMap;
 
 public class AbstractMapTest extends junit.framework.TestCase {
@@ -191,6 +195,77 @@
 		MyMap mapClone = (MyMap) map.clone();
 		assertTrue("clone not shallow", map.getMap() == mapClone.getMap());
 	}
+    
+    public class AMT extends AbstractMap {
+
+        // Very crude AbstractMap implementation
+        Vector values = new Vector();
+
+        Vector keys = new Vector();
+
+        public Set entrySet() {
+            return new AbstractSet() {
+                public Iterator iterator() {
+                    return new Iterator() {
+                        int index = 0;
+
+                        public boolean hasNext() {
+                            return index < values.size();
+                        }
+
+                        public Object next() {
+                            if (index < values.size()) {
+                                Map.Entry me = new Map.Entry() {
+                                    Object v = values.elementAt(index);
+
+                                    Object k = keys.elementAt(index);
+
+                                    public Object getKey() {
+                                        return k;
+                                    }
+
+                                    public Object getValue() {
+                                        return v;
+                                    }
+
+                                    public Object setValue(Object value) {
+                                        return null;
+                                    }
+                                };
+                                index++;
+                                return me;
+                            }
+                            return null;
+                        }
+
+                        public void remove() {
+                        }
+                    };
+                }
+
+                public int size() {
+                    return values.size();
+                }
+            };
+        }
+
+        public Object put(Object k, Object v) {
+            keys.add(k);
+            values.add(v);
+            return v;
+        }
+    }
+    
+    /**
+     * @tests {@link java.util.AbstractMap#putAll(Map)}
+     */
+    public void test_putAllLMap() {
+        Hashtable ht = new Hashtable();
+        AMT amt = new AMT();
+        ht.put("this", "that");
+        amt.putAll(ht);
+        assertEquals("Should be equal", amt, ht);
+    }
 
 	protected void setUp() {
 	}



Mime
View raw message