harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r438017 - 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, 29 Aug 2006 08:53:16 GMT
Author: pyang
Date: Tue Aug 29 01:53:16 2006
New Revision: 438017

URL: http://svn.apache.org/viewvc?rev=438017&view=rev
Log:
Patch applied for HARMONY-1288 ([classlib][luni] new methods java.util.EnumSet.removeAll(Collection<?>),
retainAll(Collection<?>), allOf(), iterator())

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=438017&r1=438016&r2=438017&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 29 01:53:16 2006
@@ -58,7 +58,9 @@
      *             if the specified elementType is null
      */
     public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType)
{
-        throw new NotYetImplementedException();
+        EnumSet<E> set = noneOf(elementType);
+        set.complement();
+        return set;
     }
 
     /**

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=438017&r1=438016&r2=438017&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 29 01:53:16 2006
@@ -15,7 +15,6 @@
 
 package java.util;
 
-import org.apache.harmony.luni.util.NotYetImplementedException;
 
 /**
  * This is a concrete subclass of EnumSet designed specifically for enum type
@@ -37,10 +36,54 @@
         super(elementType);
         enums = elementType.getEnumConstants();
     }
+    
+    private class MiniEnumSetIterator implements Iterator<E> {
+
+        private long unProcessedBits = 0;
+
+        /*
+         * Mask for current element.
+         */
+        private long currentElementMask = 0;
+
+        private boolean canProcess = true;
+
+        private MiniEnumSetIterator() {
+            unProcessedBits = bits;
+            if (0 == unProcessedBits) {
+                canProcess = false;
+            }
+        }
+
+        public boolean hasNext() {
+            return canProcess;
+        }
+
+        public E next() {
+            if (!canProcess) {
+                throw new NoSuchElementException();
+            }
+            currentElementMask = unProcessedBits & (-unProcessedBits);
+            unProcessedBits -= currentElementMask;
+            if (0 == unProcessedBits) {
+                canProcess = false;
+            }
+            return enums[Long.numberOfTrailingZeros(currentElementMask)];
+        }
+
+        public void remove() {
+            if ( currentElementMask == 0 ) {
+                throw new IllegalStateException();
+            }
+            bits &= ~currentElementMask;
+            size = Long.bitCount(bits);
+            currentElementMask = 0;
+        }
+    }
 
     @Override
     public Iterator<E> iterator() {
-        throw new NotYetImplementedException();
+        return new MiniEnumSetIterator();
     }
 
     @Override
@@ -75,11 +118,11 @@
             return false;
         }
         if (collection instanceof EnumSet) {
-            EnumSet<E> set = (EnumSet<E>) collection;
+            EnumSet set = (EnumSet) collection;
             if (!isValidType(set.elementClass)) {
                 throw new ClassCastException();
             }
-            MiniEnumSet<E> miniSet = (MiniEnumSet<E>) set;
+            MiniEnumSet miniSet = (MiniEnumSet) set;
             long oldBits = bits;
             bits |= miniSet.bits;
             size = Long.bitCount(bits);
@@ -89,7 +132,6 @@
     }
     
     @Override
-    @SuppressWarnings("unchecked")
     public boolean contains(Object object) {
         if (null == object) {
             return false;
@@ -97,7 +139,7 @@
         if (!isValidType(object.getClass())) {
             return false;
         }
-        E element = (E) object;
+        Enum element = (Enum) object;
         int ordinal = element.ordinal();
         return (bits & (1l << ordinal)) != 0;
     }
@@ -108,19 +150,59 @@
             return true;
         }
         if (collection instanceof MiniEnumSet) {
-            MiniEnumSet<E> set = (MiniEnumSet<E>) collection;
+            MiniEnumSet set = (MiniEnumSet) collection;
             return isValidType(set.elementClass ) && ((bits & set.bits) == set.bits);
         }
         return !(collection instanceof EnumSet) && super.containsAll(collection);
 
     }
     
     @Override
-    @SuppressWarnings("unchecked")
+    public boolean removeAll(Collection<?> collection) {
+        if (0 == collection.size()) {
+            return false;
+        }
+        if (collection instanceof EnumSet) {
+            EnumSet<E> set = (EnumSet<E>) collection;
+            boolean removeSuccessful = false;
+            if (isValidType(set.elementClass)) {
+                long mask = bits & ((MiniEnumSet<E>) set).bits;
+                if (mask != 0) {
+                    bits -= mask;
+                    size = Long.bitCount(bits);
+                    removeSuccessful = true;
+                }
+            }
+            return removeSuccessful;
+        }
+        return super.removeAll(collection);
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> collection) {
+        if (collection instanceof EnumSet) {
+            EnumSet<E> set = (EnumSet<E>) collection;
+            if (!isValidType(set.elementClass)) {
+                clear();
+                return true;
+            }
+            boolean retainSuccessful = false;
+            long oldBits = bits;
+            bits &= ((MiniEnumSet<E>)set).bits;
+            if (oldBits != bits) {
+                size = Long.bitCount(bits);
+                retainSuccessful = true;
+            }
+            return retainSuccessful;
+        }
+        return super.retainAll(collection);
+    }
+    
+    @Override
     public boolean remove(Object object) {
         if (!contains(object)) {
             return false;
         }
-        E element = (E) object;
+        Enum element = (Enum) object;
         int ordinal = element.ordinal();
         bits -= (1l << ordinal);
         size--;
@@ -128,7 +210,6 @@
     }
     
     @Override
-    @SuppressWarnings("unchecked")
     public boolean equals(Object object) {
         if (!(object instanceof EnumSet)) {
             return super.equals(object);

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=438017&r1=438016&r2=438017&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 29 01:53:16 2006
@@ -18,6 +18,8 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
 import java.util.Set;
 
 import junit.framework.TestCase;
@@ -76,6 +78,44 @@
     }
     
     /**
+     * @tests java.util.EnumSet#allOf(java.lang.Class)
+     */
+    @SuppressWarnings("unchecked")
+    public void test_AllOf_LClass() {
+        try {
+            EnumSet.allOf((Class) null);
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            EnumSet.allOf(Enum.class);
+            fail("Should throw ClassCastException"); //$NON-NLS-1$
+        } catch (ClassCastException cce) {
+            // expected
+        }
+
+        EnumSet<EnumFoo> enumSet = EnumSet.allOf(EnumFoo.class);
+        assertEquals("Size of enumSet should be 64", 64, enumSet.size()); //$NON-NLS-1$
+
+        assertFalse(
+                "enumSet should not contain null value", enumSet.contains(null)); //$NON-NLS-1$
+        assertTrue(
+                "enumSet should contain EnumFoo.a", enumSet.contains(EnumFoo.a)); //$NON-NLS-1$
+        assertTrue(
+                "enumSet should contain EnumFoo.b", enumSet.contains(EnumFoo.b)); //$NON-NLS-1$
+
+        enumSet.add(EnumFoo.a);
+        assertEquals("Should be equal", 64, enumSet.size()); //$NON-NLS-1$
+
+        EnumSet<EnumFoo> anotherSet = EnumSet.allOf(EnumFoo.class);
+        assertEquals("Should be equal", enumSet, anotherSet); //$NON-NLS-1$
+        assertNotSame("Should not be identical", enumSet, anotherSet); //$NON-NLS-1$
+
+    }
+    
+    /**
      * @tests java.util.EnumSet#add(E)
      */
     @SuppressWarnings("unchecked")
@@ -463,5 +503,331 @@
         setWithSubclass.add(EnumWithInnerClass.a);
         result = set.containsAll(setWithSubclass);
         assertFalse("Should return false", result); //$NON-NLS-1$
+    }
+    
+    /**
+     * @tests java.util.EnumSet#removeAll(Collection)
+     */
+    @SuppressWarnings("unchecked")
+    public void test_removeAll_LCollection() {
+        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
+        try {
+            set.removeAll(null);
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        set = EnumSet.allOf(EnumFoo.class);
+        assertEquals("Size of set should be 64:", 64, set.size()); //$NON-NLS-1$
+
+        try {
+            set.removeAll(null);
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
+        collection.add(EnumFoo.a);
+
+        boolean result = set.removeAll(collection);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+        assertEquals("Size of set should be 63", 63, set.size()); //$NON-NLS-1$
+
+        collection = new ArrayList();
+        result = set.removeAll(collection);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        Set<EmptyEnum> emptySet = EnumSet.noneOf(EmptyEnum.class);
+        result = set.removeAll(emptySet);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        EnumSet<EnumFoo> emptyFooSet = EnumSet.noneOf(EnumFoo.class);
+        result = set.removeAll(emptyFooSet);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        emptyFooSet.add(EnumFoo.a);
+        result = set.removeAll(emptyFooSet);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        Set<EnumWithInnerClass> setWithSubclass = EnumSet
+                .noneOf(EnumWithInnerClass.class);
+        result = set.removeAll(setWithSubclass);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        setWithSubclass.add(EnumWithInnerClass.a);
+        result = set.removeAll(setWithSubclass);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        Set<EnumFoo> anotherSet = EnumSet.noneOf(EnumFoo.class);
+        anotherSet.add(EnumFoo.a);
+
+        set = EnumSet.allOf(EnumFoo.class);
+        result = set.removeAll(anotherSet);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+        assertEquals("Size of set should be 63:", 63, set.size()); //$NON-NLS-1$
+
+        Set<EnumWithInnerClass> setWithInnerClass = EnumSet
+                .noneOf(EnumWithInnerClass.class);
+        setWithInnerClass.add(EnumWithInnerClass.a);
+        setWithInnerClass.add(EnumWithInnerClass.b);
+
+        Set<EnumWithInnerClass> anotherSetWithInnerClass = EnumSet
+                .noneOf(EnumWithInnerClass.class);
+        anotherSetWithInnerClass.add(EnumWithInnerClass.c);
+        anotherSetWithInnerClass.add(EnumWithInnerClass.d);
+        result = anotherSetWithInnerClass.removeAll(setWithInnerClass);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        anotherSetWithInnerClass.add(EnumWithInnerClass.a);
+        result = anotherSetWithInnerClass.removeAll(setWithInnerClass);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+        assertEquals("Size of anotherSetWithInnerClass should remain 2", //$NON-NLS-1$
+                2, anotherSetWithInnerClass.size());
+
+        anotherSetWithInnerClass.remove(EnumWithInnerClass.c);
+        anotherSetWithInnerClass.remove(EnumWithInnerClass.d);
+        result = anotherSetWithInnerClass.remove(setWithInnerClass);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        Set rawSet = EnumSet.allOf(EnumWithAllInnerClass.class);
+        result = rawSet.removeAll(EnumSet.allOf(EnumFoo.class));
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        setWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
+        anotherSetWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
+        setWithInnerClass.remove(EnumWithInnerClass.a);
+        anotherSetWithInnerClass.remove(EnumWithInnerClass.f);
+        result = setWithInnerClass.removeAll(anotherSetWithInnerClass);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+        assertEquals("Size of setWithInnerClass should be 1", 1, setWithInnerClass.size());
//$NON-NLS-1$
+
+        result = setWithInnerClass.contains(EnumWithInnerClass.f);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+    }
+    
+    /**
+     * @tests java.util.EnumSet#retainAll(Collection)
+     */
+    @SuppressWarnings("unchecked")
+    public void test_retainAll_LCollection() {
+        Set<EnumFoo> set = EnumSet.allOf(EnumFoo.class);
+
+        try {
+            set.retainAll(null);
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        set.clear();
+        boolean result = set.retainAll(null);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        Collection rawCollection = new ArrayList();
+        result = set.retainAll(rawCollection);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        rawCollection.add(EnumFoo.a);
+        result = set.retainAll(rawCollection);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        rawCollection.add(EnumWithInnerClass.a);
+        result = set.retainAll(rawCollection);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+        assertEquals("Size of set should be 0:", 0, set.size()); //$NON-NLS-1$
+
+        rawCollection.remove(EnumFoo.a);
+        result = set.retainAll(rawCollection);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        Set<EnumFoo> anotherSet = EnumSet.allOf(EnumFoo.class);
+        result = set.retainAll(anotherSet);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
+
+        Set<EnumWithInnerClass> setWithInnerClass = EnumSet
+                .allOf(EnumWithInnerClass.class);
+        result = set.retainAll(setWithInnerClass);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
+
+        setWithInnerClass = EnumSet.noneOf(EnumWithInnerClass.class);
+        result = set.retainAll(setWithInnerClass);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+
+        Set<EmptyEnum> emptySet = EnumSet.allOf(EmptyEnum.class);
+        result = set.retainAll(emptySet);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+
+        Set<EnumWithAllInnerClass> setWithAllInnerClass = EnumSet
+                .allOf(EnumWithAllInnerClass.class);
+        result = set.retainAll(setWithAllInnerClass);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+
+        set.add(EnumFoo.a);
+        result = set.retainAll(setWithInnerClass);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
+
+        setWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
+        setWithInnerClass.remove(EnumWithInnerClass.f);
+        Set<EnumWithInnerClass> anotherSetWithInnerClass = EnumSet
+                .noneOf(EnumWithInnerClass.class);
+        anotherSetWithInnerClass.add(EnumWithInnerClass.e);
+        anotherSetWithInnerClass.add(EnumWithInnerClass.f);
+
+        result = setWithInnerClass.retainAll(anotherSetWithInnerClass);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+        result = setWithInnerClass.contains(EnumWithInnerClass.e);
+        assertTrue("Should contain EnumWithInnerClass.e", result); //$NON-NLS-1$
+        result = setWithInnerClass.contains(EnumWithInnerClass.b);
+        assertFalse("Should not contain EnumWithInnerClass.b", result); //$NON-NLS-1$
+        assertEquals("Size of set should be 1:", 1, setWithInnerClass.size()); //$NON-NLS-1$
+
+        anotherSetWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
+        result = setWithInnerClass.retainAll(anotherSetWithInnerClass);
+
+        assertFalse("Return value should be false", result); //$NON-NLS-1$
+
+        rawCollection = new ArrayList();
+        rawCollection.add(EnumWithInnerClass.e);
+        rawCollection.add(EnumWithInnerClass.f);
+        result = setWithInnerClass.retainAll(rawCollection);
+        assertFalse("Should return false", result); //$NON-NLS-1$
+
+        set = EnumSet.allOf(EnumFoo.class);
+        set.remove(EnumFoo.a);
+        anotherSet = EnumSet.noneOf(EnumFoo.class);
+        anotherSet.add(EnumFoo.a);
+        result = set.retainAll(anotherSet);
+        assertTrue("Should return true", result); //$NON-NLS-1$
+        assertEquals("size should be 0", 0, set.size()); //$NON-NLS-1$
+    }
+    
+    /**
+     * @tests java.util.EnumSet#iterator()
+     */
+    public void test_iterator() {
+        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
+        set.add(EnumFoo.a);
+        set.add(EnumFoo.b);
+
+        Iterator<EnumFoo> iterator = set.iterator();
+        Iterator<EnumFoo> anotherIterator = set.iterator();
+        assertNotSame(iterator, anotherIterator);
+        try {
+            iterator.remove();
+            fail("Should throw IllegalStateException"); //$NON-NLS-1$
+        } catch (IllegalStateException e) {
+            // expectedd
+        }
+
+        assertTrue("Should has next element:", iterator.hasNext()); //$NON-NLS-1$
+        assertSame("Should be identical", EnumFoo.a, iterator.next()); //$NON-NLS-1$
+        iterator.remove();
+        assertTrue("Should has next element:", iterator.hasNext()); //$NON-NLS-1$
+        assertSame("Should be identical", EnumFoo.b, iterator.next()); //$NON-NLS-1$
+        assertFalse("Should not has next element:", iterator.hasNext()); //$NON-NLS-1$
+        assertFalse("Should not has next element:", iterator.hasNext()); //$NON-NLS-1$
+
+        assertEquals("Size should be 1:", 1, set.size()); //$NON-NLS-1$
+
+        try {
+            iterator.next();
+            fail("Should throw NoSuchElementException"); //$NON-NLS-1$
+        } catch (NoSuchElementException e) {
+            // expected
+        }
+        set = EnumSet.noneOf(EnumFoo.class);
+        set.add(EnumFoo.a);
+        iterator = set.iterator();
+        assertEquals("Should be equal", EnumFoo.a, iterator.next()); //$NON-NLS-1$
+        iterator.remove();
+        try {
+            iterator.remove();
+            fail("Should throw IllegalStateException"); //$NON-NLS-1$
+        } catch(IllegalStateException e) {
+            // expected
+        }
+        
+        Set<EmptyEnum> emptySet = EnumSet.allOf(EmptyEnum.class);
+        Iterator<EmptyEnum> emptyIterator = emptySet.iterator();
+        try {
+            emptyIterator.next();
+            fail("Should throw NoSuchElementException"); //$NON-NLS-1$
+        } catch (NoSuchElementException e) {
+            // expected
+        }
+
+        Set<EnumWithInnerClass> setWithSubclass = EnumSet
+                .allOf(EnumWithInnerClass.class);
+        setWithSubclass.remove(EnumWithInnerClass.e);
+        Iterator<EnumWithInnerClass> iteratorWithSubclass = setWithSubclass
+                .iterator();
+        assertSame("Should be same", EnumWithInnerClass.a, iteratorWithSubclass.next());
//$NON-NLS-1$
+
+        assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
+        assertSame("Should be same", EnumWithInnerClass.b, iteratorWithSubclass.next());
//$NON-NLS-1$
+
+        setWithSubclass.remove(EnumWithInnerClass.c);
+        assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
+        assertSame("Should be same", EnumWithInnerClass.c, iteratorWithSubclass.next());
//$NON-NLS-1$
+
+        assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
+        assertSame("Should be same", EnumWithInnerClass.d, iteratorWithSubclass.next());
//$NON-NLS-1$
+
+        setWithSubclass.add(EnumWithInnerClass.e);
+        assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
+        assertSame("Should be same", EnumWithInnerClass.f, iteratorWithSubclass.next());
//$NON-NLS-1$
+
+        set = EnumSet.noneOf(EnumFoo.class);
+        iterator = set.iterator();
+        try {
+            iterator.next();
+            fail("Should throw NoSuchElementException"); //$NON-NLS-1$
+        } catch (NoSuchElementException e) {
+            // expected
+        }
+        
+        set.add(EnumFoo.a);
+        iterator = set.iterator();
+        assertEquals("Should return EnumFoo.a", EnumFoo.a, iterator.next()); //$NON-NLS-1$
+        assertEquals("Size of set should be 1", 1, set.size()); //$NON-NLS-1$
+        iterator.remove();
+        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
+        assertFalse("Should return false", set.contains(EnumFoo.a)); //$NON-NLS-1$
+        
+        set.add(EnumFoo.a);
+        set.add(EnumFoo.b);
+        iterator = set.iterator();
+        assertEquals("Should be equals", EnumFoo.a, iterator.next()); //$NON-NLS-1$
+        iterator.remove();
+        try {
+            iterator.remove();
+            fail("Should throw IllegalStateException"); //$NON-NLS-1$
+        } catch(IllegalStateException e) {
+            // expected
+        }
+        
+        assertTrue("Should have next element", iterator.hasNext()); //$NON-NLS-1$
+        try {
+            iterator.remove();
+            fail("Should throw IllegalStateException"); //$NON-NLS-1$
+        } catch (IllegalStateException e) {
+            // expected
+        }
+        assertEquals("Size of set should be 1", 1, set.size()); //$NON-NLS-1$
+        assertTrue("Should have next element", iterator.hasNext()); //$NON-NLS-1$
+        assertEquals("Should return EnumFoo.b", EnumFoo.b, iterator.next()); //$NON-NLS-1$
+        set.remove(EnumFoo.b);
+        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
+        iterator.remove();
+        assertFalse("Should return false", set.contains(EnumFoo.a)); //$NON-NLS-1$
+        
+        // RI's bug, EnumFoo.b should not exist at the moment.
+        assertFalse("Should return false", set.contains(EnumFoo.b)); //$NON-NLS-1$
+        
     }
 }



Mime
View raw message