harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r431847 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/EnumMap.java test/java/tests/api/java/util/EnumMapTest.java
Date Wed, 16 Aug 2006 06:55:42 GMT
Author: pyang
Date: Tue Aug 15 23:55:42 2006
New Revision: 431847

URL: http://svn.apache.org/viewvc?rev=431847&view=rev
Log:
Patch applied for HARMONY-1203 ([classlib][luni] new constructor of java.util.EnumMap - EnumMap(Class<K>))

Added:
    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

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=431847&r1=431846&r2=431847&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
Tue Aug 15 23:55:42 2006
@@ -19,10 +19,22 @@
 
 import org.apache.harmony.luni.util.NotYetImplementedException;
 
-public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
Map<K, V>,
-        Serializable, Cloneable {
+public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
+        Map<K, V>, Serializable, Cloneable {
     private static final long serialVersionUID = 458661240069192865L;
 
+    Class<K> keyType;
+
+    transient Enum keys[];
+
+    transient Object values[];
+
+    transient boolean hasMapping[];
+
+    transient int mappingsCount;
+
+    transient int enumSize;
+
     /**
      * Constructs an empty enum map using the given key type.
      * 
@@ -32,7 +44,7 @@
      *             if the keyType is null
      */
     public EnumMap(Class<K> keyType) {
-        throw new NotYetImplementedException();
+        initialization(keyType);
     }
 
     /**
@@ -216,6 +228,15 @@
      */
     public Collection<V> values() {
         throw new NotYetImplementedException();
+    }
+
+    @SuppressWarnings("unchecked")
+    private void initialization(Class<K> type) {
+        keyType = type;
+        keys = keyType.getEnumConstants();
+        enumSize = keys.length;
+        values = new Object[enumSize];
+        hasMapping = new boolean[enumSize];
     }
 
 }

Added: 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=431847&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumMapTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumMapTest.java
Tue Aug 15 23:55:42 2006
@@ -0,0 +1,86 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util;
+
+import java.util.EnumMap;
+
+import junit.framework.TestCase;
+
+public class EnumMapTest extends TestCase {
+    enum Size {
+        Small, Middle, Big {};
+    }
+
+    enum Color {
+        Red, Green, Blue {};
+    }
+
+    enum Empty {
+        //Empty
+    }
+
+    /**
+     * @tests java.util.EnumMap#EnumMap(Class)
+     */
+    @SuppressWarnings("unchecked")
+    public void test_ConstructorLjava_lang_Class() {
+        try {
+            new EnumMap((Class) null);
+            fail("Expected NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        
+        try {
+            new EnumMap(Size.Big.getClass());
+            fail("Expected NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        try {
+            new EnumMap(Integer.class);
+            fail("Expected NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        assertNotNull(new EnumMap<Color, Double>(Color.class));
+        
+        assertNotNull(new EnumMap<Empty, Double>(Empty.class));
+
+        assertNotNull(new EnumMap(Size.class));
+        
+        assertNotNull(new EnumMap(Size.Middle.getClass()));
+        
+    }
+
+    /**
+     * Sets up the fixture.
+     */
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    /**
+     * Tears down the fixture.
+     */
+    @Override
+    protected void tearDown() throws Exception{
+        super.tearDown();
+    }
+}



Mime
View raw message