harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r434364 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/EnumMap.java test/java/tests/api/java/util/EnumMapTest.java
Date Thu, 24 Aug 2006 09:57:26 GMT
Author: pyang
Date: Thu Aug 24 02:57:25 2006
New Revision: 434364

URL: http://svn.apache.org/viewvc?rev=434364&view=rev
Log:
Patch applied for HARMONY-1264 ( [classlib][luni] new methods containsKey(Object) and containsValue(Object)
in java.util.EnumMap)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumMap.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumMapTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumMap.java?rev=434364&r1=434363&r2=434364&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumMap.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumMap.java
Thu Aug 24 02:57:25 2006
@@ -119,8 +119,13 @@
      *            the key whose presence in this map is to be tested
      * @return true if this map has a mapping for the given key.
      */
+    @Override
     public boolean containsKey(Object key) {
-        throw new NotYetImplementedException();
+        if (isValidKeyType(key)) {
+            int keyOrdinal = ((Enum) key).ordinal();
+            return hasMapping[keyOrdinal];
+        }
+        return false;
     }
 
     /**
@@ -130,8 +135,22 @@
      *            the value whose presence in this map is to be tested
      * @return true if this map has one or more keys mapped to the given value.
      */
+    @Override
     public boolean containsValue(Object value) {
-        throw new NotYetImplementedException();
+        if (null == value) {
+            for (int i = 0; i < enumSize; i++) {
+                if (hasMapping[i] && null == values[i]) {
+                    return true;
+                }
+            }
+        } else {
+            for (int i = 0; i < enumSize; i++) {
+                if (hasMapping[i] && value.equals(values[i])) {
+                    return true;
+                }
+            }
+        }
+        return false;
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumMapTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumMapTest.java?rev=434364&r1=434363&r2=434364&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumMapTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumMapTest.java
Thu Aug 24 02:57:25 2006
@@ -205,7 +205,60 @@
         enumSizeMap.clear();
         assertNull("Failed to clear all elements", enumSizeMap.get(Size.Small)); //$NON-NLS-1$
     }
-    
+
+    /**
+     * @tests java.util.EnumMap#containsKey(Object)
+     */
+    @SuppressWarnings( { "unchecked", "boxing" })
+    public void test_containsKeyLjava_lang_Object() {
+        EnumMap enumSizeMap = new EnumMap(Size.class);
+        assertFalse("Returned true for uncontained key", enumSizeMap //$NON-NLS-1$
+                .containsKey(Size.Small));
+        enumSizeMap.put(Size.Small, 1);
+        assertTrue("Returned false for contained key", enumSizeMap //$NON-NLS-1$
+                .containsKey(Size.Small));
+
+        enumSizeMap.put(Size.Big, null);
+        assertTrue("Returned false for contained key", enumSizeMap //$NON-NLS-1$
+                .containsKey(Size.Big));
+
+        assertFalse("Returned true for uncontained key", enumSizeMap //$NON-NLS-1$
+                .containsKey(Color.Red));
+        assertFalse("Returned true for uncontained key", enumSizeMap //$NON-NLS-1$
+                .containsKey(new Integer("3"))); //$NON-NLS-1$
+        assertFalse("Returned true for uncontained key", enumSizeMap //$NON-NLS-1$
+                .containsKey(null));
+    }
+
+    /**
+     * @tests java.util.EnumMap#containsValue(Object)
+     */
+    @SuppressWarnings( { "unchecked", "boxing" })
+    public void test_containsValueLjava_lang_Object() {
+        EnumMap enumSizeMap = new EnumMap(Size.class);
+        Double double1 = new Double(3);
+        Double double2 = new Double(3);
+
+        assertFalse("Returned true for uncontained value", enumSizeMap //$NON-NLS-1$
+                .containsValue(double1));
+        enumSizeMap.put(Size.Middle, 2);
+        enumSizeMap.put(Size.Small, double1);
+        assertTrue("Returned false for contained value", enumSizeMap //$NON-NLS-1$
+                .containsValue(double1));
+        assertTrue("Returned false for contained value", enumSizeMap //$NON-NLS-1$
+                .containsValue(double2));
+        assertTrue("Returned false for contained value", enumSizeMap //$NON-NLS-1$
+                .containsValue(2));
+        assertFalse("Returned true for uncontained value", enumSizeMap //$NON-NLS-1$
+                .containsValue(1));
+
+        assertFalse("Returned true for uncontained value", enumSizeMap //$NON-NLS-1$
+                .containsValue(null));
+        enumSizeMap.put(Size.Big, null);
+        assertTrue("Returned false for contained value", enumSizeMap //$NON-NLS-1$
+                .containsValue(null));
+    }
+
     /**
      * @tests java.util.EnumMap#get(Object)
      */



Mime
View raw message