harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r433933 - 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 Wed, 23 Aug 2006 06:27:55 GMT
Author: pyang
Date: Tue Aug 22 23:27:54 2006
New Revision: 433933

URL: http://svn.apache.org/viewvc?rev=433933&view=rev
Log:
Patch applied for HARMONY-1249 ([classlib][luni] new method java.util.EnumSet.containsAll(Collection)
- overrides java.util.AbstractCollection.containsAll(Collection))

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java
    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
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/EnumSet.java?rev=433933&r1=433932&r2=433933&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
Tue Aug 22 23:27:54 2006
@@ -14,10 +14,12 @@
  */
 package java.util;
 
+import java.io.Serializable;
+
 import org.apache.harmony.luni.util.NotYetImplementedException;
 
 public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
-        implements Cloneable, java.io.Serializable {
+        implements Cloneable, Serializable {
     
     final Class<E> elementClass;
 

Modified: 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=433933&r1=433932&r2=433933&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/MiniEnumSet.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/MiniEnumSet.java
Tue Aug 22 23:27:54 2006
@@ -77,4 +77,16 @@
         int ordinal = element.ordinal();
         return (bits & (1l << ordinal)) != 0;
     }
+    
+    @Override
+    public boolean containsAll(Collection<?> collection) {
+        if (collection.size() == 0) {
+            return true;
+        }
+        if (collection instanceof MiniEnumSet) {
+            MiniEnumSet<E> set = (MiniEnumSet<E>) collection;
+            return isValidType(set.elementClass ) && ((bits & set.bits) == set.bits);
+        }
+        return !(collection instanceof EnumSet) && super.containsAll(collection);
 
+    }
 }

Modified: 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=433933&r1=433932&r2=433933&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EnumSetTest.java
Tue Aug 22 23:27:54 2006
@@ -15,6 +15,8 @@
 
 package tests.api.java.util;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.EnumSet;
 import java.util.Set;
 
@@ -35,6 +37,10 @@
     static enum EnumFoo {
         a, b,c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B,
C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, aa, bb, cc, dd, ee,
ff, gg, hh, ii, jj, kk, ll,
     }
+    
+    static enum EmptyEnum {
+        // expected
+    }
 
     /**
      * @tests java.util.EnumSet#noneOf(java.lang.Class)
@@ -195,5 +201,80 @@
         setWithSubclass.add(EnumWithInnerClass.f);
         result = setWithSubclass.contains(EnumWithInnerClass.f);
         assertTrue("Should contain EnumWithSubclass.f", result); //$NON-NLS-1$
+    }
+    
+    /**
+     * @tests java.util.EnumSet#containsAll(Collection)
+     */
+    @SuppressWarnings( { "unchecked", "boxing" })
+    public void test_containsAll_LCollection() {
+        EnumSet<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
+        Enum[] elements = EnumFoo.class.getEnumConstants();
+        for(int i = 0; i < elements.length; i++) {
+            set.add((EnumFoo)elements[i]);
+        }
+        try {
+            set.containsAll(null);
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        EnumSet<EmptyEnum> emptySet = EnumSet.noneOf(EmptyEnum.class);
+        elements = EmptyEnum.class.getEnumConstants();
+        for(int i = 0; i < elements.length; i++) {
+            emptySet.add((EmptyEnum)elements[i]);
+        }
+        boolean result = set.containsAll(emptySet);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+
+        Collection rawCollection = new ArrayList();
+        result = set.containsAll(rawCollection);
+        assertTrue("Should contain empty collection:", result); //$NON-NLS-1$
+
+        rawCollection.add(1);
+        result = set.containsAll(rawCollection);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        rawCollection.add(EnumWithInnerClass.a);
+        result = set.containsAll(rawCollection);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        EnumSet rawSet = EnumSet.noneOf(EnumFoo.class);
+        result = set.containsAll(rawSet);
+        assertTrue("Should contain empty set", result); //$NON-NLS-1$
+
+        emptySet = EnumSet.noneOf(EmptyEnum.class);
+        result = set.containsAll(emptySet);
+        assertTrue("No class cast should be performed on empty set", result); //$NON-NLS-1$
+
+        Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
+        collection.add(EnumFoo.a);
+        result = set.containsAll(collection);
+        assertTrue("Should contain all elements in collection", result); //$NON-NLS-1$
+
+        EnumSet<EnumFoo> fooSet = EnumSet.noneOf(EnumFoo.class);
+        fooSet.add(EnumFoo.a);
+        result = set.containsAll(fooSet);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+
+        set.clear();
+        try {
+            set.containsAll(null);
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        Collection<EnumWithInnerClass> collectionWithSubclass = new ArrayList<EnumWithInnerClass>();
+        collectionWithSubclass.add(EnumWithInnerClass.a);
+        result = set.containsAll(collectionWithSubclass);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        EnumSet<EnumWithInnerClass> setWithSubclass = EnumSet
+                .noneOf(EnumWithInnerClass.class);
+        setWithSubclass.add(EnumWithInnerClass.a);
+        result = set.containsAll(setWithSubclass);
+        assertFalse("Should return false", result); //$NON-NLS-1$
     }
 }



Mime
View raw message