commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r738956 [15/34] - in /commons/proper/collections/branches/collections_jdk5_branch/src: java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/ java/org/apache/commons/collections/bidimap/ java/org/apache/commons/collec...
Date Thu, 29 Jan 2009 18:48:47 GMT
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/Flat3Map.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/Flat3Map.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/Flat3Map.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/Flat3Map.java Thu Jan 29 18:48:37 2009
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -64,7 +64,7 @@
  * <strong>Note that Flat3Map is not synchronized and is not thread-safe.</strong>
  * If you wish to use this map from multiple threads concurrently, you must use
  * appropriate synchronization. The simplest approach is to wrap this map
- * using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw 
+ * using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw
  * exceptions when accessed by concurrent threads without synchronization.
  *
  * @since Commons Collections 3.0
@@ -72,7 +72,7 @@
  *
  * @author Stephen Colebourne
  */
-public class Flat3Map implements IterableMap, Serializable, Cloneable {
+public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneable {
 
     /** Serialization version */
     private static final long serialVersionUID = -6701087419741928296L;
@@ -86,19 +86,19 @@
     /** Hash, used while in flat mode */
     private transient int hash3;
     /** Key, used while in flat mode */
-    private transient Object key1;
+    private transient K key1;
     /** Key, used while in flat mode */
-    private transient Object key2;
+    private transient K key2;
     /** Key, used while in flat mode */
-    private transient Object key3;
+    private transient K key3;
     /** Value, used while in flat mode */
-    private transient Object value1;
+    private transient V value1;
     /** Value, used while in flat mode */
-    private transient Object value2;
+    private transient V value2;
     /** Value, used while in flat mode */
-    private transient Object value3;
+    private transient V value3;
     /** Map, used while in delegate mode */
-    private transient AbstractHashedMap delegateMap;
+    private transient AbstractHashedMap<K, V> delegateMap;
 
     /**
      * Constructor.
@@ -113,7 +113,7 @@
      * @param map  the map to copy
      * @throws NullPointerException if the map is null
      */
-    public Flat3Map(Map map) {
+    public Flat3Map(Map<? extends K, ? extends V> map) {
         super();
         putAll(map);
     }
@@ -121,11 +121,11 @@
     //-----------------------------------------------------------------------
     /**
      * Gets the value mapped to the key specified.
-     * 
+     *
      * @param key  the key
      * @return the mapped value, null if no match
      */
-    public Object get(Object key) {
+    public V get(Object key) {
         if (delegateMap != null) {
             return delegateMap.get(key);
         }
@@ -158,7 +158,7 @@
 
     /**
      * Gets the size of the map.
-     * 
+     *
      * @return the size
      */
     public int size() {
@@ -170,7 +170,7 @@
 
     /**
      * Checks whether the map is currently empty.
-     * 
+     *
      * @return true if the map is currently size zero
      */
     public boolean isEmpty() {
@@ -180,7 +180,7 @@
     //-----------------------------------------------------------------------
     /**
      * Checks whether the map contains the specified key.
-     * 
+     *
      * @param key  the key to search for
      * @return true if the map contains the key
      */
@@ -215,7 +215,7 @@
 
     /**
      * Checks whether the map contains the specified value.
-     * 
+     *
      * @param value  the value to search for
      * @return true if the map contains the key
      */
@@ -248,12 +248,12 @@
     //-----------------------------------------------------------------------
     /**
      * Puts a key-value mapping into this map.
-     * 
+     *
      * @param key  the key to add
      * @param value  the value to add
      * @return the value previously mapped to this key, null if none
      */
-    public Object put(Object key, Object value) {
+    public V put(K key, V value) {
         if (delegateMap != null) {
             return delegateMap.put(key, value);
         }
@@ -262,19 +262,19 @@
             switch (size) {  // drop through
                 case 3:
                     if (key3 == null) {
-                        Object old = value3;
+                        V old = value3;
                         value3 = value;
                         return old;
                     }
                 case 2:
                     if (key2 == null) {
-                        Object old = value2;
+                        V old = value2;
                         value2 = value;
                         return old;
                     }
                 case 1:
                     if (key1 == null) {
-                        Object old = value1;
+                        V old = value1;
                         value1 = value;
                         return old;
                     }
@@ -285,26 +285,26 @@
                 switch (size) {  // drop through
                     case 3:
                         if (hash3 == hashCode && key.equals(key3)) {
-                            Object old = value3;
+                            V old = value3;
                             value3 = value;
                             return old;
                         }
                     case 2:
                         if (hash2 == hashCode && key.equals(key2)) {
-                            Object old = value2;
+                            V old = value2;
                             value2 = value;
                             return old;
                         }
                     case 1:
                         if (hash1 == hashCode && key.equals(key1)) {
-                            Object old = value1;
+                            V old = value1;
                             value1 = value;
                             return old;
                         }
                 }
             }
         }
-        
+
         // add new mapping
         switch (size) {
             default:
@@ -333,11 +333,11 @@
 
     /**
      * Puts all the values from the specified map into this map.
-     * 
+     *
      * @param map  the map to add
      * @throws NullPointerException if the map is null
      */
-    public void putAll(Map map) {
+    public void putAll(Map<? extends K, ? extends V> map) {
         int size = map.size();
         if (size == 0) {
             return;
@@ -347,8 +347,7 @@
             return;
         }
         if (size < 4) {
-            for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
-                Map.Entry entry = (Map.Entry) it.next();
+            for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
                 put(entry.getKey(), entry.getValue());
             }
         } else {
@@ -370,7 +369,7 @@
             case 1:
                 delegateMap.put(key1, value1);
         }
-        
+
         size = 0;
         hash1 = hash2 = hash3 = 0;
         key1 = key2 = key3 = null;
@@ -387,17 +386,17 @@
      * @return a new AbstractHashedMap or subclass
      * @since Commons Collections 3.1
      */
-    protected AbstractHashedMap createDelegateMap() {
-        return new HashedMap();
+    protected AbstractHashedMap<K, V> createDelegateMap() {
+        return new HashedMap<K, V>();
     }
 
     /**
      * Removes the specified mapping from this map.
-     * 
+     *
      * @param key  the mapping to remove
      * @return the value mapped to the removed key, null if key not in map
      */
-    public Object remove(Object key) {
+    public V remove(Object key) {
         if (delegateMap != null) {
             return delegateMap.remove(key);
         }
@@ -408,7 +407,7 @@
             switch (size) {  // drop through
                 case 3:
                     if (key3 == null) {
-                        Object old = value3;
+                        V old = value3;
                         hash3 = 0;
                         key3 = null;
                         value3 = null;
@@ -416,7 +415,7 @@
                         return old;
                     }
                     if (key2 == null) {
-                        Object old = value3;
+                        V old = value3;
                         hash2 = hash3;
                         key2 = key3;
                         value2 = value3;
@@ -427,7 +426,7 @@
                         return old;
                     }
                     if (key1 == null) {
-                        Object old = value3;
+                        V old = value3;
                         hash1 = hash3;
                         key1 = key3;
                         value1 = value3;
@@ -440,7 +439,7 @@
                     return null;
                 case 2:
                     if (key2 == null) {
-                        Object old = value2;
+                        V old = value2;
                         hash2 = 0;
                         key2 = null;
                         value2 = null;
@@ -448,7 +447,7 @@
                         return old;
                     }
                     if (key1 == null) {
-                        Object old = value2;
+                        V old = value2;
                         hash1 = hash2;
                         key1 = key2;
                         value1 = value2;
@@ -461,7 +460,7 @@
                     return null;
                 case 1:
                     if (key1 == null) {
-                        Object old = value1;
+                        V old = value1;
                         hash1 = 0;
                         key1 = null;
                         value1 = null;
@@ -475,7 +474,7 @@
                 switch (size) {  // drop through
                     case 3:
                         if (hash3 == hashCode && key.equals(key3)) {
-                            Object old = value3;
+                            V old = value3;
                             hash3 = 0;
                             key3 = null;
                             value3 = null;
@@ -483,7 +482,7 @@
                             return old;
                         }
                         if (hash2 == hashCode && key.equals(key2)) {
-                            Object old = value3;
+                            V old = value3;
                             hash2 = hash3;
                             key2 = key3;
                             value2 = value3;
@@ -494,7 +493,7 @@
                             return old;
                         }
                         if (hash1 == hashCode && key.equals(key1)) {
-                            Object old = value3;
+                            V old = value3;
                             hash1 = hash3;
                             key1 = key3;
                             value1 = value3;
@@ -507,7 +506,7 @@
                         return null;
                     case 2:
                         if (hash2 == hashCode && key.equals(key2)) {
-                            Object old = value2;
+                            V old = value2;
                             hash2 = 0;
                             key2 = null;
                             value2 = null;
@@ -515,7 +514,7 @@
                             return old;
                         }
                         if (hash1 == hashCode && key.equals(key1)) {
-                            Object old = value2;
+                            V old = value2;
                             hash1 = hash2;
                             key1 = key2;
                             value1 = value2;
@@ -528,7 +527,7 @@
                         return null;
                     case 1:
                         if (hash1 == hashCode && key.equals(key1)) {
-                            Object old = value1;
+                            V old = value1;
                             hash1 = 0;
                             key1 = null;
                             value1 = null;
@@ -566,28 +565,28 @@
      * 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() {
+    public MapIterator<K, V> mapIterator() {
         if (delegateMap != null) {
             return delegateMap.mapIterator();
         }
         if (size == 0) {
-            return EmptyMapIterator.INSTANCE;
+            return EmptyMapIterator.<K, V>getInstance();
         }
-        return new FlatMapIterator(this);
+        return new FlatMapIterator<K, V>(this);
     }
 
     /**
      * FlatMapIterator
      */
-    static class FlatMapIterator implements MapIterator, ResettableIterator {
-        private final Flat3Map parent;
+    static class FlatMapIterator<K, V> implements MapIterator<K, V>, ResettableIterator<K> {
+        private final Flat3Map<K, V> parent;
         private int nextIndex = 0;
         private boolean canRemove = false;
-        
-        FlatMapIterator(Flat3Map parent) {
+
+        FlatMapIterator(Flat3Map<K, V> parent) {
             super();
             this.parent = parent;
         }
@@ -596,7 +595,7 @@
             return (nextIndex < parent.size);
         }
 
-        public Object next() {
+        public K next() {
             if (hasNext() == false) {
                 throw new NoSuchElementException(AbstractHashedMap.NO_NEXT_ENTRY);
             }
@@ -614,7 +613,7 @@
             canRemove = false;
         }
 
-        public Object getKey() {
+        public K getKey() {
             if (canRemove == false) {
                 throw new IllegalStateException(AbstractHashedMap.GETKEY_INVALID);
             }
@@ -629,7 +628,7 @@
             throw new IllegalStateException("Invalid map index");
         }
 
-        public Object getValue() {
+        public V getValue() {
             if (canRemove == false) {
                 throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID);
             }
@@ -644,13 +643,13 @@
             throw new IllegalStateException("Invalid map index");
         }
 
-        public Object setValue(Object value) {
+        public V setValue(V value) {
             if (canRemove == false) {
                 throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID);
             }
-            Object old = getValue();
+            V old = getValue();
             switch (nextIndex) {
-                case 3: 
+                case 3:
                     parent.value3 = value;
                     break;
                 case 2:
@@ -662,44 +661,43 @@
             }
             return old;
         }
-        
+
         public void reset() {
             nextIndex = 0;
             canRemove = false;
         }
-        
+
         public String toString() {
             if (canRemove) {
                 return "Iterator[" + getKey() + "=" + getValue() + "]";
-            } else {
-                return "Iterator[]";
             }
+            return "Iterator[]";
         }
     }
-    
+
     /**
      * Gets the entrySet view of the map.
      * Changes made to the view affect this map.
-     * The Map Entry is not an independent object and changes as the 
+     * The Map Entry is not an independent object and changes as the
      * iterator progresses.
      * To simply iterate through the entries, use {@link #mapIterator()}.
-     * 
+     *
      * @return the entrySet view
      */
-    public Set entrySet() {
+    public Set<Map.Entry<K, V>> entrySet() {
         if (delegateMap != null) {
             return delegateMap.entrySet();
         }
-        return new EntrySet(this);
+        return new EntrySet<K, V>(this);
     }
-    
+
     /**
      * EntrySet
      */
-    static class EntrySet extends AbstractSet {
-        private final Flat3Map parent;
-        
-        EntrySet(Flat3Map parent) {
+    static class EntrySet<K, V> extends AbstractSet<Map.Entry<K, V>> {
+        private final Flat3Map<K, V> parent;
+
+        EntrySet(Flat3Map<K, V> parent) {
             super();
             this.parent = parent;
         }
@@ -707,43 +705,42 @@
         public int size() {
             return parent.size();
         }
-        
+
         public void clear() {
             parent.clear();
         }
-        
+
         public boolean remove(Object obj) {
             if (obj instanceof Map.Entry == false) {
                 return false;
             }
-            Map.Entry entry = (Map.Entry) obj;
+            Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
             Object key = entry.getKey();
             boolean result = parent.containsKey(key);
             parent.remove(key);
             return result;
         }
 
-        public Iterator iterator() {
+        public Iterator<Map.Entry<K, V>> iterator() {
             if (parent.delegateMap != null) {
                 return parent.delegateMap.entrySet().iterator();
             }
             if (parent.size() == 0) {
-                return EmptyIterator.INSTANCE;
+                return EmptyIterator.<Map.Entry<K, V>>getInstance();
             }
-            return new EntrySetIterator(parent);
+            return new EntrySetIterator<K, V>(parent);
         }
     }
 
-    /**
-     * EntrySetIterator and MapEntry
-     */
-    static class EntrySetIterator implements Iterator, Map.Entry {
-        private final Flat3Map parent;
+    static abstract class EntryIterator<K, V> implements Map.Entry<K, V> {
+        private final Flat3Map<K, V> parent;
         private int nextIndex = 0;
-        private boolean canRemove = false;
-        
-        EntrySetIterator(Flat3Map parent) {
-            super();
+        protected boolean canRemove = false;
+
+        /**
+         * Create a new Flat3Map.EntryIterator.
+         */
+        public EntryIterator(Flat3Map<K, V> parent) {
             this.parent = parent;
         }
 
@@ -751,7 +748,7 @@
             return (nextIndex < parent.size);
         }
 
-        public Object next() {
+        public Map.Entry<K, V> nextEntry() {
             if (hasNext() == false) {
                 throw new NoSuchElementException(AbstractHashedMap.NO_NEXT_ENTRY);
             }
@@ -769,7 +766,7 @@
             canRemove = false;
         }
 
-        public Object getKey() {
+        public K getKey() {
             if (canRemove == false) {
                 throw new IllegalStateException(AbstractHashedMap.GETKEY_INVALID);
             }
@@ -784,7 +781,7 @@
             throw new IllegalStateException("Invalid map index");
         }
 
-        public Object getValue() {
+        public V getValue() {
             if (canRemove == false) {
                 throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID);
             }
@@ -799,13 +796,13 @@
             throw new IllegalStateException("Invalid map index");
         }
 
-        public Object setValue(Object value) {
+        public V setValue(V value) {
             if (canRemove == false) {
                 throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID);
             }
-            Object old = getValue();
+            V old = getValue();
             switch (nextIndex) {
-                case 3: 
+                case 3:
                     parent.value3 = value;
                     break;
                 case 2:
@@ -817,7 +814,21 @@
             }
             return old;
         }
-        
+    }
+
+    /**
+     * EntrySetIterator and MapEntry
+     */
+    static class EntrySetIterator<K, V> extends EntryIterator<K, V> implements Iterator<Map.Entry<K, V>> {
+
+        EntrySetIterator(Flat3Map<K, V> parent) {
+            super(parent);
+        }
+
+        public Map.Entry<K, V> next() {
+            return nextEntry();
+        }
+
         public boolean equals(Object obj) {
             if (canRemove == false) {
                 return false;
@@ -825,13 +836,13 @@
             if (obj instanceof Map.Entry == false) {
                 return false;
             }
-            Map.Entry other = (Map.Entry) obj;
+            Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
             Object key = getKey();
             Object value = getValue();
             return (key == null ? other.getKey() == null : key.equals(other.getKey())) &&
                    (value == null ? other.getValue() == null : value.equals(other.getValue()));
         }
-        
+
         public int hashCode() {
             if (canRemove == false) {
                 return 0;
@@ -841,37 +852,36 @@
             return (key == null ? 0 : key.hashCode()) ^
                    (value == null ? 0 : value.hashCode());
         }
-        
+
         public String toString() {
             if (canRemove) {
                 return getKey() + "=" + getValue();
-            } else {
-                return "";
             }
+            return "";
         }
     }
-    
+
     /**
      * Gets the keySet view of the map.
      * Changes made to the view affect this map.
      * To simply iterate through the keys, use {@link #mapIterator()}.
-     * 
+     *
      * @return the keySet view
      */
-    public Set keySet() {
+    public Set<K> keySet() {
         if (delegateMap != null) {
             return delegateMap.keySet();
         }
-        return new KeySet(this);
+        return new KeySet<K>(this);
     }
 
     /**
      * KeySet
      */
-    static class KeySet extends AbstractSet {
-        private final Flat3Map parent;
-        
-        KeySet(Flat3Map parent) {
+    static class KeySet<K> extends AbstractSet<K> {
+        private final Flat3Map<K, ?> parent;
+
+        KeySet(Flat3Map<K, ?> parent) {
             super();
             this.parent = parent;
         }
@@ -879,11 +889,11 @@
         public int size() {
             return parent.size();
         }
-        
+
         public void clear() {
             parent.clear();
         }
-        
+
         public boolean contains(Object key) {
             return parent.containsKey(key);
         }
@@ -894,53 +904,54 @@
             return result;
         }
 
-        public Iterator iterator() {
+        public Iterator<K> iterator() {
             if (parent.delegateMap != null) {
                 return parent.delegateMap.keySet().iterator();
             }
             if (parent.size() == 0) {
-                return EmptyIterator.INSTANCE;
+                return EmptyIterator.<K>getInstance();
             }
-            return new KeySetIterator(parent);
+            return new KeySetIterator<K>(parent);
         }
     }
 
     /**
      * KeySetIterator
      */
-    static class KeySetIterator extends EntrySetIterator {
-        
-        KeySetIterator(Flat3Map parent) {
-            super(parent);
+    static class KeySetIterator<K> extends EntryIterator<K, Object> implements Iterator<K>{
+
+        @SuppressWarnings("unchecked")
+        KeySetIterator(Flat3Map<K, ?> parent) {
+            super((Flat3Map<K, Object>) parent);
         }
 
-        public Object next() {
-            super.next();
+        public K next() {
+            nextEntry();
             return getKey();
         }
     }
-    
+
     /**
      * Gets the values view of the map.
      * Changes made to the view affect this map.
      * To simply iterate through the values, use {@link #mapIterator()}.
-     * 
+     *
      * @return the values view
      */
-    public Collection values() {
+    public Collection<V> values() {
         if (delegateMap != null) {
             return delegateMap.values();
         }
-        return new Values(this);
+        return new Values<V>(this);
     }
 
     /**
      * Values
      */
-    static class Values extends AbstractCollection {
-        private final Flat3Map parent;
-        
-        Values(Flat3Map parent) {
+    static class Values<V> extends AbstractCollection<V> {
+        private final Flat3Map<?, V> parent;
+
+        Values(Flat3Map<?, V> parent) {
             super();
             this.parent = parent;
         }
@@ -948,37 +959,38 @@
         public int size() {
             return parent.size();
         }
-        
+
         public void clear() {
             parent.clear();
         }
-        
+
         public boolean contains(Object value) {
             return parent.containsValue(value);
         }
 
-        public Iterator iterator() {
+        public Iterator<V> iterator() {
             if (parent.delegateMap != null) {
                 return parent.delegateMap.values().iterator();
             }
             if (parent.size() == 0) {
-                return EmptyIterator.INSTANCE;
+                return EmptyIterator.<V>getInstance();
             }
-            return new ValuesIterator(parent);
+            return new ValuesIterator<V>(parent);
         }
     }
 
     /**
      * ValuesIterator
      */
-    static class ValuesIterator extends EntrySetIterator {
-        
-        ValuesIterator(Flat3Map parent) {
-            super(parent);
+    static class ValuesIterator<V> extends EntryIterator<Object, V> implements Iterator<V> {
+
+        @SuppressWarnings("unchecked")
+        ValuesIterator(Flat3Map<?, V> parent) {
+            super((Flat3Map<Object, V>) parent);
         }
 
-        public Object next() {
-            super.next();
+        public V next() {
+            nextEntry();
             return getValue();
         }
     }
@@ -990,7 +1002,7 @@
     private void writeObject(ObjectOutputStream out) throws IOException {
         out.defaultWriteObject();
         out.writeInt(size());
-        for (MapIterator it = mapIterator(); it.hasNext();) {
+        for (MapIterator<?, ?> it = mapIterator(); it.hasNext();) {
             out.writeObject(it.next());  // key
             out.writeObject(it.getValue());  // value
         }
@@ -999,6 +1011,7 @@
     /**
      * Read the map in using a custom routine.
      */
+    @SuppressWarnings("unchecked")
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
         in.defaultReadObject();
         int count = in.readInt();
@@ -1006,7 +1019,7 @@
             delegateMap = createDelegateMap();
         }
         for (int i = count; i > 0; i--) {
-            put(in.readObject(), in.readObject());
+            put((K) in.readObject(), (V) in.readObject());
         }
     }
 
@@ -1017,11 +1030,12 @@
      * @return a shallow clone
      * @since Commons Collections 3.1
      */
-    public Object clone() {
+    @SuppressWarnings("unchecked")
+    public Flat3Map<K, V> clone() {
         try {
-            Flat3Map cloned = (Flat3Map) super.clone();
+            Flat3Map<K, V> cloned = (Flat3Map<K, V>) super.clone();
             if (cloned.delegateMap != null) {
-                cloned.delegateMap = (HashedMap) cloned.delegateMap.clone();
+                cloned.delegateMap = (HashedMap<K, V>) cloned.delegateMap.clone();
             }
             return cloned;
         } catch (CloneNotSupportedException ex) {
@@ -1031,7 +1045,7 @@
 
     /**
      * Compares this map with another.
-     * 
+     *
      * @param obj  the object to compare to
      * @return true if equal
      */
@@ -1045,7 +1059,7 @@
         if (obj instanceof Map == false) {
             return false;
         }
-        Map other = (Map) obj;
+        Map<?, ?> other = (Map<?, ?>) obj;
         if (size != other.size()) {
             return false;
         }
@@ -1083,7 +1097,7 @@
 
     /**
      * Gets the standard Map hashCode.
-     * 
+     *
      * @return the hash code defined in the Map interface
      */
     public int hashCode() {
@@ -1104,7 +1118,7 @@
 
     /**
      * Gets the map as a String.
-     * 
+     *
      * @return a string version of the map
      */
     public String toString() {

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/HashedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/HashedMap.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/HashedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/HashedMap.java Thu Jan 29 18:48:37 2009
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,14 +26,14 @@
  * A <code>Map</code> implementation that is a general purpose alternative
  * to <code>HashMap</code>.
  * <p>
- * This implementation improves on the JDK1.4 HashMap by adding the 
+ * This implementation improves on the JDK1.4 HashMap by adding the
  * {@link org.apache.commons.collections.MapIterator MapIterator}
  * functionality and many methods for subclassing.
  * <p>
  * <strong>Note that HashedMap is not synchronized and is not thread-safe.</strong>
  * If you wish to use this map from multiple threads concurrently, you must use
  * appropriate synchronization. The simplest approach is to wrap this map
- * using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw 
+ * using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw
  * exceptions when accessed by concurrent threads without synchronization.
  *
  * @since Commons Collections 3.0
@@ -41,12 +41,12 @@
  *
  * @author Stephen Colebourne
  */
-public class HashedMap
-        extends AbstractHashedMap implements Serializable, Cloneable {
+public class HashedMap<K, V>
+        extends AbstractHashedMap<K, V> implements Serializable, Cloneable {
 
     /** Serialisation version */
     private static final long serialVersionUID = -1788199231038721040L;
-    
+
     /**
      * Constructs a new empty map with default size and load factor.
      */
@@ -55,7 +55,7 @@
     }
 
     /**
-     * Constructs a new, empty map with the specified initial capacity. 
+     * Constructs a new, empty map with the specified initial capacity.
      *
      * @param initialCapacity  the initial capacity
      * @throws IllegalArgumentException if the initial capacity is less than one
@@ -66,7 +66,7 @@
 
     /**
      * Constructs a new, empty map with the specified initial capacity and
-     * load factor. 
+     * load factor.
      *
      * @param initialCapacity  the initial capacity
      * @param loadFactor  the load factor
@@ -83,7 +83,7 @@
      * @param map  the map to copy
      * @throws NullPointerException if the map is null
      */
-    public HashedMap(Map map) {
+    public HashedMap(Map<K, V> map) {
         super(map);
     }
 
@@ -93,10 +93,10 @@
      *
      * @return a shallow clone
      */
-    public Object clone() {
-        return super.clone();
+    public HashedMap<K, V> clone() {
+        return (HashedMap<K, V>) super.clone();
     }
-    
+
     /**
      * Write the map out using a custom routine.
      */
@@ -112,5 +112,5 @@
         in.defaultReadObject();
         doReadObject(in);
     }
-    
+
 }

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/IdentityMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/IdentityMap.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/IdentityMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/IdentityMap.java Thu Jan 29 18:48:37 2009
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,7 +32,7 @@
  * <strong>Note that IdentityMap is not synchronized and is not thread-safe.</strong>
  * If you wish to use this map from multiple threads concurrently, you must use
  * appropriate synchronization. The simplest approach is to wrap this map
- * using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw 
+ * using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw
  * exceptions when accessed by concurrent threads without synchronization.
  *
  * @since Commons Collections 3.0
@@ -41,8 +41,8 @@
  * @author java util HashMap
  * @author Stephen Colebourne
  */
-public class IdentityMap
-        extends AbstractHashedMap implements Serializable, Cloneable {
+public class IdentityMap<K, V>
+        extends AbstractHashedMap<K, V> implements Serializable, Cloneable {
 
     /** Serialisation version */
     private static final long serialVersionUID = 2028493495224302329L;
@@ -55,7 +55,7 @@
     }
 
     /**
-     * Constructs a new, empty map with the specified initial capacity. 
+     * Constructs a new, empty map with the specified initial capacity.
      *
      * @param initialCapacity  the initial capacity
      * @throws IllegalArgumentException if the initial capacity is less than one
@@ -66,7 +66,7 @@
 
     /**
      * Constructs a new, empty map with the specified initial capacity and
-     * load factor. 
+     * load factor.
      *
      * @param initialCapacity  the initial capacity
      * @param loadFactor  the load factor
@@ -83,7 +83,7 @@
      * @param map  the map to copy
      * @throws NullPointerException if the map is null
      */
-    public IdentityMap(Map map) {
+    public IdentityMap(Map<K, V> map) {
         super(map);
     }
 
@@ -91,18 +91,18 @@
     /**
      * Gets the hash code for the key specified.
      * This implementation uses the identity hash code.
-     * 
+     *
      * @param key  the key to get a hash code for
      * @return the hash code
      */
     protected int hash(Object key) {
         return System.identityHashCode(key);
     }
-    
+
     /**
      * Compares two keys for equals.
      * This implementation uses <code>==</code>.
-     * 
+     *
      * @param key1  the first key to compare
      * @param key2  the second key to compare
      * @return true if equal by identity
@@ -110,11 +110,11 @@
     protected boolean isEqualKey(Object key1, Object key2) {
         return (key1 == key2);
     }
-    
+
     /**
      * Compares two values for equals.
      * This implementation uses <code>==</code>.
-     * 
+     *
      * @param value1  the first value to compare
      * @param value2  the second value to compare
      * @return true if equal by identity
@@ -122,31 +122,31 @@
     protected boolean isEqualValue(Object value1, Object value2) {
         return (value1 == value2);
     }
-    
+
     /**
      * Creates an entry to store the data.
      * This implementation creates an IdentityEntry instance.
-     * 
+     *
      * @param next  the next entry in sequence
      * @param hashCode  the hash code to use
      * @param key  the key to store
      * @param value  the value to store
      * @return the newly created entry
      */
-    protected HashEntry createEntry(HashEntry next, int hashCode, Object key, Object value) {
-        return new IdentityEntry(next, hashCode, key, value);
+    protected IdentityEntry<K, V> createEntry(HashEntry<K, V> next, int hashCode, K key, V value) {
+        return new IdentityEntry<K, V>(next, hashCode, key, value);
     }
-    
+
     //-----------------------------------------------------------------------
     /**
      * HashEntry
      */
-    protected static class IdentityEntry extends HashEntry {
-        
-        protected IdentityEntry(HashEntry next, int hashCode, Object key, Object value) {
+    protected static class IdentityEntry<K, V> extends HashEntry<K, V> {
+
+        protected IdentityEntry(HashEntry<K, V> next, int hashCode, K key, V value) {
             super(next, hashCode, key, value);
         }
-        
+
         public boolean equals(Object obj) {
             if (obj == this) {
                 return true;
@@ -154,28 +154,28 @@
             if (obj instanceof Map.Entry == false) {
                 return false;
             }
-            Map.Entry other = (Map.Entry) obj;
+            Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
             return
                 (getKey() == other.getKey()) &&
                 (getValue() == other.getValue());
         }
-        
+
         public int hashCode() {
             return System.identityHashCode(getKey()) ^
                    System.identityHashCode(getValue());
         }
     }
-    
+
     //-----------------------------------------------------------------------
     /**
      * Clones the map without cloning the keys or values.
      *
      * @return a shallow clone
      */
-    public Object clone() {
-        return super.clone();
+    public IdentityMap<K, V> clone() {
+        return (IdentityMap<K, V>) super.clone();
     }
-    
+
     /**
      * Write the map out using a custom routine.
      */
@@ -191,5 +191,5 @@
         in.defaultReadObject();
         doReadObject(in);
     }
-    
+
 }

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LRUMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LRUMap.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LRUMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LRUMap.java Thu Jan 29 18:48:37 2009
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -35,7 +35,7 @@
  * <p>
  * The map implements <code>OrderedMap</code> and entries may be queried using
  * the bidirectional <code>OrderedMapIterator</code>. The order returned is
- * least recently used to most recently used. Iterators from map views can 
+ * least recently used to most recently used. Iterators from map views can
  * also be cast to <code>OrderedIterator</code> if required.
  * <p>
  * All the available iterators can be reset back to the start by casting to
@@ -44,7 +44,7 @@
  * <strong>Note that LRUMap is not synchronized and is not thread-safe.</strong>
  * If you wish to use this map from multiple threads concurrently, you must use
  * appropriate synchronization. The simplest approach is to wrap this map
- * using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw 
+ * using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw
  * <code>NullPointerException</code>'s when accessed by concurrent threads.
  *
  * @since Commons Collections 3.0 (previously in main package v1.0)
@@ -56,14 +56,14 @@
  * @author Mike Pettypiece
  * @author Mario Ivankovits
  */
-public class LRUMap
-        extends AbstractLinkedMap implements BoundedMap, Serializable, Cloneable {
-    
+public class LRUMap<K, V>
+        extends AbstractLinkedMap<K, V> implements BoundedMap<K, V>, Serializable, Cloneable {
+
     /** Serialisation version */
     private static final long serialVersionUID = -612114643488955218L;
     /** Default maximum size */
     protected static final int DEFAULT_MAX_SIZE = 100;
-    
+
     /** Maximum size */
     private transient int maxSize;
     /** Scan behaviour */
@@ -100,7 +100,7 @@
 
     /**
      * Constructs a new, empty map with the specified initial capacity and
-     * load factor. 
+     * load factor.
      *
      * @param maxSize  the maximum size of the map, -1 for no limit,
      * @param loadFactor  the load factor
@@ -140,7 +140,7 @@
      * @throws NullPointerException if the map is null
      * @throws IllegalArgumentException if the map is empty
      */
-    public LRUMap(Map map) {
+    public LRUMap(Map<K, V> map) {
         this(map, false);
     }
 
@@ -155,7 +155,7 @@
      * @throws IllegalArgumentException if the map is empty
      * @since Commons Collections 3.1
      */
-    public LRUMap(Map map, boolean scanUntilRemovable) {
+    public LRUMap(Map<K, V> map, boolean scanUntilRemovable) {
         this(map.size(), DEFAULT_LOAD_FACTOR, scanUntilRemovable);
         putAll(map);
     }
@@ -166,12 +166,12 @@
      * <p>
      * This operation changes the position of the key in the map to the
      * most recently used position (first).
-     * 
+     *
      * @param key  the key
      * @return the mapped value, null if no match
      */
-    public Object get(Object key) {
-        LinkEntry entry = (LinkEntry) getEntry(key);
+    public V get(Object key) {
+        LinkEntry<K, V> entry = getEntry(key);
         if (entry == null) {
             return null;
         }
@@ -184,10 +184,10 @@
      * Moves an entry to the MRU position at the end of the list.
      * <p>
      * This implementation moves the updated entry to the end of the list.
-     * 
+     *
      * @param entry  the entry to update
      */
-    protected void moveToMRU(LinkEntry entry) {
+    protected void moveToMRU(LinkEntry<K, V> entry) {
         if (entry.after != header) {
             modCount++;
             // remove
@@ -203,21 +203,21 @@
                 " (please report this to commons-dev@jakarta.apache.org)");
         }
     }
-    
+
     /**
      * Updates an existing key-value mapping.
      * <p>
      * This implementation moves the updated entry to the top of the list
      * using {@link #moveToMRU(AbstractLinkedMap.LinkEntry)}.
-     * 
+     *
      * @param entry  the entry to update
      * @param newValue  the new value to store
      */
-    protected void updateEntry(HashEntry entry, Object newValue) {
-        moveToMRU((LinkEntry) entry);  // handles modCount
+    protected void updateEntry(HashEntry<K, V> entry, V newValue) {
+        moveToMRU((LinkEntry<K, V>) entry);  // handles modCount
         entry.setValue(newValue);
     }
-    
+
     /**
      * Adds a new key-value mapping into this map.
      * <p>
@@ -227,15 +227,15 @@
      * From Commons Collections 3.1 this method uses {@link #isFull()} rather
      * than accessing <code>size</code> and <code>maxSize</code> directly.
      * It also handles the scanUntilRemovable functionality.
-     * 
+     *
      * @param hashIndex  the index into the data array to store at
      * @param hashCode  the hash code of the key to add
      * @param key  the key to add
      * @param value  the value to add
      */
-    protected void addMapping(int hashIndex, int hashCode, Object key, Object value) {
+    protected void addMapping(int hashIndex, int hashCode, K key, V value) {
         if (isFull()) {
-            LinkEntry reuse = header.after;
+            LinkEntry<K, V> reuse = header.after;
             boolean removeLRUEntry = false;
             if (scanUntilRemovable) {
                 while (reuse != header && reuse != null) {
@@ -255,7 +255,7 @@
             } else {
                 removeLRUEntry = removeLRU(reuse);
             }
-            
+
             if (removeLRUEntry) {
                 if (reuse == null) {
                     throw new IllegalStateException(
@@ -272,27 +272,27 @@
             super.addMapping(hashIndex, hashCode, key, value);
         }
     }
-    
+
     /**
      * Reuses an entry by removing it and moving it to a new place in the map.
      * <p>
      * This method uses {@link #removeEntry}, {@link #reuseEntry} and {@link #addEntry}.
-     * 
+     *
      * @param entry  the entry to reuse
      * @param hashIndex  the index into the data array to store at
      * @param hashCode  the hash code of the key to add
      * @param key  the key to add
      * @param value  the value to add
      */
-    protected void reuseMapping(LinkEntry entry, int hashIndex, int hashCode, Object key, Object value) {
+    protected void reuseMapping(LinkEntry<K, V> entry, int hashIndex, int hashCode, K key, V value) {
         // find the entry before the entry specified in the hash table
         // remember that the parameters (except the first) refer to the new entry,
         // not the old one
         try {
             int removeIndex = hashIndex(entry.hashCode, data.length);
-            HashEntry[] tmp = data;  // may protect against some sync issues
-            HashEntry loop = tmp[removeIndex];
-            HashEntry previous = null;
+            HashEntry<K, V>[] tmp = data;  // may protect against some sync issues
+            HashEntry<K, V> loop = tmp[removeIndex];
+            HashEntry<K, V> previous = null;
             while (loop != entry && loop != null) {
                 previous = loop;
                 loop = loop.next;
@@ -304,7 +304,7 @@
                     " Please check that your keys are immutable, and that you have used synchronization properly." +
                     " If so, then please report this to commons-dev@jakarta.apache.org as a bug.");
             }
-            
+
             // reuse the entry
             modCount++;
             removeEntry(entry, removeIndex, previous);
@@ -318,7 +318,7 @@
                     " If so, then please report this to commons-dev@jakarta.apache.org as a bug.");
         }
     }
-    
+
     /**
      * Subclass method to control removal of the least recently used entry from the map.
      * <p>
@@ -349,10 +349,10 @@
      * <p>
      * NOTE: Commons Collections 3.0 passed the wrong entry to this method.
      * This is fixed in version 3.1 onwards.
-     * 
+     *
      * @param entry  the entry to be removed
      */
-    protected boolean removeLRU(LinkEntry entry) {
+    protected boolean removeLRU(LinkEntry<K, V> entry) {
         return true;
     }
 
@@ -392,10 +392,10 @@
      *
      * @return a shallow clone
      */
-    public Object clone() {
-        return super.clone();
+    public LRUMap<K, V> clone() {
+        return (LRUMap<K, V>) super.clone();
     }
-    
+
     /**
      * Write the map out using a custom routine.
      */
@@ -411,7 +411,7 @@
         in.defaultReadObject();
         doReadObject(in);
     }
-    
+
     /**
      * Writes the data necessary for <code>put()</code> to work in deserialization.
      */
@@ -427,5 +427,5 @@
         maxSize = in.readInt();
         super.doReadObject(in);
     }
-    
+
 }

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LazyMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LazyMap.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LazyMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LazyMap.java Thu Jan 29 18:48:37 2009
@@ -62,9 +62,7 @@
  * @author Stephen Colebourne
  * @author Paul Jack
  */
-public class LazyMap<K,V>
-        extends AbstractMapDecorator<K,V>
-        implements Map<K,V>, Serializable {
+public class LazyMap<K, V> extends AbstractMapDecorator<K, V> implements Map<K, V>, Serializable {
 
     /** Serialization version */
     private static final long serialVersionUID = 7990956402564206740L;

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LinkedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LinkedMap.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LinkedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LinkedMap.java Thu Jan 29 18:48:37 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 key 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/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/ListOrderedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/ListOrderedMap.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/ListOrderedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/ListOrderedMap.java Thu Jan 29 18:48:37 2009
@@ -32,11 +32,10 @@
 import java.util.NoSuchElementException;
 import java.util.Set;
 
-import org.apache.commons.collections.MapIterator;
 import org.apache.commons.collections.OrderedMap;
 import org.apache.commons.collections.OrderedMapIterator;
 import org.apache.commons.collections.ResettableIterator;
-import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
+import org.apache.commons.collections.iterators.AbstractUntypedIteratorDecorator;
 import org.apache.commons.collections.keyvalue.AbstractMapEntry;
 import org.apache.commons.collections.list.UnmodifiableList;
 
@@ -68,15 +67,15 @@
  * @author Stephen Colebourne
  * @author Matt Benson
  */
-public class ListOrderedMap
-        extends AbstractMapDecorator
-        implements OrderedMap, Serializable {
+public class ListOrderedMap<K, V>
+        extends AbstractMapDecorator<K, V>
+        implements OrderedMap<K, V>, Serializable {
 
     /** Serialization version */
     private static final long serialVersionUID = 2728177751851003750L;
 
     /** Internal list to hold the sequence of objects */
-    protected final List insertOrder = new ArrayList();
+    protected final List<K> insertOrder = new ArrayList<K>();
 
     /**
      * Factory method to create an ordered map.
@@ -86,8 +85,8 @@
      * @param map  the map to decorate, must not be null
      * @throws IllegalArgumentException if map is null
      */
-    public static OrderedMap decorate(Map map) {
-        return new ListOrderedMap(map);
+    public static <K, V> OrderedMap<K, V> decorate(Map<K, V> map) {
+        return new ListOrderedMap<K, V>(map);
     }
 
     //-----------------------------------------------------------------------
@@ -98,7 +97,7 @@
      * @since Commons Collections 3.1
      */
     public ListOrderedMap() {
-        this(new HashMap());
+        this(new HashMap<K, V>());
     }
 
     /**
@@ -107,7 +106,7 @@
      * @param map  the map to decorate, must not be null
      * @throws IllegalArgumentException if map is null
      */
-    protected ListOrderedMap(Map map) {
+    protected ListOrderedMap(Map<K, V> map) {
         super(map);
         insertOrder.addAll(decorated().keySet());
     }
@@ -133,6 +132,7 @@
      * @throws ClassNotFoundException
      * @since Commons Collections 3.1
      */
+    @SuppressWarnings("unchecked")
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
         in.defaultReadObject();
         map = (Map) in.readObject();
@@ -140,12 +140,8 @@
 
     // Implement OrderedMap
     //-----------------------------------------------------------------------
-    public MapIterator mapIterator() {
-        return orderedMapIterator();
-    }
-
-    public OrderedMapIterator orderedMapIterator() {
-        return new ListOrderedMapIterator(this);
+    public OrderedMapIterator<K, V> mapIterator() {
+        return new ListOrderedMapIterator<K, V>(this);
     }
 
     /**
@@ -154,7 +150,7 @@
      * @return the first key currently in this map
      * @throws NoSuchElementException if this map is empty
      */
-    public Object firstKey() {
+    public K firstKey() {
         if (size() == 0) {
             throw new NoSuchElementException("Map is empty");
         }
@@ -167,7 +163,7 @@
      * @return the last key currently in this map
      * @throws NoSuchElementException if this map is empty
      */
-    public Object lastKey() {
+    public K lastKey() {
         if (size() == 0) {
             throw new NoSuchElementException("Map is empty");
         }
@@ -181,7 +177,7 @@
      * @param key  the key to find previous for
      * @return the next key, null if no match or at start
      */
-    public Object nextKey(Object key) {
+    public K nextKey(Object key) {
         int index = insertOrder.indexOf(key);
         if (index >= 0 && index < size() - 1) {
             return insertOrder.get(index + 1);
@@ -196,7 +192,7 @@
      * @param key  the key to find previous for
      * @return the previous key, null if no match or at start
      */
-    public Object previousKey(Object key) {
+    public K previousKey(Object key) {
         int index = insertOrder.indexOf(key);
         if (index > 0) {
             return insertOrder.get(index - 1);
@@ -205,27 +201,26 @@
     }
 
     //-----------------------------------------------------------------------
-    public Object put(Object key, Object value) {
+    public V put(K key, V value) {
         if (decorated().containsKey(key)) {
             // re-adding doesn't change order
             return decorated().put(key, value);
         } else {
             // first add, so add to both map and list
-            Object result = decorated().put(key, value);
+            V result = decorated().put(key, value);
             insertOrder.add(key);
             return result;
         }
     }
 
-    public void putAll(Map map) {
-        for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
-            Map.Entry entry = (Map.Entry) it.next();
+    public void putAll(Map<? extends K, ? extends V> map) {
+        for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
             put(entry.getKey(), entry.getValue());
         }
     }
 
-    public Object remove(Object key) {
-        Object result = decorated().remove(key);
+    public V remove(Object key) {
+        V result = decorated().remove(key);
         insertOrder.remove(key);
         return result;
     }
@@ -244,8 +239,8 @@
      * @see #keyList()
      * @return the fully modifiable collection view over the keys
      */
-    public Set keySet() {
-        return new KeySetView(this);
+    public Set<K> keySet() {
+        return new KeySetView<K>(this);
     }
 
     /**
@@ -258,7 +253,7 @@
      * @return the unmodifiable list view over the keys
      * @since Commons Collections 3.2
      */
-    public List keyList() {
+    public List<K> keyList() {
         return UnmodifiableList.decorate(insertOrder);
     }
 
@@ -273,8 +268,8 @@
      * @see #valueList()
      * @return the fully modifiable collection view over the values
      */
-    public Collection values() {
-        return new ValuesView(this);
+    public Collection<V> values() {
+        return new ValuesView<V>(this);
     }
 
     /**
@@ -287,8 +282,8 @@
      * @return the partially modifiable list view over the values
      * @since Commons Collections 3.2
      */
-    public List valueList() {
-        return new ValuesView(this);
+    public List<V> valueList() {
+        return new ValuesView<V>(this);
     }
 
     /**
@@ -298,8 +293,8 @@
      *
      * @return the fully modifiable set view over the entries
      */
-    public Set entrySet() {
-        return new EntrySetView(this, this.insertOrder);
+    public Set<Map.Entry<K, V>> entrySet() {
+        return new EntrySetView<K, V>(this, this.insertOrder);
     }
 
     //-----------------------------------------------------------------------
@@ -315,11 +310,9 @@
         StringBuffer buf = new StringBuffer();
         buf.append('{');
         boolean first = true;
-        Iterator it = entrySet().iterator();
-        while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
-            Object key = entry.getKey();
-            Object value = entry.getValue();
+        for (Map.Entry<K, V> entry : entrySet()) {
+            K key = entry.getKey();
+            V value = entry.getValue();
             if (first) {
                 first = false;
             } else {
@@ -341,7 +334,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 insertOrder.get(index);
     }
     
@@ -352,7 +345,7 @@
      * @return the key at the specified index
      * @throws IndexOutOfBoundsException if the index is invalid
      */
-    public Object getValue(int index) {
+    public V getValue(int index) {
         return get(insertOrder.get(index));
     }
     
@@ -374,8 +367,8 @@
      * @throws IndexOutOfBoundsException if the index is invalid
      * @since Commons Collections 3.2
      */
-    public Object setValue(int index, Object value) {
-        Object key = insertOrder.get(index);
+    public V setValue(int index, V value) {
+        K key = insertOrder.get(index);
         return put(key, value);
     }
 
@@ -398,10 +391,10 @@
      * @throws IndexOutOfBoundsException if the index is out of range
      * @since Commons Collections 3.2
      */
-    public Object put(int index, Object key, Object value) {
-        Map m = decorated();
+    public V put(int index, K key, V value) {
+        Map<K, V> m = decorated();
         if (m.containsKey(key)) {
-            Object result = m.remove(key);
+            V result = m.remove(key);
             int pos = insertOrder.indexOf(key);
             insertOrder.remove(pos);
             if (pos < index) {
@@ -424,7 +417,7 @@
      * @return the removed value, 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));
     }
 
@@ -445,17 +438,18 @@
      * @see #keySet()
      * @return The ordered list of keys.  
      */
-    public List asList() {
+    public List<K> asList() {
         return keyList();
     }
 
     //-----------------------------------------------------------------------
-    static class ValuesView extends AbstractList {
-        private final ListOrderedMap parent;
+    static class ValuesView<V> extends AbstractList<V> {
+        private final ListOrderedMap<Object, V> parent;
 
-        ValuesView(ListOrderedMap parent) {
+        @SuppressWarnings("unchecked")
+        ValuesView(ListOrderedMap<?, V> parent) {
             super();
-            this.parent = parent;
+            this.parent = (ListOrderedMap<Object, V>) parent;
         }
 
         public int size() {
@@ -470,34 +464,35 @@
             this.parent.clear();
         }
 
-        public Iterator iterator() {
-            return new AbstractIteratorDecorator(parent.entrySet().iterator()) {
-                public Object next() {
-                    return ((Map.Entry) iterator.next()).getValue();
+        public Iterator<V> iterator() {
+            return new AbstractUntypedIteratorDecorator<Map.Entry<Object, V>, V>(parent.entrySet().iterator()) {
+                public V next() {
+                    return getIterator().next().getValue();
                 }
             };
         }
 
-        public Object get(int index) {
+        public V get(int index) {
             return this.parent.getValue(index);
         }
 
-        public Object set(int index, Object value) {
+        public V set(int index, V value) {
             return this.parent.setValue(index, value);
         }
 
-        public Object remove(int index) {
+        public V remove(int index) {
             return this.parent.remove(index);
         }
     }
 
     //-----------------------------------------------------------------------
-    static class KeySetView extends AbstractSet {
-        private final ListOrderedMap parent;
+    static class KeySetView<K> extends AbstractSet<K> {
+        private final ListOrderedMap<K, Object> parent;
 
-        KeySetView(ListOrderedMap parent) {
+        @SuppressWarnings("unchecked")
+        KeySetView(ListOrderedMap<K, ?> parent) {
             super();
-            this.parent = parent;
+            this.parent = (ListOrderedMap<K, Object>) parent;
         }
 
         public int size() {
@@ -512,28 +507,28 @@
             this.parent.clear();
         }
 
-        public Iterator iterator() {
-            return new AbstractIteratorDecorator(parent.entrySet().iterator()) {
-                public Object next() {
-                    return ((Map.Entry) super.next()).getKey();
+        public Iterator<K> iterator() {
+            return new AbstractUntypedIteratorDecorator<Map.Entry<K, Object>, K>(parent.entrySet().iterator()) {
+                public K next() {
+                    return getIterator().next().getKey();
                 }
             };
         }
     }
 
     //-----------------------------------------------------------------------    
-    static class EntrySetView extends AbstractSet {
-        private final ListOrderedMap parent;
-        private final List insertOrder;
-        private Set entrySet;
+    static class EntrySetView<K, V> extends AbstractSet<Map.Entry<K, V>> {
+        private final ListOrderedMap<K, V> parent;
+        private final List<K> insertOrder;
+        private Set<Map.Entry<K, V>> entrySet;
 
-        public EntrySetView(ListOrderedMap parent, List insertOrder) {
+        public EntrySetView(ListOrderedMap<K, V> parent, List<K> insertOrder) {
             super();
             this.parent = parent;
             this.insertOrder = insertOrder;
         }
 
-        private Set getEntrySet() {
+        private Set<Map.Entry<K, V>> getEntrySet() {
             if (entrySet == null) {
                 entrySet = parent.decorated().entrySet();
             }
@@ -551,16 +546,17 @@
             return getEntrySet().contains(obj);
         }
 
-        public boolean containsAll(Collection coll) {
+        public boolean containsAll(Collection<?> coll) {
             return getEntrySet().containsAll(coll);
         }
 
+        @SuppressWarnings("unchecked")
         public boolean remove(Object obj) {
             if (obj instanceof Map.Entry == false) {
                 return false;
             }
             if (getEntrySet().contains(obj)) {
-                Object key = ((Map.Entry) obj).getKey();
+                Object key = ((Map.Entry<K, V>) obj).getKey();
                 parent.remove(key);
                 return true;
             }
@@ -570,14 +566,14 @@
         public void clear() {
             this.parent.clear();
         }
-        
+
         public boolean equals(Object obj) {
             if (obj == this) {
                 return true;
             }
             return getEntrySet().equals(obj);
         }
-        
+
         public int hashCode() {
             return getEntrySet().hashCode();
         }
@@ -585,25 +581,25 @@
         public String toString() {
             return getEntrySet().toString();
         }
-        
-        public Iterator iterator() {
-            return new ListOrderedIterator(parent, insertOrder);
+
+        public Iterator<Map.Entry<K, V>> iterator() {
+            return new ListOrderedIterator<K, V>(parent, insertOrder);
         }
     }
-    
+
     //-----------------------------------------------------------------------
-    static class ListOrderedIterator extends AbstractIteratorDecorator {
-        private final ListOrderedMap parent;
-        private Object last = null;
+    static class ListOrderedIterator<K, V> extends AbstractUntypedIteratorDecorator<K, Map.Entry<K, V>> {
+        private final ListOrderedMap<K, V> parent;
+        private K last = null;
         
-        ListOrderedIterator(ListOrderedMap parent, List insertOrder) {
+        ListOrderedIterator(ListOrderedMap<K, V> parent, List<K> insertOrder) {
             super(insertOrder.iterator());
             this.parent = parent;
         }
-        
-        public Object next() {
-            last = super.next();
-            return new ListOrderedMapEntry(parent, last);
+
+        public Map.Entry<K, V> next() {
+            last = getIterator().next();
+            return new ListOrderedMapEntry<K, V>(parent, last);
         }
 
         public void remove() {
@@ -611,43 +607,43 @@
             parent.decorated().remove(last);
         }
     }
-    
+
     //-----------------------------------------------------------------------
-    static class ListOrderedMapEntry extends AbstractMapEntry {
-        private final ListOrderedMap parent;
-        
-        ListOrderedMapEntry(ListOrderedMap parent, Object key) {
+    static class ListOrderedMapEntry<K, V> extends AbstractMapEntry<K, V> {
+        private final ListOrderedMap<K, V> parent;
+
+        ListOrderedMapEntry(ListOrderedMap<K, V> parent, K key) {
             super(key, null);
             this.parent = parent;
         }
-        
-        public Object getValue() {
+
+        public V getValue() {
             return parent.get(key);
         }
 
-        public Object setValue(Object value) {
+        public V setValue(V value) {
             return parent.decorated().put(key, value);
         }
     }
 
     //-----------------------------------------------------------------------
-    static class ListOrderedMapIterator implements OrderedMapIterator, ResettableIterator {
-        private final ListOrderedMap parent;
-        private ListIterator iterator;
-        private Object last = null;
+    static class ListOrderedMapIterator<K, V> implements OrderedMapIterator<K, V>, ResettableIterator<K> {
+        private final ListOrderedMap<K, V> parent;
+        private ListIterator<K> iterator;
+        private K last = null;
         private boolean readable = false;
-        
-        ListOrderedMapIterator(ListOrderedMap parent) {
+
+        ListOrderedMapIterator(ListOrderedMap<K, V> parent) {
             super();
             this.parent = parent;
             this.iterator = parent.insertOrder.listIterator();
         }
-        
+
         public boolean hasNext() {
             return iterator.hasNext();
         }
-        
-        public Object next() {
+
+        public K next() {
             last = iterator.next();
             readable = true;
             return last;
@@ -656,13 +652,13 @@
         public boolean hasPrevious() {
             return iterator.hasPrevious();
         }
-        
-        public Object previous() {
+
+        public K previous() {
             last = iterator.previous();
             readable = true;
             return last;
         }
-        
+
         public void remove() {
             if (readable == false) {
                 throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID);
@@ -671,41 +667,40 @@
             parent.map.remove(last);
             readable = false;
         }
-        
-        public Object getKey() {
+
+        public K getKey() {
             if (readable == false) {
                 throw new IllegalStateException(AbstractHashedMap.GETKEY_INVALID);
             }
             return last;
         }
 
-        public Object getValue() {
+        public V getValue() {
             if (readable == false) {
                 throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID);
             }
             return parent.get(last);
         }
-        
-        public Object setValue(Object value) {
+
+        public V setValue(V value) {
             if (readable == false) {
                 throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID);
             }
             return parent.map.put(last, value);
         }
-        
+
         public void reset() {
             iterator = parent.insertOrder.listIterator();
             last = null;
             readable = false;
         }
-        
+
         public String toString() {
             if (readable == true) {
                 return "Iterator[" + getKey() + "=" + getValue() + "]";
-            } else {
-                return "Iterator[]";
             }
+            return "Iterator[]";
         }
     }
-    
+
 }



Mime
View raw message