harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r538576 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/AbstractMap.java test/java/tests/api/java/util/AbstractMapTest.java
Date Wed, 16 May 2007 13:15:42 GMT
Author: pyang
Date: Wed May 16 06:15:42 2007
New Revision: 538576

URL: http://svn.apache.org/viewvc?view=rev&rev=538576
Log:
Apply new 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=538576&r1=538575&r2=538576
==============================================================================
--- 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
Wed May 16 06:15:42 2007
@@ -137,12 +137,15 @@
                 return false;
             }
 
-            Set<?> objectSet = map.entrySet();
             Iterator<Map.Entry<K, V>> it = entrySet().iterator();
 
             try {
                 while (it.hasNext()) {
-                    if (!objectSet.contains(it.next())) {
+                    Entry<K, V> entry = it.next();
+                    K key = entry.getKey();
+                    V value = entry.getValue();
+                    Object obj = map.get(key);
+                    if( null != obj && (!obj.equals(value)) || null == obj &&
obj != value) {
                         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=538576&r1=538575&r2=538576
==============================================================================
--- 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
Wed May 16 06:15:42 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