harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r432183 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/EnumSet.java main/java/java/util/MiniEnumSet.java test/java/tests/api/java/util/EnumSetTest.java
Date Thu, 17 Aug 2006 08:50:50 GMT
Author: pyang
Date: Thu Aug 17 01:50:49 2006
New Revision: 432183

URL: http://svn.apache.org/viewvc?rev=432183&view=rev
Log:
Patch applied for HARMONY-1211([classlib][luni] new method noneOf(Class<E>) in java.util.EnumSet)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/MiniEnumSet.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java?rev=432183&r1=432182&r2=432183&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java
Thu Aug 17 01:50:49 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
+/* 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.
@@ -18,6 +18,12 @@
 
 public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
         implements Cloneable, java.io.Serializable {
+    
+    final Class<E> elementClass;
+
+    EnumSet(Class<E> cls) {
+        elementClass = cls;
+    }
 
     /**
      * Creates an empty enum set. The permitted elements are of type Class<E>.
@@ -30,6 +36,12 @@
      *             if the specified elementType is null
      */
     public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E>
elementType) {
+        if (!elementType.isEnum()) {
+            throw new ClassCastException();
+        }
+        if (elementType.getEnumConstants().length < 64) {
+            return new MiniEnumSet<E>(elementType);
+        }
         throw new NotYetImplementedException();
     }
 

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/MiniEnumSet.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/MiniEnumSet.java?rev=432183&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/MiniEnumSet.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/MiniEnumSet.java
Thu Aug 17 01:50:49 2006
@@ -0,0 +1,40 @@
+/* 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 java.util;
+
+import org.apache.harmony.luni.util.NotYetImplementedException;
+
+/**
+ * This is a concrete subclass of EnumSet designed specifically for enum type
+ * with less than or equal to 64 elements.
+ * 
+ */
+final class MiniEnumSet<E extends Enum<E>> extends EnumSet<E> {
+    
+    MiniEnumSet(Class<E> elementType) {
+        super(elementType);
+    }
+
+    @Override
+    public Iterator<E> iterator() {
+        throw new NotYetImplementedException();
+    }
+
+    @Override
+    public int size() {
+        throw new NotYetImplementedException();
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java?rev=432183&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java
Thu Aug 17 01:50:49 2006
@@ -0,0 +1,61 @@
+/* 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.EnumSet;
+
+import junit.framework.TestCase;
+
+public class EnumSetTest extends TestCase {
+
+    enum EnumWithAllInnerClass {
+        a {},
+        b {},
+    }
+
+    /**
+     * @tests java.util.EnumSet#noneOf(java.lang.Class)
+     */
+    @SuppressWarnings("unchecked")
+    public void test_NoneOf_LClass() {
+        try {
+            EnumSet.noneOf((Class) null);
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            EnumSet.noneOf(Enum.class);
+            fail("Should throw ClassCastException"); //$NON-NLS-1$
+        } catch (ClassCastException cce) {
+            // expected
+        }
+
+        Class<EnumWithAllInnerClass> c = (Class<EnumWithAllInnerClass>) EnumWithAllInnerClass.a
+                .getClass();
+        try {
+            EnumSet.noneOf(c);
+            fail("Should throw ClassCastException"); //$NON-NLS-1$
+        } catch (ClassCastException e) {
+            // expected
+        }
+
+        EnumSet<EnumWithAllInnerClass> setWithInnerClass = EnumSet
+                .noneOf(EnumWithAllInnerClass.class);
+        assertNotNull(setWithInnerClass);
+    }
+}



Mime
View raw message