### Eclipse Workspace Patch 1.0 #P org.eclipse.osgi Index: core/framework/org/eclipse/osgi/framework/eventmgr/CopyOnWriteIdentityMap.java =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/framework/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/eventmgr/CopyOnWriteIdentityMap.java,v retrieving revision 1.6 diff -u -r1.6 CopyOnWriteIdentityMap.java --- core/framework/org/eclipse/osgi/framework/eventmgr/CopyOnWriteIdentityMap.java 8 Sep 2010 17:56:32 -0000 1.6 +++ core/framework/org/eclipse/osgi/framework/eventmgr/CopyOnWriteIdentityMap.java 1 Oct 2010 17:16:11 -0000 @@ -330,7 +330,7 @@ * The set and the entries returned by the set cannot be modified. */ public Set> entrySet() { - return new EntrySet>(entries(), EntrySet.ENTRY); + return new EntrySet(entries()); } /** @@ -341,7 +341,7 @@ * The set cannot be modified. */ public Set keySet() { - return new EntrySet(entries(), EntrySet.KEY); + return new KeySet(entries()); } /** @@ -352,7 +352,7 @@ * The collection cannot be modified. */ public Collection values() { - return new EntrySet(entries(), EntrySet.VALUE); + return new ValueSet(entries()); } /** @@ -419,20 +419,57 @@ * * This class is immutable. */ - private static class EntrySet extends AbstractSet { - private final Entry[] entries; - private final int returnType; - final static int ENTRY = 1; - final static int KEY = 2; - final static int VALUE = 3; + private static class EntrySet extends AbstractSet> { + private final Entry[] entries; - EntrySet(Entry[] entries, int returnType) { + EntrySet(Entry[] entries) { this.entries = entries; - this.returnType = returnType; } - public Iterator iterator() { - return new EntryIterator(entries, returnType); + public Iterator> iterator() { + return new EntryIterator(entries); + } + + public int size() { + return entries.length; + } + } + + /** + * Set class used for entry and key sets and values collections. + * + * This class is immutable. + */ + private static class KeySet extends AbstractSet { + private final Entry[] entries; + + KeySet(Entry[] entries) { + this.entries = entries; + } + + public Iterator iterator() { + return new KeyIterator(entries); + } + + public int size() { + return entries.length; + } + } + + /** + * Set class used for entry and key sets and values collections. + * + * This class is immutable. + */ + private static class ValueSet extends AbstractSet { + private final Entry[] entries; + + ValueSet(Entry[] entries) { + this.entries = entries; + } + + public Iterator iterator() { + return new ValueIterator(entries); } public int size() { @@ -444,39 +481,85 @@ * Iterator class used for entry and key sets and values collections. * */ - private static class EntryIterator implements Iterator { - private final Entry[] entries; - private final int returnType; + private static class EntryIterator implements Iterator> { + private final Entry[] entries; + private final int length; private int cursor = 0; - EntryIterator(Entry[] entries, int returnType) { + EntryIterator(Entry[] entries) { this.entries = entries; - this.returnType = returnType; + this.length = entries.length; } public boolean hasNext() { - return cursor < entries.length; + return cursor < length; } - public E next() { - if (cursor == entries.length) { + public Map.Entry next() { + if (cursor == length) { throw new NoSuchElementException(); } - switch (returnType) { - case EntrySet.ENTRY : - @SuppressWarnings("unchecked") - E entry = (E) entries[cursor++]; - return entry; - case EntrySet.KEY : - @SuppressWarnings("unchecked") - E key = (E) entries[cursor++].key; - return key; - case EntrySet.VALUE : - @SuppressWarnings("unchecked") - E value = (E) entries[cursor++].value; - return value; + return entries[cursor++]; + } + + public void remove() { + throw new UnsupportedOperationException(); // the collection cannot be modified. + } + } + + /** + * Iterator class used for entry and key sets and values collections. + * + */ + private static class KeyIterator implements Iterator { + private final Entry[] entries; + private final int length; + private int cursor = 0; + + KeyIterator(Entry[] entries) { + this.entries = entries; + this.length = entries.length; + } + + public boolean hasNext() { + return cursor < length; + } + + public K next() { + if (cursor == length) { + throw new NoSuchElementException(); + } + return entries[cursor++].key; + } + + public void remove() { + throw new UnsupportedOperationException(); // the collection cannot be modified. + } + } + + /** + * Iterator class used for entry and key sets and values collections. + * + */ + private static class ValueIterator implements Iterator { + private final Entry[] entries; + private final int length; + private int cursor = 0; + + ValueIterator(Entry[] entries) { + this.entries = entries; + this.length = entries.length; + } + + public boolean hasNext() { + return cursor < length; + } + + public V next() { + if (cursor == length) { + throw new NoSuchElementException(); } - throw new InternalError(); + return entries[cursor++].value; } public void remove() {