harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r433503 - 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 Tue, 22 Aug 2006 04:26:18 GMT
Author: pyang
Date: Mon Aug 21 21:26:17 2006
New Revision: 433503

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

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=433503&r1=433502&r2=433503&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
Mon Aug 21 21:26:17 2006
@@ -39,7 +39,7 @@
         if (!elementType.isEnum()) {
             throw new ClassCastException();
         }
-        if (elementType.getEnumConstants().length < 64) {
+        if (elementType.getEnumConstants().length <= 64) {
             return new MiniEnumSet<E>(elementType);
         }
         throw new NotYetImplementedException();

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=433503&r1=433502&r2=433503&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
Mon Aug 21 21:26:17 2006
@@ -54,7 +54,7 @@
         if (!isValidType(element.getDeclaringClass())) {
             throw new ClassCastException();
         }
-        int mask = 1 << element.ordinal();
+        long mask = 1l << element.ordinal();
         if ((bits & mask) == mask) {
             return false;
         }
@@ -62,5 +62,19 @@
 
         size = Long.bitCount(bits);
         return true;
+    }
+    
+    @Override
+    @SuppressWarnings("unchecked")
+    public boolean contains(Object object) {
+        if (null == object) {
+            return false;
+        }
+        if (!isValidType(object.getClass())) {
+            return false;
+        }
+        E element = (E) object;
+        int ordinal = element.ordinal();
+        return (bits & (1l << ordinal)) != 0;
     }
 }

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=433503&r1=433502&r2=433503&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
Mon Aug 21 21:26:17 2006
@@ -33,7 +33,7 @@
     }
     
     static enum EnumFoo {
-        a, b,
+        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,
     }
 
     /**
@@ -149,5 +149,51 @@
         set.add(EnumFoo.a);
         set.add(EnumFoo.b);
         assertEquals("Size should be 2", 2, set.size()); //$NON-NLS-1$
+    }
+    
+    /**
+     * @tests java.util.EnumSet#contains(Object)
+     */
+    public void test_contains_LObject() {
+        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
+        Enum[] elements = EnumFoo.class.getEnumConstants();
+        for(int i = 0; i < elements.length; i++) {
+            set.add((EnumFoo)elements[i]);
+        }
+        boolean result = set.contains(null);
+        assertFalse("Should not contain null:", result); //$NON-NLS-1$
+
+        result = set.contains(EnumFoo.a);
+        assertTrue("Should contain EnumFoo.a", result); //$NON-NLS-1$
+        result = set.contains(EnumFoo.ll);
+        assertTrue("Should contain EnumFoo.ll", result); //$NON-NLS-1$
+
+        result = set.contains(EnumFoo.b);
+        assertTrue("Should contain EnumFoo.b", result); //$NON-NLS-1$
+
+        result = set.contains(new Object());
+        assertFalse("Should not contain Object instance", result); //$NON-NLS-1$
+
+        result = set.contains(EnumWithInnerClass.a);
+        assertFalse("Should not contain EnumWithSubclass.a", result); //$NON-NLS-1$
+        
+        set = EnumSet.noneOf(EnumFoo.class);
+        set.add(EnumFoo.aa);
+        set.add(EnumFoo.bb);
+        set.add(EnumFoo.cc);
+        
+        assertEquals("Size of set should be 3", 3, set.size()); //$NON-NLS-1$
+        assertTrue("set should contain EnumFoo.aa", set.contains(EnumFoo.aa)); //$NON-NLS-1$
+
+        Set<EnumWithInnerClass> setWithSubclass = EnumSet
+                .noneOf(EnumWithInnerClass.class);
+        setWithSubclass.add(EnumWithInnerClass.a);
+        setWithSubclass.add(EnumWithInnerClass.b);
+        setWithSubclass.add(EnumWithInnerClass.c);
+        setWithSubclass.add(EnumWithInnerClass.d);
+        setWithSubclass.add(EnumWithInnerClass.e);
+        setWithSubclass.add(EnumWithInnerClass.f);
+        result = setWithSubclass.contains(EnumWithInnerClass.f);
+        assertTrue("Should contain EnumWithSubclass.f", result); //$NON-NLS-1$
     }
 }



Mime
View raw message