commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r814997 [10/18] - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/ java/org/apache/commons/collections/bidimap/ java/org/apache/commons/collections/buffer/ java/org/apac...
Date Tue, 15 Sep 2009 05:30:02 GMT
Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/LinkedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/LinkedMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/LinkedMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/LinkedMap.java Tue Sep 15 05:29:56 2009
@@ -62,8 +62,7 @@
  *
  * @author Stephen Colebourne
  */
-public class LinkedMap
-        extends AbstractLinkedMap implements Serializable, Cloneable {
+public class LinkedMap<K, V> extends AbstractLinkedMap<K, V> implements Serializable, Cloneable {
 
     /** Serialisation version */
     private static final long serialVersionUID = 9077234323521161066L;
@@ -104,7 +103,7 @@
      * @param map  the map to copy
      * @throws NullPointerException if the map is null
      */
-    public LinkedMap(Map map) {
+    public LinkedMap(Map<K, V> map) {
         super(map);
     }
 
@@ -114,8 +113,8 @@
      *
      * @return a shallow clone
      */
-    public Object clone() {
-        return super.clone();
+    public LinkedMap<K, V> clone() {
+        return (LinkedMap<K, V>) super.clone();
     }
     
     /**
@@ -142,7 +141,7 @@
      * @return the key at the specified index
      * @throws IndexOutOfBoundsException if the index is invalid
      */
-    public Object get(int index) {
+    public K get(int index) {
         return getEntry(index).getKey();
     }
     
@@ -153,7 +152,7 @@
      * @return the value at the specified index
      * @throws IndexOutOfBoundsException if the index is invalid
      */
-    public Object getValue(int index) {
+    public V getValue(int index) {
         return getEntry(index).getValue();
     }
     
@@ -166,7 +165,7 @@
     public int indexOf(Object key) {
         key = convertKey(key);
         int i = 0;
-        for (LinkEntry entry = header.after; entry != header; entry = entry.after, i++) {
+        for (LinkEntry<K, V> entry = header.after; entry != header; entry = entry.after, i++) {
             if (isEqualKey(key, entry.key)) {
                 return i;
             }
@@ -182,7 +181,7 @@
      *  or <code>null</code> if none existed
      * @throws IndexOutOfBoundsException if the index is invalid
      */
-    public Object remove(int index) {
+    public V remove(int index) {
         return remove(get(index));
     }
 
@@ -201,29 +200,29 @@
      * @see #keySet()
      * @return The ordered list of keys.  
      */
-    public List asList() {
-        return new LinkedMapList(this);
+    public List<K> asList() {
+        return new LinkedMapList<K>(this);
     }
 
     /**
      * List view of map.
      */
-    static class LinkedMapList extends AbstractList {
-        
-        final LinkedMap parent;
-        
-        LinkedMapList(LinkedMap parent) {
+    static class LinkedMapList<K> extends AbstractList<K> {
+
+        final LinkedMap<K, ?> parent;
+
+        LinkedMapList(LinkedMap<K, ?> parent) {
             this.parent = parent;
         }
-        
+
         public int size() {
             return parent.size();
         }
-    
-        public Object get(int index) {
+
+        public K get(int index) {
             return parent.get(index);
         }
-        
+
         public boolean contains(Object obj) {
             return parent.containsKey(obj);
         }
@@ -231,58 +230,58 @@
         public int indexOf(Object obj) {
             return parent.indexOf(obj);
         }
-        
+
         public int lastIndexOf(Object obj) {
             return parent.indexOf(obj);
         }
-        
-        public boolean containsAll(Collection coll) {
+
+        public boolean containsAll(Collection<?> coll) {
             return parent.keySet().containsAll(coll);
         }
-        
-        public Object remove(int index) {
+
+        public K remove(int index) {
             throw new UnsupportedOperationException();
         }
-        
+
         public boolean remove(Object obj) {
             throw new UnsupportedOperationException();
         }
-        
-        public boolean removeAll(Collection coll) {
+
+        public boolean removeAll(Collection<?> coll) {
             throw new UnsupportedOperationException();
         }
-        
-        public boolean retainAll(Collection coll) {
+
+        public boolean retainAll(Collection<?> coll) {
             throw new UnsupportedOperationException();
         }
-        
+
         public void clear() {
             throw new UnsupportedOperationException();
         }
-        
+
         public Object[] toArray() {
             return parent.keySet().toArray();
         }
 
-        public Object[] toArray(Object[] array) {
+        public <T> T[] toArray(T[] array) {
             return parent.keySet().toArray(array);
         }
-        
-        public Iterator iterator() {
+
+        public Iterator<K> iterator() {
             return UnmodifiableIterator.decorate(parent.keySet().iterator());
         }
-        
-        public ListIterator listIterator() {
+
+        public ListIterator<K> listIterator() {
             return UnmodifiableListIterator.decorate(super.listIterator());
         }
-        
-        public ListIterator listIterator(int fromIndex) {
+
+        public ListIterator<K> listIterator(int fromIndex) {
             return UnmodifiableListIterator.decorate(super.listIterator(fromIndex));
         }
-        
-        public List subList(int fromIndexInclusive, int toIndexExclusive) {
+
+        public List<K> subList(int fromIndexInclusive, int toIndexExclusive) {
             return UnmodifiableList.decorate(super.subList(fromIndexInclusive, toIndexExclusive));
         }
     }
-    
+
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiKeyMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiKeyMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiKeyMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiKeyMap.java Tue Sep 15 05:29:56 2009
@@ -17,10 +17,7 @@
 package org.apache.commons.collections.map;
 
 import java.io.Serializable;
-import java.util.Collection;
-import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.MapIterator;
@@ -77,14 +74,15 @@
  *
  * @author Stephen Colebourne
  */
-public class MultiKeyMap
-        implements IterableMap, Serializable {
+public class MultiKeyMap<K, V> extends AbstractMapDecorator<MultiKey<? extends K>, V>
+        implements IterableMap<MultiKey<? extends K>, V>, Serializable {
 
     /** Serialisation version */
     private static final long serialVersionUID = -1788199231038721040L;
 
     /** The decorated map */
-    protected final AbstractHashedMap map;
+    //keep this member around for serialization BC with older Collections releases assuming we want to do that
+    protected AbstractHashedMap<MultiKey<? extends K>, V> map;
 
     //-----------------------------------------------------------------------
     /**
@@ -94,14 +92,14 @@
      * @param map  the map to decorate, not null
      * @throws IllegalArgumentException if the map is null or not empty
      */
-    public static MultiKeyMap decorate(AbstractHashedMap map) {
+    public static <K, V> MultiKeyMap<K, V> decorate(AbstractHashedMap<MultiKey<? extends K>, V> map) {
         if (map == null) {
             throw new IllegalArgumentException("Map must not be null");
         }
         if (map.size() > 0) {
             throw new IllegalArgumentException("Map must be empty");
         }
-        return new MultiKeyMap(map);
+        return new MultiKeyMap<K, V>(map);
     }
 
     //-----------------------------------------------------------------------    
@@ -109,8 +107,7 @@
      * Constructs a new MultiKeyMap that decorates a <code>HashedMap</code>.
      */
     public MultiKeyMap() {
-        super();
-        map = new HashedMap();
+        this(new HashedMap<MultiKey<? extends K>, V>());
     }
 
     /**
@@ -121,8 +118,8 @@
      *
      * @param map  the map to decorate
      */
-    protected MultiKeyMap(AbstractHashedMap map) {
-        super();
+    protected MultiKeyMap(AbstractHashedMap<MultiKey<? extends K>, V> map) {
+        super(map);
         this.map = map;
     }
 
@@ -134,9 +131,9 @@
      * @param key2  the second key
      * @return the mapped value, null if no match
      */
-    public Object get(Object key1, Object key2) {
+    public V get(Object key1, Object key2) {
         int hashCode = hash(key1, key2);
-        AbstractHashedMap.HashEntry entry = map.data[map.hashIndex(hashCode, map.data.length)];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) {
                 return entry.getValue();
@@ -155,7 +152,7 @@
      */
     public boolean containsKey(Object key1, Object key2) {
         int hashCode = hash(key1, key2);
-        AbstractHashedMap.HashEntry entry = map.data[map.hashIndex(hashCode, map.data.length)];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) {
                 return true;
@@ -173,20 +170,19 @@
      * @param value  the value to store
      * @return the value previously mapped to this combined key, null if none
      */
-    public Object put(Object key1, Object key2, Object value) {
+    public V put(K key1, K key2, V value) {
         int hashCode = hash(key1, key2);
-        int index = map.hashIndex(hashCode, map.data.length);
-        AbstractHashedMap.HashEntry entry = map.data[index];
+        int index = decorated().hashIndex(hashCode, decorated().data.length);
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) {
-                Object oldValue = entry.getValue();
-                map.updateEntry(entry, value);
+                V oldValue = entry.getValue();
+                decorated().updateEntry(entry, value);
                 return oldValue;
             }
             entry = entry.next;
         }
-        
-        map.addMapping(index, hashCode, new MultiKey(key1, key2), value);
+        decorated().addMapping(index, hashCode, new MultiKey<K>(key1, key2), value);
         return null;
     }
 
@@ -197,15 +193,15 @@
      * @param key2  the second key
      * @return the value mapped to the removed key, null if key not in map
      */
-    public Object remove(Object key1, Object key2) {
+    public V remove(Object key1, Object key2) {
         int hashCode = hash(key1, key2);
-        int index = map.hashIndex(hashCode, map.data.length);
-        AbstractHashedMap.HashEntry entry = map.data[index];
-        AbstractHashedMap.HashEntry previous = null;
+        int index = decorated().hashIndex(hashCode, decorated().data.length);
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> previous = null;
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) {
-                Object oldValue = entry.getValue();
-                map.removeMapping(entry, index, previous);
+                V oldValue = entry.getValue();
+                decorated().removeMapping(entry, index, previous);
                 return oldValue;
             }
             previous = entry;
@@ -244,12 +240,13 @@
      * @param key2  the second key
      * @return true if the key matches
      */
-    protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2) {
-        MultiKey multi = (MultiKey) entry.getKey();
+    protected boolean isEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry,
+            Object key1, Object key2) {
+        MultiKey<? extends K> multi = entry.getKey();
         return
             multi.size() == 2 &&
-            (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
-            (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1)));
+            (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) &&
+            (key2 == multi.getKey(1) || key1 != null && key2.equals(multi.getKey(1)));
     }
 
     //-----------------------------------------------------------------------
@@ -261,9 +258,9 @@
      * @param key3  the third key
      * @return the mapped value, null if no match
      */
-    public Object get(Object key1, Object key2, Object key3) {
+    public V get(Object key1, Object key2, Object key3) {
         int hashCode = hash(key1, key2, key3);
-        AbstractHashedMap.HashEntry entry = map.data[map.hashIndex(hashCode, map.data.length)];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3)) {
                 return entry.getValue();
@@ -283,7 +280,7 @@
      */
     public boolean containsKey(Object key1, Object key2, Object key3) {
         int hashCode = hash(key1, key2, key3);
-        AbstractHashedMap.HashEntry entry = map.data[map.hashIndex(hashCode, map.data.length)];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3)) {
                 return true;
@@ -302,20 +299,19 @@
      * @param value  the value to store
      * @return the value previously mapped to this combined key, null if none
      */
-    public Object put(Object key1, Object key2, Object key3, Object value) {
+    public V put(K key1, K key2, K key3, V value) {
         int hashCode = hash(key1, key2, key3);
-        int index = map.hashIndex(hashCode, map.data.length);
-        AbstractHashedMap.HashEntry entry = map.data[index];
+        int index = decorated().hashIndex(hashCode, decorated().data.length);
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3)) {
-                Object oldValue = entry.getValue();
-                map.updateEntry(entry, value);
+                V oldValue = entry.getValue();
+                decorated().updateEntry(entry, value);
                 return oldValue;
             }
             entry = entry.next;
         }
-        
-        map.addMapping(index, hashCode, new MultiKey(key1, key2, key3), value);
+        decorated().addMapping(index, hashCode, new MultiKey<K>(key1, key2, key3), value);
         return null;
     }
 
@@ -327,15 +323,15 @@
      * @param key3  the third key
      * @return the value mapped to the removed key, null if key not in map
      */
-    public Object remove(Object key1, Object key2, Object key3) {
+    public V remove(Object key1, Object key2, Object key3) {
         int hashCode = hash(key1, key2, key3);
-        int index = map.hashIndex(hashCode, map.data.length);
-        AbstractHashedMap.HashEntry entry = map.data[index];
-        AbstractHashedMap.HashEntry previous = null;
+        int index = decorated().hashIndex(hashCode, decorated().data.length);
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> previous = null;
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3)) {
-                Object oldValue = entry.getValue();
-                map.removeMapping(entry, index, previous);
+                V oldValue = entry.getValue();
+                decorated().removeMapping(entry, index, previous);
                 return oldValue;
             }
             previous = entry;
@@ -379,13 +375,13 @@
      * @param key3  the third key
      * @return true if the key matches
      */
-    protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3) {
-        MultiKey multi = (MultiKey) entry.getKey();
+    protected boolean isEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2, Object key3) {
+        MultiKey<? extends K> multi = entry.getKey();
         return
             multi.size() == 3 &&
-            (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
-            (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) &&
-            (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2)));
+            (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) &&
+            (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))) &&
+            (key3 == multi.getKey(2) || key3 != null && key3.equals(multi.getKey(2)));
     }
 
     //-----------------------------------------------------------------------
@@ -398,9 +394,9 @@
      * @param key4  the fourth key
      * @return the mapped value, null if no match
      */
-    public Object get(Object key1, Object key2, Object key3, Object key4) {
+    public V get(Object key1, Object key2, Object key3, Object key4) {
         int hashCode = hash(key1, key2, key3, key4);
-        AbstractHashedMap.HashEntry entry = map.data[map.hashIndex(hashCode, map.data.length)];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4)) {
                 return entry.getValue();
@@ -421,7 +417,7 @@
      */
     public boolean containsKey(Object key1, Object key2, Object key3, Object key4) {
         int hashCode = hash(key1, key2, key3, key4);
-        AbstractHashedMap.HashEntry entry = map.data[map.hashIndex(hashCode, map.data.length)];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4)) {
                 return true;
@@ -441,20 +437,19 @@
      * @param value  the value to store
      * @return the value previously mapped to this combined key, null if none
      */
-    public Object put(Object key1, Object key2, Object key3, Object key4, Object value) {
+    public V put(K key1, K key2, K key3, K key4, V value) {
         int hashCode = hash(key1, key2, key3, key4);
-        int index = map.hashIndex(hashCode, map.data.length);
-        AbstractHashedMap.HashEntry entry = map.data[index];
+        int index = decorated().hashIndex(hashCode, decorated().data.length);
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4)) {
-                Object oldValue = entry.getValue();
-                map.updateEntry(entry, value);
+                V oldValue = entry.getValue();
+                decorated().updateEntry(entry, value);
                 return oldValue;
             }
             entry = entry.next;
         }
-        
-        map.addMapping(index, hashCode, new MultiKey(key1, key2, key3, key4), value);
+        decorated().addMapping(index, hashCode, new MultiKey<K>(key1, key2, key3, key4), value);
         return null;
     }
 
@@ -467,15 +462,15 @@
      * @param key4  the fourth key
      * @return the value mapped to the removed key, null if key not in map
      */
-    public Object remove(Object key1, Object key2, Object key3, Object key4) {
+    public V remove(Object key1, Object key2, Object key3, Object key4) {
         int hashCode = hash(key1, key2, key3, key4);
-        int index = map.hashIndex(hashCode, map.data.length);
-        AbstractHashedMap.HashEntry entry = map.data[index];
-        AbstractHashedMap.HashEntry previous = null;
+        int index = decorated().hashIndex(hashCode, decorated().data.length);
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> previous = null;
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4)) {
-                Object oldValue = entry.getValue();
-                map.removeMapping(entry, index, previous);
+                V oldValue = entry.getValue();
+                decorated().removeMapping(entry, index, previous);
                 return oldValue;
             }
             previous = entry;
@@ -524,14 +519,14 @@
      * @param key4  the fourth key
      * @return true if the key matches
      */
-    protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3, Object key4) {
-        MultiKey multi = (MultiKey) entry.getKey();
+    protected boolean isEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, Object key1, Object key2, Object key3, Object key4) {
+        MultiKey<? extends K> multi = entry.getKey();
         return
             multi.size() == 4 &&
-            (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
-            (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) &&
-            (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))) &&
-            (key4 == null ? multi.getKey(3) == null : key4.equals(multi.getKey(3)));
+            (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) &&
+            (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))) &&
+            (key3 == multi.getKey(2) || key3 != null && key3.equals(multi.getKey(2))) &&
+            (key4 == multi.getKey(3) || key4 != null && key4.equals(multi.getKey(3)));
     }
 
     //-----------------------------------------------------------------------
@@ -545,9 +540,9 @@
      * @param key5  the fifth key
      * @return the mapped value, null if no match
      */
-    public Object get(Object key1, Object key2, Object key3, Object key4, Object key5) {
+    public V get(Object key1, Object key2, Object key3, Object key4, Object key5) {
         int hashCode = hash(key1, key2, key3, key4, key5);
-        AbstractHashedMap.HashEntry entry = map.data[map.hashIndex(hashCode, map.data.length)];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4, key5)) {
                 return entry.getValue();
@@ -569,7 +564,7 @@
      */
     public boolean containsKey(Object key1, Object key2, Object key3, Object key4, Object key5) {
         int hashCode = hash(key1, key2, key3, key4, key5);
-        AbstractHashedMap.HashEntry entry = map.data[map.hashIndex(hashCode, map.data.length)];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4, key5)) {
                 return true;
@@ -590,20 +585,19 @@
      * @param value  the value to store
      * @return the value previously mapped to this combined key, null if none
      */
-    public Object put(Object key1, Object key2, Object key3, Object key4, Object key5, Object value) {
+    public V put(K key1, K key2, K key3, K key4, K key5, V value) {
         int hashCode = hash(key1, key2, key3, key4, key5);
-        int index = map.hashIndex(hashCode, map.data.length);
-        AbstractHashedMap.HashEntry entry = map.data[index];
+        int index = decorated().hashIndex(hashCode, decorated().data.length);
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index];
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4, key5)) {
-                Object oldValue = entry.getValue();
-                map.updateEntry(entry, value);
+                V oldValue = entry.getValue();
+                decorated().updateEntry(entry, value);
                 return oldValue;
             }
             entry = entry.next;
         }
-        
-        map.addMapping(index, hashCode, new MultiKey(key1, key2, key3, key4, key5), value);
+        decorated().addMapping(index, hashCode, new MultiKey<K>(key1, key2, key3, key4, key5), value);
         return null;
     }
 
@@ -617,15 +611,15 @@
      * @param key5  the fifth key
      * @return the value mapped to the removed key, null if key not in map
      */
-    public Object remove(Object key1, Object key2, Object key3, Object key4, Object key5) {
+    public V remove(Object key1, Object key2, Object key3, Object key4, Object key5) {
         int hashCode = hash(key1, key2, key3, key4, key5);
-        int index = map.hashIndex(hashCode, map.data.length);
-        AbstractHashedMap.HashEntry entry = map.data[index];
-        AbstractHashedMap.HashEntry previous = null;
+        int index = decorated().hashIndex(hashCode, decorated().data.length);
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index];
+        AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> previous = null;
         while (entry != null) {
             if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4, key5)) {
-                Object oldValue = entry.getValue();
-                map.removeMapping(entry, index, previous);
+                V oldValue = entry.getValue();
+                decorated().removeMapping(entry, index, previous);
                 return oldValue;
             }
             previous = entry;
@@ -679,15 +673,16 @@
      * @param key5  the fifth key
      * @return true if the key matches
      */
-    protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3, Object key4, Object key5) {
-        MultiKey multi = (MultiKey) entry.getKey();
+    protected boolean isEqualKey(AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry,
+            Object key1, Object key2, Object key3, Object key4, Object key5) {
+        MultiKey<? extends K> multi = entry.getKey();
         return
             multi.size() == 5 &&
-            (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
-            (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) &&
-            (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))) &&
-            (key4 == null ? multi.getKey(3) == null : key4.equals(multi.getKey(3))) &&
-            (key5 == null ? multi.getKey(4) == null : key5.equals(multi.getKey(4)));
+            (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) &&
+            (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))) &&
+            (key3 == multi.getKey(2) || key3 != null && key3.equals(multi.getKey(2))) &&
+            (key4 == multi.getKey(3) || key4 != null && key4.equals(multi.getKey(3))) &&
+            (key5 == multi.getKey(4) || key5 != null && key5.equals(multi.getKey(4)));
     }
 
     //-----------------------------------------------------------------------
@@ -702,9 +697,9 @@
      */
     public boolean removeAll(Object key1) {
         boolean modified = false;
-        MapIterator it = mapIterator();
+        MapIterator<MultiKey<? extends K>, V> it = mapIterator();
         while (it.hasNext()) {
-            MultiKey multi = (MultiKey) it.next();
+            MultiKey<? extends K> multi = it.next();
             if (multi.size() >= 1 &&
                 (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0)))) {
                 it.remove();
@@ -726,9 +721,9 @@
      */
     public boolean removeAll(Object key1, Object key2) {
         boolean modified = false;
-        MapIterator it = mapIterator();
+        MapIterator<MultiKey<? extends K>, V> it = mapIterator();
         while (it.hasNext()) {
-            MultiKey multi = (MultiKey) it.next();
+            MultiKey<? extends K> multi = it.next();
             if (multi.size() >= 2 &&
                 (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
                 (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1)))) {
@@ -752,9 +747,9 @@
      */
     public boolean removeAll(Object key1, Object key2, Object key3) {
         boolean modified = false;
-        MapIterator it = mapIterator();
+        MapIterator<MultiKey<? extends K>, V> it = mapIterator();
         while (it.hasNext()) {
-            MultiKey multi = (MultiKey) it.next();
+            MultiKey<? extends K> multi = it.next();
             if (multi.size() >= 3 &&
                 (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
                 (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) &&
@@ -780,9 +775,9 @@
      */
     public boolean removeAll(Object key1, Object key2, Object key3, Object key4) {
         boolean modified = false;
-        MapIterator it = mapIterator();
+        MapIterator<MultiKey<? extends K>, V> it = mapIterator();
         while (it.hasNext()) {
-            MultiKey multi = (MultiKey) it.next();
+            MultiKey<? extends K> multi = it.next();
             if (multi.size() >= 4 &&
                 (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
                 (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) &&
@@ -801,13 +796,10 @@
      * 
      * @param key  the key to check
      */
-    protected void checkKey(Object key) {
+    protected void checkKey(MultiKey<?> key) {
         if (key == null) {
             throw new NullPointerException("Key must not be null");
         }
-        if (key instanceof MultiKey == false) {
-            throw new ClassCastException("Key must be a MultiKey");
-        }
     }
 
     /**
@@ -815,8 +807,8 @@
      *
      * @return a shallow clone
      */
-    public Object clone() {
-        return new MultiKeyMap((AbstractHashedMap) map.clone());
+    public MultiKeyMap<K, V> clone() {
+        return new MultiKeyMap<K, V>(decorated().clone());
     }
 
     /**
@@ -829,9 +821,9 @@
      * @throws NullPointerException if the key is null
      * @throws ClassCastException if the key is not a MultiKey
      */
-    public Object put(Object key, Object value) {
+    public V put(MultiKey<? extends K> key, V value) {
         checkKey(key);
-        return map.put(key, value);
+        return super.put(key, value);
     }
 
     /**
@@ -842,72 +834,24 @@
      * @throws NullPointerException if the mapToCopy or any key within is null
      * @throws ClassCastException if any key in mapToCopy is not a MultiKey
      */
-    public void putAll(Map mapToCopy) {
-        for (Iterator it = mapToCopy.keySet().iterator(); it.hasNext();) {
-            Object key = it.next();
+    @Override
+    public void putAll(Map<? extends MultiKey<? extends K>, ? extends V> mapToCopy) {
+        for (MultiKey<? extends K> key : mapToCopy.keySet()) {
             checkKey(key);
         }
-        map.putAll(mapToCopy);
+        super.putAll(mapToCopy);
     }
 
     //-----------------------------------------------------------------------
-    public MapIterator mapIterator() {
-        return map.mapIterator();
-    }
-
-    public int size() {
-        return map.size();
-    }
-
-    public boolean isEmpty() {
-        return map.isEmpty();
-    }
-
-    public boolean containsKey(Object key) {
-        return map.containsKey(key);
-    }
-
-    public boolean containsValue(Object value) {
-        return map.containsValue(value);
-    }
-
-    public Object get(Object key) {
-        return map.get(key);
-    }
-
-    public Object remove(Object key) {
-        return map.remove(key);
-    }
-
-    public void clear() {
-        map.clear();
+    public MapIterator<MultiKey<? extends K>, V> mapIterator() {
+        return decorated().mapIterator();
     }
 
-    public Set keySet() {
-        return map.keySet();
-    }
-
-    public Collection values() {
-        return map.values();
-    }
-
-    public Set entrySet() {
-        return map.entrySet();
-    }
-
-    public boolean equals(Object obj) {
-        if (obj == this) {
-            return true;
-        }
-        return map.equals(obj);
-    }
-
-    public int hashCode() {
-        return map.hashCode();
-    }
-
-    public String toString() {
-        return map.toString();
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected AbstractHashedMap<MultiKey<? extends K>, V> decorated() {
+        return map;
     }
-
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/PredicatedSortedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/PredicatedSortedMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/PredicatedSortedMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/PredicatedSortedMap.java Tue Sep 15 05:29:56 2009
@@ -46,9 +46,7 @@
  * @author Stephen Colebourne
  * @author Paul Jack
  */
-public class PredicatedSortedMap
-        extends PredicatedMap
-        implements SortedMap {
+public class PredicatedSortedMap<K, V> extends PredicatedMap<K, V> implements SortedMap<K, V> {
 
     /** Serialization version */
     private static final long serialVersionUID = 3359846175935304332L;
@@ -64,8 +62,9 @@
      * @param valuePredicate  the predicate to validate to values, null means no check
      * @throws IllegalArgumentException if the map is null
      */
-    public static SortedMap decorate(SortedMap map, Predicate keyPredicate, Predicate valuePredicate) {
-        return new PredicatedSortedMap(map, keyPredicate, valuePredicate);
+    public static <K, V> SortedMap<K, V> decorate(SortedMap<K, V> map,
+            Predicate<? super K> keyPredicate, Predicate<? super V> valuePredicate) {
+        return new PredicatedSortedMap<K, V>(map, keyPredicate, valuePredicate);
     }
 
     //-----------------------------------------------------------------------
@@ -77,7 +76,8 @@
      * @param valuePredicate  the predicate to validate to values, null means no check
      * @throws IllegalArgumentException if the map is null
      */
-    protected PredicatedSortedMap(SortedMap map, Predicate keyPredicate, Predicate valuePredicate) {
+    protected PredicatedSortedMap(SortedMap<K, V> map, Predicate<? super K> keyPredicate,
+            Predicate<? super V> valuePredicate) {
         super(map, keyPredicate, valuePredicate);
     }
 
@@ -87,36 +87,36 @@
      * 
      * @return the decorated map
      */
-    protected SortedMap getSortedMap() {
-        return (SortedMap) map;
+    protected SortedMap<K, V> getSortedMap() {
+        return (SortedMap<K, V>) map;
     }
 
     //-----------------------------------------------------------------------
-    public Object firstKey() {
+    public K firstKey() {
         return getSortedMap().firstKey();
     }
 
-    public Object lastKey() {
+    public K lastKey() {
         return getSortedMap().lastKey();
     }
 
-    public Comparator comparator() {
+    public Comparator<? super K> comparator() {
         return getSortedMap().comparator();
     }
 
-    public SortedMap subMap(Object fromKey, Object toKey) {
-        SortedMap map = getSortedMap().subMap(fromKey, toKey);
-        return new PredicatedSortedMap(map, keyPredicate, valuePredicate);
+    public SortedMap<K, V> subMap(K fromKey, K toKey) {
+        SortedMap<K, V> map = getSortedMap().subMap(fromKey, toKey);
+        return new PredicatedSortedMap<K, V>(map, keyPredicate, valuePredicate);
     }
 
-    public SortedMap headMap(Object toKey) {
-        SortedMap map = getSortedMap().headMap(toKey);
-        return new PredicatedSortedMap(map, keyPredicate, valuePredicate);
+    public SortedMap<K, V> headMap(K toKey) {
+        SortedMap<K, V> map = getSortedMap().headMap(toKey);
+        return new PredicatedSortedMap<K, V>(map, keyPredicate, valuePredicate);
     }
 
-    public SortedMap tailMap(Object fromKey) {
-        SortedMap map = getSortedMap().tailMap(fromKey);
-        return new PredicatedSortedMap(map, keyPredicate, valuePredicate);
+    public SortedMap<K, V> tailMap(K fromKey) {
+        SortedMap<K, V> map = getSortedMap().tailMap(fromKey);
+        return new PredicatedSortedMap<K, V>(map, keyPredicate, valuePredicate);
     }
 
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ReferenceIdentityMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ReferenceIdentityMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ReferenceIdentityMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ReferenceIdentityMap.java Tue Sep 15 05:29:56 2009
@@ -70,7 +70,7 @@
  *
  * @author Stephen Colebourne
  */
-public class ReferenceIdentityMap extends AbstractReferenceMap implements Serializable {
+public class ReferenceIdentityMap<K, V> extends AbstractReferenceMap<K, V> implements Serializable {
 
     /** Serialization version */
     private static final long serialVersionUID = -1266190134568365852L;
@@ -80,7 +80,8 @@
      * use hard references to keys and soft references to values.
      */
     public ReferenceIdentityMap() {
-        super(HARD, SOFT, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, false);
+        super(ReferenceStrength.HARD, ReferenceStrength.SOFT, DEFAULT_CAPACITY,
+                DEFAULT_LOAD_FACTOR, false);
     }
 
     /**
@@ -92,7 +93,7 @@
      * @param valueType  the type of reference to use for values;
      *   must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
      */
-    public ReferenceIdentityMap(int keyType, int valueType) {
+    public ReferenceIdentityMap(ReferenceStrength keyType, ReferenceStrength valueType) {
         super(keyType, valueType, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, false);
     }
 
@@ -107,7 +108,8 @@
      * @param purgeValues should the value be automatically purged when the 
      *   key is garbage collected 
      */
-    public ReferenceIdentityMap(int keyType, int valueType, boolean purgeValues) {
+    public ReferenceIdentityMap(ReferenceStrength keyType, ReferenceStrength valueType,
+            boolean purgeValues) {
         super(keyType, valueType, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, purgeValues);
     }
 
@@ -122,7 +124,8 @@
      * @param capacity  the initial capacity for the map
      * @param loadFactor  the load factor for the map
      */
-    public ReferenceIdentityMap(int keyType, int valueType, int capacity, float loadFactor) {
+    public ReferenceIdentityMap(ReferenceStrength keyType, ReferenceStrength valueType,
+            int capacity, float loadFactor) {
         super(keyType, valueType, capacity, loadFactor, false);
     }
 
@@ -139,8 +142,8 @@
      * @param purgeValues  should the value be automatically purged when the 
      *   key is garbage collected 
      */
-    public ReferenceIdentityMap(int keyType, int valueType, int capacity,
-                        float loadFactor, boolean purgeValues) {
+    public ReferenceIdentityMap(ReferenceStrength keyType, ReferenceStrength valueType,
+            int capacity, float loadFactor, boolean purgeValues) {
         super(keyType, valueType, capacity, loadFactor, purgeValues);
     }
 
@@ -182,8 +185,8 @@
      * @return true if equal by identity
      */
     protected boolean isEqualKey(Object key1, Object key2) {
-        key2 = (keyType > HARD ? ((Reference) key2).get() : key2);
-        return (key1 == key2);
+        key2 = keyType == ReferenceStrength.HARD ? key2 : ((Reference<?>) key2).get();
+        return key1 == key2;
     }
 
     /**
@@ -196,7 +199,7 @@
      * @return true if equal by identity
      */
     protected boolean isEqualValue(Object value1, Object value2) {
-        return (value1 == value2);
+        return value1 == value2;
     }
 
     //-----------------------------------------------------------------------

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ReferenceMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ReferenceMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ReferenceMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ReferenceMap.java Tue Sep 15 05:29:56 2009
@@ -73,7 +73,7 @@
  * @author Paul Jack
  * @author Stephen Colebourne
  */
-public class ReferenceMap extends AbstractReferenceMap implements Serializable {
+public class ReferenceMap<K, V> extends AbstractReferenceMap<K, V> implements Serializable {
 
     /** Serialization version */
     private static final long serialVersionUID = 1555089888138299607L;
@@ -83,7 +83,8 @@
      * use hard references to keys and soft references to values.
      */
     public ReferenceMap() {
-        super(HARD, SOFT, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, false);
+        super(ReferenceStrength.HARD, ReferenceStrength.SOFT, DEFAULT_CAPACITY,
+                DEFAULT_LOAD_FACTOR, false);
     }
 
     /**
@@ -95,7 +96,7 @@
      * @param valueType  the type of reference to use for values;
      *   must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
      */
-    public ReferenceMap(int keyType, int valueType) {
+    public ReferenceMap(ReferenceStrength keyType, ReferenceStrength valueType) {
         super(keyType, valueType, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, false);
     }
 
@@ -110,7 +111,7 @@
      * @param purgeValues should the value be automatically purged when the 
      *   key is garbage collected 
      */
-    public ReferenceMap(int keyType, int valueType, boolean purgeValues) {
+    public ReferenceMap(ReferenceStrength keyType, ReferenceStrength valueType, boolean purgeValues) {
         super(keyType, valueType, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, purgeValues);
     }
 
@@ -126,7 +127,8 @@
      * @param capacity  the initial capacity for the map
      * @param loadFactor  the load factor for the map
      */
-    public ReferenceMap(int keyType, int valueType, int capacity, float loadFactor) {
+    public ReferenceMap(ReferenceStrength keyType, ReferenceStrength valueType, int capacity,
+            float loadFactor) {
         super(keyType, valueType, capacity, loadFactor, false);
     }
 
@@ -144,8 +146,8 @@
      * @param purgeValues  should the value be automatically purged when the 
      *   key is garbage collected 
      */
-    public ReferenceMap(int keyType, int valueType, int capacity,
-                        float loadFactor, boolean purgeValues) {
+    public ReferenceMap(ReferenceStrength keyType, ReferenceStrength valueType, int capacity,
+            float loadFactor, boolean purgeValues) {
         super(keyType, valueType, capacity, loadFactor, purgeValues);
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/SingletonMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/SingletonMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/SingletonMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/SingletonMap.java Tue Sep 15 05:29:56 2009
@@ -27,7 +27,6 @@
 
 import org.apache.commons.collections.BoundedMap;
 import org.apache.commons.collections.KeyValue;
-import org.apache.commons.collections.MapIterator;
 import org.apache.commons.collections.OrderedMap;
 import org.apache.commons.collections.OrderedMapIterator;
 import org.apache.commons.collections.ResettableIterator;
@@ -59,16 +58,16 @@
  *
  * @author Stephen Colebourne
  */
-public class SingletonMap
-        implements OrderedMap, BoundedMap, KeyValue, Serializable, Cloneable {
+public class SingletonMap<K, V>
+        implements OrderedMap<K, V>, BoundedMap<K, V>, KeyValue<K, V>, Serializable, Cloneable {
 
     /** Serialization version */
     private static final long serialVersionUID = -8931271118676803261L;
 
     /** Singleton key */
-    private final Object key;
+    private final K key;
     /** Singleton value */
-    private Object value;
+    private V value;
 
     /**
      * Constructor that creates a map of <code>null</code> to <code>null</code>.
@@ -84,7 +83,7 @@
      * @param key  the key to use
      * @param value  the value to use
      */
-    public SingletonMap(Object key, Object value) {
+    public SingletonMap(K key, V value) {
         super();
         this.key = key;
         this.value = value;
@@ -95,7 +94,7 @@
      *
      * @param keyValue  the key value pair to use
      */
-    public SingletonMap(KeyValue keyValue) {
+    public SingletonMap(KeyValue<K, V> keyValue) {
         super();
         this.key = keyValue.getKey();
         this.value = keyValue.getValue();
@@ -106,7 +105,7 @@
      *
      * @param mapEntry  the mapEntry to use
      */
-    public SingletonMap(Map.Entry mapEntry) {
+    public SingletonMap(Map.Entry<K, V> mapEntry) {
         super();
         this.key = mapEntry.getKey();
         this.value = mapEntry.getValue();
@@ -119,12 +118,12 @@
      * @throws NullPointerException if the map is null
      * @throws IllegalArgumentException if the size is not 1
      */
-    public SingletonMap(Map map) {
+    public SingletonMap(Map<K, V> map) {
         super();
         if (map.size() != 1) {
             throw new IllegalArgumentException("The map size must be 1");
         }
-        Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
+        Map.Entry<K, V> entry = map.entrySet().iterator().next();
         this.key = entry.getKey();
         this.value = entry.getValue();
     }
@@ -136,7 +135,7 @@
      *
      * @return the key 
      */
-    public Object getKey() {
+    public K getKey() {
         return key;
     }
 
@@ -145,7 +144,7 @@
      *
      * @return the value
      */
-    public Object getValue() {
+    public V getValue() {
         return value;
     }
 
@@ -155,8 +154,8 @@
      * @param value  the new value to set
      * @return the old value
      */
-    public Object setValue(Object value) {
-        Object old = this.value;
+    public V setValue(V value) {
+        V old = this.value;
         this.value = value;
         return old;
     }
@@ -189,7 +188,7 @@
      * @param key  the key
      * @return the mapped value, null if no match
      */
-    public Object get(Object key) {
+    public V get(Object key) {
         if (isEqualKey(key)) {
             return value;
         }
@@ -247,7 +246,7 @@
      * @return the value previously mapped to this key, null if none
      * @throws IllegalArgumentException if the key does not match
      */
-    public Object put(Object key, Object value) {
+    public V put(K key, V value) {
         if (isEqualKey(key)) {
             return setValue(value);
         }
@@ -265,21 +264,21 @@
      * @throws NullPointerException if the map is null
      * @throws IllegalArgumentException if the key does not match
      */
-    public void putAll(Map map) {
+    public void putAll(Map<? extends K, ? extends V> map) {
         switch (map.size()) {
             case 0:
                 return;
-            
+
             case 1:
-                Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
+                Map.Entry<? extends K, ? extends V> entry = map.entrySet().iterator().next();
                 put(entry.getKey(), entry.getValue());
                 return;
-            
+
             default:
                 throw new IllegalArgumentException("The map size must be 0 or 1");
         }
     }
-
+    
     /**
      * Unsupported operation.
      * 
@@ -287,7 +286,7 @@
      * @return the value mapped to the removed key, null if key not in map
      * @throws UnsupportedOperationException always
      */
-    public Object remove(Object key) {
+    public V remove(Object key) {
         throw new UnsupportedOperationException();
     }
 
@@ -306,8 +305,8 @@
      * 
      * @return the entrySet view
      */
-    public Set entrySet() {
-        Map.Entry entry = new TiedMapEntry(this, getKey());
+    public Set<Map.Entry<K, V>> entrySet() {
+        Map.Entry<K, V> entry = new TiedMapEntry<K, V>(this, getKey());
         return Collections.singleton(entry);
     }
     
@@ -318,7 +317,7 @@
      * 
      * @return the keySet view
      */
-    public Set keySet() {
+    public Set<K> keySet() {
         return Collections.singleton(key);
     }
 
@@ -329,38 +328,15 @@
      * 
      * @return the values view
      */
-    public Collection values() {
-        return new SingletonValues(this);
+    public Collection<V> values() {
+        return new SingletonValues<V>(this);
     }
 
     /**
-     * Gets an iterator over the map.
-     * Changes made to the iterator using <code>setValue</code> affect this map.
-     * The <code>remove</code> method is unsupported.
-     * <p>
-     * A MapIterator returns the keys in the map. It also provides convenient
-     * methods to get the key and value, and set the value.
-     * It avoids the need to create an entrySet/keySet/values object.
-     * It also avoids creating the Map Entry object.
-     * 
-     * @return the map iterator
-     */
-    public MapIterator mapIterator() {
-        return new SingletonMapIterator(this);
-    }
-
-    // OrderedMap
-    //-----------------------------------------------------------------------
-    /**
-     * Obtains an <code>OrderedMapIterator</code> over the map.
-     * <p>
-     * A ordered map iterator is an efficient way of iterating over maps
-     * in both directions.
-     * 
-     * @return an ordered map iterator
+     * {@inheritDoc}
      */
-    public OrderedMapIterator orderedMapIterator() {
-        return new SingletonMapIterator(this);
+    public OrderedMapIterator<K, V> mapIterator() {
+        return new SingletonMapIterator<K, V>(this);
     }
 
     /**
@@ -368,7 +344,7 @@
      * 
      * @return the key
      */
-    public Object firstKey() {
+    public K firstKey() {
         return getKey();
     }
 
@@ -377,7 +353,7 @@
      * 
      * @return the key
      */
-    public Object lastKey() {
+    public K lastKey() {
         return getKey();
     }
 
@@ -387,7 +363,7 @@
      * @param key  the next key
      * @return null always
      */
-    public Object nextKey(Object key) {
+    public K nextKey(K key) {
         return null;
     }
 
@@ -397,7 +373,7 @@
      * @param key  the next key
      * @return null always
      */
-    public Object previousKey(Object key) {
+    public K previousKey(K key) {
         return null;
     }
 
@@ -426,12 +402,12 @@
     /**
      * SingletonMapIterator.
      */
-    static class SingletonMapIterator implements OrderedMapIterator, ResettableIterator {
-        private final SingletonMap parent;
+    static class SingletonMapIterator<K, V> implements OrderedMapIterator<K, V>, ResettableIterator<K> {
+        private final SingletonMap<K, V> parent;
         private boolean hasNext = true;
         private boolean canGetSet = false;
         
-        SingletonMapIterator(SingletonMap parent) {
+        SingletonMapIterator(SingletonMap<K, V> parent) {
             super();
             this.parent = parent;
         }
@@ -440,7 +416,7 @@
             return hasNext;
         }
 
-        public Object next() {
+        public K next() {
             if (hasNext == false) {
                 throw new NoSuchElementException(AbstractHashedMap.NO_NEXT_ENTRY);
             }
@@ -453,7 +429,7 @@
             return (hasNext == false);
         }
 
-        public Object previous() {
+        public K previous() {
             if (hasNext == true) {
                 throw new NoSuchElementException(AbstractHashedMap.NO_PREVIOUS_ENTRY);
             }
@@ -465,21 +441,21 @@
             throw new UnsupportedOperationException();
         }
 
-        public Object getKey() {
+        public K getKey() {
             if (canGetSet == false) {
                 throw new IllegalStateException(AbstractHashedMap.GETKEY_INVALID);
             }
             return parent.getKey();
         }
 
-        public Object getValue() {
+        public V getValue() {
             if (canGetSet == false) {
                 throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID);
             }
             return parent.getValue();
         }
 
-        public Object setValue(Object value) {
+        public V setValue(V value) {
             if (canGetSet == false) {
                 throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID);
             }
@@ -493,9 +469,8 @@
         public String toString() {
             if (hasNext) {
                 return "Iterator[]";
-            } else {
-                return "Iterator[" + getKey() + "=" + getValue() + "]";
             }
+            return "Iterator[" + getKey() + "=" + getValue() + "]";
         }
     }
     
@@ -503,11 +478,11 @@
      * Values implementation for the SingletonMap.
      * This class is needed as values is a view that must update as the map updates.
      */
-    static class SingletonValues extends AbstractSet implements Serializable {
+    static class SingletonValues<V> extends AbstractSet<V> implements Serializable {
         private static final long serialVersionUID = -3689524741863047872L;
-        private final SingletonMap parent;
+        private final SingletonMap<?, V> parent;
 
-        SingletonValues(SingletonMap parent) {
+        SingletonValues(SingletonMap<?, V> parent) {
             super();
             this.parent = parent;
         }
@@ -524,8 +499,8 @@
         public void clear() {
             throw new UnsupportedOperationException();
         }
-        public Iterator iterator() {
-            return new SingletonIterator(parent.getValue(), false);
+        public Iterator<V> iterator() {
+            return new SingletonIterator<V>(parent.getValue(), false);
         }
     }
     
@@ -535,10 +510,10 @@
      *
      * @return a shallow clone
      */
-    public Object clone() {
+    @SuppressWarnings("unchecked")
+    public SingletonMap<K, V> clone() {
         try {
-            SingletonMap cloned = (SingletonMap) super.clone();
-            return cloned;
+            return (SingletonMap<K, V>) super.clone();
         } catch (CloneNotSupportedException ex) {
             throw new InternalError();
         }
@@ -550,6 +525,7 @@
      * @param obj  the object to compare to
      * @return true if equal
      */
+    @SuppressWarnings("unchecked")
     public boolean equals(Object obj) {
         if (obj == this) {
             return true;

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java Tue Sep 15 05:29:56 2009
@@ -37,8 +37,11 @@
  *
  * @author Stephen Colebourne
  */
-public final class UnmodifiableEntrySet
-        extends AbstractSetDecorator implements Unmodifiable {
+public final class UnmodifiableEntrySet<K, V>
+        extends AbstractSetDecorator<Map.Entry<K, V>> implements Unmodifiable {
+
+    /** Serialization version */
+    private static final long serialVersionUID = 1678353579659253473L;
 
     /**
      * Factory method to create an unmodifiable set of Map Entry objects.
@@ -46,11 +49,11 @@
      * @param set  the set to decorate, must not be null
      * @throws IllegalArgumentException if set is null
      */
-    public static Set decorate(Set set) {
+    public static <K, V> Set<Map.Entry<K, V>> decorate(Set<Map.Entry<K, V>> set) {
         if (set instanceof Unmodifiable) {
             return set;
         }
-        return new UnmodifiableEntrySet(set);
+        return new UnmodifiableEntrySet<K, V>(set);
     }
 
     //-----------------------------------------------------------------------
@@ -60,16 +63,16 @@
      * @param set  the set to decorate, must not be null
      * @throws IllegalArgumentException if set is null
      */
-    private UnmodifiableEntrySet(Set set) {
+    private UnmodifiableEntrySet(Set<Map.Entry<K, V>> set) {
         super(set);
     }
 
     //-----------------------------------------------------------------------
-    public boolean add(Object object) {
+    public boolean add(Map.Entry<K, V> object) {
         throw new UnsupportedOperationException();
     }
 
-    public boolean addAll(Collection coll) {
+    public boolean addAll(Collection<? extends Map.Entry<K, V>> coll) {
         throw new UnsupportedOperationException();
     }
 
@@ -81,28 +84,30 @@
         throw new UnsupportedOperationException();
     }
 
-    public boolean removeAll(Collection coll) {
+    public boolean removeAll(Collection<?> coll) {
         throw new UnsupportedOperationException();
     }
 
-    public boolean retainAll(Collection coll) {
+    public boolean retainAll(Collection<?> coll) {
         throw new UnsupportedOperationException();
     }
 
     //-----------------------------------------------------------------------
-    public Iterator iterator() {
+    public Iterator<Map.Entry<K, V>> iterator() {
         return new UnmodifiableEntrySetIterator(collection.iterator());
     }
     
+    @SuppressWarnings("unchecked")
     public Object[] toArray() {
         Object[] array = collection.toArray();
         for (int i = 0; i < array.length; i++) {
-            array[i] = new UnmodifiableEntry((Map.Entry) array[i]);
+            array[i] = new UnmodifiableEntry((Map.Entry<K, V>) array[i]);
         }
         return array;
     }
     
-    public Object[] toArray(Object array[]) {
+    @SuppressWarnings("unchecked")
+    public <T> T[] toArray(T[] array) {
         Object[] result = array;
         if (array.length > 0) {
             // we must create a new array to handle multi-threaded situations
@@ -111,15 +116,15 @@
         }
         result = collection.toArray(result);
         for (int i = 0; i < result.length; i++) {
-            result[i] = new UnmodifiableEntry((Map.Entry) result[i]);
+            result[i] = new UnmodifiableEntry((Map.Entry<K, V>) result[i]);
         }
 
         // check to see if result should be returned straight
         if (result.length > array.length) {
-            return result;
+            return (T[]) result;
         }
 
-        // copy back into input array to fulfil the method contract
+        // copy back into input array to fulfill the method contract
         System.arraycopy(result, 0, array, 0, result.length);
         if (array.length > result.length) {
             array[result.length] = null;
@@ -131,17 +136,16 @@
     /**
      * Implementation of an entry set iterator.
      */
-    final static class UnmodifiableEntrySetIterator extends AbstractIteratorDecorator {
-        
-        protected UnmodifiableEntrySetIterator(Iterator iterator) {
+    private class UnmodifiableEntrySetIterator extends AbstractIteratorDecorator<Map.Entry<K, V>> {
+
+        protected UnmodifiableEntrySetIterator(Iterator<Map.Entry<K, V>> iterator) {
             super(iterator);
         }
-        
-        public Object next() {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            return new UnmodifiableEntry(entry);
+
+        public Map.Entry<K, V> next() {
+            return new UnmodifiableEntry(iterator.next());
         }
-        
+
         public void remove() {
             throw new UnsupportedOperationException();
         }
@@ -151,13 +155,13 @@
     /**
      * Implementation of a map entry that is unmodifiable.
      */
-    final static class UnmodifiableEntry extends AbstractMapEntryDecorator {
+    private class UnmodifiableEntry extends AbstractMapEntryDecorator<K, V> {
 
-        protected UnmodifiableEntry(Map.Entry entry) {
+        protected UnmodifiableEntry(Map.Entry<K, V> entry) {
             super(entry);
         }
 
-        public Object setValue(Object obj) {
+        public V setValue(V obj) {
             throw new UnsupportedOperationException();
         }
     }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableMap.java Tue Sep 15 05:29:56 2009
@@ -44,9 +44,9 @@
  *
  * @author Stephen Colebourne
  */
-public final class UnmodifiableMap
-        extends AbstractMapDecorator
-        implements IterableMap, Unmodifiable, Serializable {
+public final class UnmodifiableMap<K, V>
+        extends AbstractMapDecorator<K, V>
+        implements IterableMap<K, V>, Unmodifiable, Serializable {
 
     /** Serialization version */
     private static final long serialVersionUID = 2737023427269031941L;
@@ -57,11 +57,11 @@
      * @param map  the map to decorate, must not be null
      * @throws IllegalArgumentException if map is null
      */
-    public static Map decorate(Map map) {
+    public static <K, V> Map<K, V> decorate(Map<K, V> map) {
         if (map instanceof Unmodifiable) {
             return map;
         }
-        return new UnmodifiableMap(map);
+        return new UnmodifiableMap<K, V>(map);
     }
 
     //-----------------------------------------------------------------------
@@ -71,7 +71,7 @@
      * @param map  the map to decorate, must not be null
      * @throws IllegalArgumentException if map is null
      */
-    private UnmodifiableMap(Map map) {
+    private UnmodifiableMap(Map<K, V> map) {
         super(map);
     }
 
@@ -96,9 +96,10 @@
      * @throws ClassNotFoundException
      * @since Commons Collections 3.1
      */
+    @SuppressWarnings("unchecked")
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
         in.defaultReadObject();
-        map = (Map) in.readObject();
+        map = (Map<K, V>) in.readObject();
     }
 
     //-----------------------------------------------------------------------
@@ -106,40 +107,39 @@
         throw new UnsupportedOperationException();
     }
 
-    public Object put(Object key, Object value) {
+    public V put(K key, V value) {
         throw new UnsupportedOperationException();
     }
 
-    public void putAll(Map mapToCopy) {
+    public void putAll(Map<? extends K, ? extends V> mapToCopy) {
         throw new UnsupportedOperationException();
     }
 
-    public Object remove(Object key) {
+    public V remove(Object key) {
         throw new UnsupportedOperationException();
     }
 
-    public MapIterator mapIterator() {
+    public MapIterator<K, V> mapIterator() {
         if (map instanceof IterableMap) {
-            MapIterator it = ((IterableMap) map).mapIterator();
-            return UnmodifiableMapIterator.decorate(it);
-        } else {
-            MapIterator it = new EntrySetMapIterator(map);
+            MapIterator<K, V> it = ((IterableMap<K, V>) map).mapIterator();
             return UnmodifiableMapIterator.decorate(it);
         }
+        MapIterator<K, V> it = new EntrySetMapIterator<K, V>(map);
+        return UnmodifiableMapIterator.decorate(it);
     }
 
-    public Set entrySet() {
-        Set set = super.entrySet();
+    public Set<Map.Entry<K, V>> entrySet() {
+        Set<Map.Entry<K, V>> set = super.entrySet();
         return UnmodifiableEntrySet.decorate(set);
     }
 
-    public Set keySet() {
-        Set set = super.keySet();
+    public Set<K> keySet() {
+        Set<K> set = super.keySet();
         return UnmodifiableSet.decorate(set);
     }
 
-    public Collection values() {
-        Collection coll = super.values();
+    public Collection<V> values() {
+        Collection<V> coll = super.values();
         return UnmodifiableCollection.decorate(coll);
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/AbstractSerializableSetDecorator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/AbstractSerializableSetDecorator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/AbstractSerializableSetDecorator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/AbstractSerializableSetDecorator.java Tue Sep 15 05:29:56 2009
@@ -29,8 +29,8 @@
  * @author Stephen Colebourne
  * @since Commons Collections 3.1
  */
-public abstract class AbstractSerializableSetDecorator
-        extends AbstractSetDecorator
+public abstract class AbstractSerializableSetDecorator<E>
+        extends AbstractSetDecorator<E>
         implements Serializable {
 
     /** Serialization version */
@@ -39,7 +39,7 @@
     /**
      * Constructor.
      */
-    protected AbstractSerializableSetDecorator(Set set) {
+    protected AbstractSerializableSetDecorator(Set<E> set) {
         super(set);
     }
 
@@ -62,9 +62,10 @@
      * @throws IOException
      * @throws ClassNotFoundException
      */
+    @SuppressWarnings("unchecked")
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
         in.defaultReadObject();
-        collection = (Collection) in.readObject();
+        collection = (Collection<E>) in.readObject();
     }
 
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/CompositeSet.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/CompositeSet.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/CompositeSet.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/CompositeSet.java Tue Sep 15 05:29:56 2009
@@ -17,7 +17,7 @@
 package org.apache.commons.collections.set;
 
 import java.util.Collection;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.commons.collections.CollectionUtils;
@@ -35,29 +35,30 @@
  *
  * @author Brian McCallister
  */
-public class CompositeSet extends CompositeCollection implements Set {
+public class CompositeSet<E> extends CompositeCollection<E> implements Set<E> {
+
     /**
      * Create an empty CompositeSet
      */
     public CompositeSet() {
         super();
     }
-    
+
     /**
      * Create a CompositeSet with just <code>set</code> composited
      * @param set The initial set in the composite
      */
-    public CompositeSet(Set set) {
+    public CompositeSet(Set<E> set) {
         super(set);
     }
-    
+
     /**
      * Create a composite set with sets as the initial set of composited Sets
      */
-    public CompositeSet(Set[] sets) {
+    public CompositeSet(Set<E>[] sets) {
         super(sets);
     }
-    
+
     /**
      * Add a Set to this composite
      *
@@ -69,14 +70,13 @@
      * @see org.apache.commons.collections.collection.CompositeCollection.CollectionMutator
      * @see SetMutator
      */
-    public synchronized void addComposited(Collection c) {
+    public synchronized void addComposited(Collection<E> c) {
         if (!(c instanceof Set)) {
             throw new IllegalArgumentException("Collections added must implement java.util.Set");
         }
-        
-        for (Iterator i = this.getCollections().iterator(); i.hasNext();) {
-            Set set = (Set) i.next();
-            Collection intersects = CollectionUtils.intersection(set, c);
+
+        for (Set<E> set : getCollections()) {
+            Collection<E> intersects = CollectionUtils.intersection(set, c);
             if (intersects.size() > 0) {
                 if (this.mutator == null) {
                     throw new UnsupportedOperationException(
@@ -86,38 +86,48 @@
                     throw new UnsupportedOperationException(
                         "Collision adding composited collection to a CompositeSet with a CollectionMutator instead of a SetMutator");
                 }
-                ((SetMutator) this.mutator).resolveCollision(this, set, (Set) c, intersects);
+                getMutator().resolveCollision(this, set, (Set<E>) c, intersects);
                 if (CollectionUtils.intersection(set, c).size() > 0) {
                     throw new IllegalArgumentException(
                         "Attempt to add illegal entry unresolved by SetMutator.resolveCollision()");
                 }
             }
         }
-        super.addComposited(new Collection[]{c});
+        super.addComposited(c);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @SuppressWarnings("unchecked")
+    @Override
+    public List<? extends Set<E>> getCollections() {
+        return (List<Set<E>>) super.getCollections();
     }
-    
+
     /**
      * Add two sets to this composite
      *
      * @throws IllegalArgumentException if c or d does not implement java.util.Set
      */
-    public synchronized void addComposited(Collection c, Collection d) {
+    @SuppressWarnings("unchecked")
+    public synchronized void addComposited(Collection<E> c, Collection<E> d) {
         if (!(c instanceof Set)) throw new IllegalArgumentException("Argument must implement java.util.Set");
         if (!(d instanceof Set)) throw new IllegalArgumentException("Argument must implement java.util.Set");
-        this.addComposited(new Set[]{(Set) c, (Set) d});
+        this.addComposited(new Set[] { (Set<? extends E>) c, (Set<? extends E>) d });
     }
-    
+
     /**
      * Add an array of sets to this composite
      * @param comps
      * @throws IllegalArgumentException if any of the collections in comps do not implement Set
      */
-    public synchronized void addComposited(Collection[] comps) {
+    public synchronized void addComposited(Collection<E>[] comps) {
         for (int i = comps.length - 1; i >= 0; --i) {
             this.addComposited(comps[i]);
         }
     }
-    
+
     /**
      * This can receive either a <code>CompositeCollection.CollectionMutator</code>
      * or a <code>CompositeSet.SetMutator</code>. If a
@@ -125,12 +135,12 @@
      * composited sets will throw IllegalArgumentException
      * <p>
      */
-    public void setMutator(CollectionMutator mutator) {
+    public void setMutator(CollectionMutator<E> mutator) {
         super.setMutator(mutator);
     }
-    
+
     /* Set operations */
-    
+
     /**
      * If a <code>CollectionMutator</code> is defined for this CompositeSet then this
      * method will be called anyway.
@@ -139,46 +149,51 @@
      * @return true if the object is removed, false otherwise
      */
     public boolean remove(Object obj) {
-        for (Iterator i = this.getCollections().iterator(); i.hasNext();) {
-            Set set = (Set) i.next();
+        for (Set<? extends E> set : getCollections()) {
             if (set.contains(obj)) return set.remove(obj);
         }
         return false;
     }
-    
-    
+
     /**
      * @see Set#equals
      */
+    @SuppressWarnings("unchecked")
     public boolean equals(Object obj) {
         if (obj instanceof Set) {
             Set set = (Set) obj;
-            if (set.containsAll(this) && set.size() == this.size()) {
-                return true;
-            }
+            return set.containsAll(this) && set.size() == this.size();
         }
         return false;
     }
-    
+
     /**
      * @see Set#hashCode
      */
     public int hashCode() {
         int code = 0;
-        for (Iterator i = this.iterator(); i.hasNext();) {
-            Object next = i.next();
-            code += (next != null ? next.hashCode() : 0);
+        for (E e : this) {
+            code += (e == null ? 0 : e.hashCode());
         }
         return code;
     }
-    
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected SetMutator<E> getMutator() {
+        return (SetMutator<E>) super.getMutator();
+    }
+
     /**
      * Define callbacks for mutation operations.
      * <p>
      * Defining remove() on implementations of SetMutator is pointless
      * as they are never called by CompositeSet.
      */
-    public static interface SetMutator extends CompositeCollection.CollectionMutator {
+    public static interface SetMutator<E> extends CompositeCollection.CollectionMutator<E> {
+
         /**
          * <p>
          * Called when a Set is added to the CompositeSet and there is a
@@ -193,6 +208,6 @@
          * @param added the Set being added to the composite
          * @param intersects the intersection of th existing and added sets
          */
-        public void resolveCollision(CompositeSet comp, Set existing, Set added, Collection intersects);
+        public void resolveCollision(CompositeSet<E> comp, Set<E> existing, Set<E> added, Collection<E> intersects);
     }
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/MapBackedSet.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/MapBackedSet.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/MapBackedSet.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/MapBackedSet.java Tue Sep 15 05:29:56 2009
@@ -37,15 +37,16 @@
  *
  * @author Stephen Colebourne
  */
-public final class MapBackedSet implements Set, Serializable {
+public final class MapBackedSet<E, V> implements Set<E>, Serializable {
 
     /** Serialization version */
     private static final long serialVersionUID = 6723912213766056587L;
 
     /** The map being used as the backing store */
-    protected final Map map;
+    protected final Map<E, ? super V> map;
+
     /** The dummyValue to use */
-    protected final Object dummyValue;
+    protected final V dummyValue;
 
     /**
      * Factory method to create a set from a map.
@@ -53,7 +54,7 @@
      * @param map  the map to decorate, must not be null
      * @throws IllegalArgumentException if set is null
      */
-    public static Set decorate(Map map) {
+    public static <E, V> Set<E> decorate(Map<E, ? super V> map) {
         return decorate(map, null);
     }
 
@@ -64,11 +65,11 @@
      * @param dummyValue  the dummy value to use
      * @throws IllegalArgumentException if map is null
      */
-    public static Set decorate(Map map, Object dummyValue) {
+    public static <E, V> Set<E> decorate(Map<E, ? super V> map, V dummyValue) {
         if (map == null) {
             throw new IllegalArgumentException("The map must not be null");
         }
-        return new MapBackedSet(map, dummyValue);
+        return new MapBackedSet<E, V>(map, dummyValue);
     }
 
     //-----------------------------------------------------------------------
@@ -79,7 +80,7 @@
      * @param dummyValue  the dummy value to use
      * @throws IllegalArgumentException if map is null
      */
-    private MapBackedSet(Map map, Object dummyValue) {
+    private MapBackedSet(Map<E, ? super V> map, V dummyValue) {
         super();
         this.map = map;
         this.dummyValue = dummyValue;
@@ -94,7 +95,7 @@
         return map.isEmpty();
     }
 
-    public Iterator iterator() {
+    public Iterator<E> iterator() {
         return map.keySet().iterator();
     }
 
@@ -102,21 +103,20 @@
         return map.containsKey(obj);
     }
 
-    public boolean containsAll(Collection coll) {
+    public boolean containsAll(Collection<?> coll) {
         return map.keySet().containsAll(coll);
     }
 
-    public boolean add(Object obj) {
+    public boolean add(E obj) {
         int size = map.size();
         map.put(obj, dummyValue);
         return (map.size() != size);
     }
 
-    public boolean addAll(Collection coll) {
+    public boolean addAll(Collection<? extends E> coll) {
         int size = map.size();
-        for (Iterator it = coll.iterator(); it.hasNext();) {
-            Object obj = it.next();
-            map.put(obj, dummyValue);
+        for (E e : coll) {
+            map.put(e, dummyValue);
         }
         return (map.size() != size);
     }
@@ -127,11 +127,11 @@
         return (map.size() != size);
     }
 
-    public boolean removeAll(Collection coll) {
+    public boolean removeAll(Collection<?> coll) {
         return map.keySet().removeAll(coll);
     }
 
-    public boolean retainAll(Collection coll) {
+    public boolean retainAll(Collection<?> coll) {
         return map.keySet().retainAll(coll);
     }
 
@@ -143,7 +143,7 @@
         return map.keySet().toArray();
     }
 
-    public Object[] toArray(Object[] array) {
+    public <T> T[] toArray(T[] array) {
         return map.keySet().toArray(array);
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/TransformedSet.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/TransformedSet.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/TransformedSet.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/TransformedSet.java Tue Sep 15 05:29:56 2009
@@ -36,7 +36,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TransformedSet extends TransformedCollection implements Set {
+public class TransformedSet<E> extends TransformedCollection<E> implements Set<E> {
 
     /** Serialization version */
     private static final long serialVersionUID = 306127383500410386L;
@@ -52,8 +52,8 @@
      * @param transformer  the transformer to use for conversion, must not be null
      * @throws IllegalArgumentException if set or transformer is null
      */
-    public static Set decorate(Set set, Transformer transformer) {
-        return new TransformedSet(set, transformer);
+    public static <E> Set<E> decorate(Set<E> set, Transformer<? super E, ? extends E> transformer) {
+        return new TransformedSet<E>(set, transformer);
     }
     
     /**
@@ -70,13 +70,14 @@
      * @throws IllegalArgumentException if set or transformer is null
      * @since Commons Collections 3.3
      */
+    // TODO: Generics
     public static Set decorateTransform(Set set, Transformer transformer) {
         TransformedSet decorated = new TransformedSet(set, transformer);
         if (transformer != null && set != null && set.size() > 0) {
             Object[] values = set.toArray();
             set.clear();
             for(int i=0; i<values.length; i++) {
-                decorated.getCollection().add(transformer.transform(values[i]));
+                decorated.decorated().add(transformer.transform(values[i]));
             }
         }
         return decorated;
@@ -93,7 +94,7 @@
      * @param transformer  the transformer to use for conversion, must not be null
      * @throws IllegalArgumentException if set or transformer is null
      */
-    protected TransformedSet(Set set, Transformer transformer) {
+    protected TransformedSet(Set<E> set, Transformer<? super E, ? extends E> transformer) {
         super(set, transformer);
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/TransformedSortedSet.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/TransformedSortedSet.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/TransformedSortedSet.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/set/TransformedSortedSet.java Tue Sep 15 05:29:56 2009
@@ -36,7 +36,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TransformedSortedSet extends TransformedSet implements SortedSet {
+public class TransformedSortedSet<E> extends TransformedSet<E> implements SortedSet<E> {
 
     /** Serialization version */
     private static final long serialVersionUID = -1675486811351124386L;
@@ -52,8 +52,8 @@
      * @param transformer  the transformer to use for conversion, must not be null
      * @throws IllegalArgumentException if set or transformer is null
      */
-    public static SortedSet decorate(SortedSet set, Transformer transformer) {
-        return new TransformedSortedSet(set, transformer);
+    public static <E> SortedSet<E> decorate(SortedSet<E> set, Transformer<? super E, ? extends E> transformer) {
+        return new TransformedSortedSet<E>(set, transformer);
     }
     
     /**
@@ -70,13 +70,14 @@
      * @throws IllegalArgumentException if set or transformer is null
      * @since Commons Collections 3.3
      */
+     // TODO: Generics
     public static SortedSet decorateTransform(SortedSet set, Transformer transformer) {
         TransformedSortedSet decorated = new TransformedSortedSet(set, transformer);
         if (transformer != null && set != null && set.size() > 0) {
             Object[] values = set.toArray();
             set.clear();
             for(int i=0; i<values.length; i++) {
-                decorated.getCollection().add(transformer.transform(values[i]));
+                decorated.decorated().add(transformer.transform(values[i]));
             }
         }
         return decorated;
@@ -93,7 +94,7 @@
      * @param transformer  the transformer to use for conversion, must not be null
      * @throws IllegalArgumentException if set or transformer is null
      */
-    protected TransformedSortedSet(SortedSet set, Transformer transformer) {
+    protected TransformedSortedSet(SortedSet<E> set, Transformer<? super E, ? extends E> transformer) {
         super(set, transformer);
     }
 
@@ -102,37 +103,37 @@
      * 
      * @return the decorated set
      */
-    protected SortedSet getSortedSet() {
-        return (SortedSet) collection;
+    protected SortedSet<E> getSortedSet() {
+        return (SortedSet<E>) collection;
     }
 
     //-----------------------------------------------------------------------
-    public Object first() {
+    public E first() {
         return getSortedSet().first();
     }
 
-    public Object last() {
+    public E last() {
         return getSortedSet().last();
     }
 
-    public Comparator comparator() {
+    public Comparator<? super E> comparator() {
         return getSortedSet().comparator();
     }
 
     //-----------------------------------------------------------------------
-    public SortedSet subSet(Object fromElement, Object toElement) {
-        SortedSet set = getSortedSet().subSet(fromElement, toElement);
-        return new TransformedSortedSet(set, transformer);
+    public SortedSet<E> subSet(E fromElement, E toElement) {
+        SortedSet<E> set = getSortedSet().subSet(fromElement, toElement);
+        return new TransformedSortedSet<E>(set, transformer);
     }
 
-    public SortedSet headSet(Object toElement) {
-        SortedSet set = getSortedSet().headSet(toElement);
-        return new TransformedSortedSet(set, transformer);
+    public SortedSet<E> headSet(E toElement) {
+        SortedSet<E> set = getSortedSet().headSet(toElement);
+        return new TransformedSortedSet<E>(set, transformer);
     }
 
-    public SortedSet tailSet(Object fromElement) {
-        SortedSet set = getSortedSet().tailSet(fromElement);
-        return new TransformedSortedSet(set, transformer);
+    public SortedSet<E> tailSet(E fromElement) {
+        SortedSet<E> set = getSortedSet().tailSet(fromElement);
+        return new TransformedSortedSet<E>(set, transformer);
     }
 
 }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/AbstractTestObject.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/AbstractTestObject.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/AbstractTestObject.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/AbstractTestObject.java Tue Sep 15 05:29:56 2009
@@ -173,7 +173,7 @@
         Object o = makeObject();
         if (o instanceof Serializable && isTestSerialization()) {
             byte[] objekt = writeExternalFormToBytes((Serializable) o);
-            Object p = readExternalFormFromBytes(objekt);
+            readExternalFormFromBytes(objekt);
         }
     }
 



Mime
View raw message