harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r417010 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common: java/security/Provider.java org/apache/harmony/security/utils/TwoKeyHashMap.java
Date Sun, 25 Jun 2006 11:15:23 GMT
Author: ndbeyer
Date: Sun Jun 25 04:15:22 2006
New Revision: 417010

URL: http://svn.apache.org/viewvc?rev=417010&view=rev
Log:
Generification and cleanup.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/TwoKeyHashMap.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java?rev=417010&r1=417009&r2=417010&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
Sun Jun 25 04:15:22 2006
@@ -38,35 +38,16 @@
 import org.apache.harmony.security.fortress.Services;
 import org.apache.harmony.security.utils.TwoKeyHashMap;
 
-
-/**
- * @com.intel.drl.spec_ref
- * 
- */
-
 public abstract class Provider extends Properties {
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
     private static final long serialVersionUID = -4298000515446427739L;
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     private String name;
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     private double version;
 
     // String representation of the provider version number.
     private transient String versionString;
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     private String info;
 
     //The provider preference order number. 
@@ -75,20 +56,20 @@
 
     // Contains "Service.Algorithm" and Provider.Service classes added using
     // putService()
-    private transient TwoKeyHashMap serviceTable;
+    private transient TwoKeyHashMap<Service> serviceTable;
 
     // Contains "Service.Alias" and Provider.Service classes added using
     // putService()
-    private transient TwoKeyHashMap aliasTable;
+    private transient TwoKeyHashMap<Service> aliasTable;
 
     // Contains "Service.Algorithm" and Provider.Service classes added using
     // put()
-    private transient TwoKeyHashMap propertyServiceTable;
+    private transient TwoKeyHashMap<Service> propertyServiceTable;
 
     // Contains "Service.Alias" and Provider.Service classes added using put()
-    private transient TwoKeyHashMap propertyAliasTable;
+    private transient TwoKeyHashMap<Service> propertyAliasTable;
 
-    // The propeties changed via put()
+    // The properties changed via put()
     private transient Properties changedProperties;
 
     // For getService(String type, String algorithm) optimization:
@@ -100,17 +81,13 @@
     private transient String lastServiceName;
 
     // For getServices() optimization:
-    private transient Set lastServicesSet;
+    private transient Set<Service> lastServicesSet;
 
     // For getService(String type) optimization:
     private transient String lastType;
     // last Service found by type
     private transient Provider.Service lastServicesByType;
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     protected Provider(String name, double version, String info) {
         this.name = name;
         this.version = version;
@@ -163,10 +140,6 @@
         return name + " provider, Ver. " + version + " " + info;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public synchronized void clear() {
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
@@ -196,20 +169,12 @@
         servicesChanged();
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public synchronized void load(InputStream inStream) throws IOException {
         Properties tmp = new Properties();
         tmp.load(inStream);
         myPutAll(tmp);
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public synchronized void putAll(Map<?,?> t) {
 
         // Implementation note:
@@ -227,11 +192,11 @@
         if (changedProperties == null) {
             changedProperties = new Properties();
         }
-        Iterator it = t.entrySet().iterator();
+        Iterator<? extends Map.Entry<?, ?>> it = t.entrySet().iterator();
         Object key;
         Object value;
         while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
+            Map.Entry<?, ?> entry = it.next();
             key = entry.getKey();
             if (key instanceof String && ((String) key).startsWith("Provider."))
{
                 // Provider service type is reserved
@@ -250,34 +215,18 @@
         }
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public synchronized Set<Map.Entry<Object,Object>> entrySet() {
         return Collections.unmodifiableSet(super.entrySet());
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public Set<Object> keySet() {
         return Collections.unmodifiableSet(super.keySet());
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public Collection<Object> values() {
         return Collections.unmodifiableCollection(super.values());
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public synchronized Object put(Object key, Object value) {
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
@@ -301,10 +250,6 @@
         return super.put(key, value);
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public synchronized Object remove(Object key) {
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
@@ -415,8 +360,8 @@
             return lastServicesByType;
         }
         Provider.Service service;
-        for (Iterator it = getServices().iterator(); it.hasNext();) {
-            service = (Provider.Service) it.next();
+        for (Iterator<Service> it = getServices().iterator(); it.hasNext();) {
+            service = it.next();
             if (type.equals(service.type)) {
                 lastType = type;
                 lastServicesByType = service;
@@ -426,10 +371,6 @@
         return null;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public synchronized Provider.Service getService(String type,
             String algorithm) {
         if (type == null || algorithm == null) {
@@ -468,19 +409,15 @@
         return null;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public synchronized Set<Provider.Service> getServices() {
         updatePropertyServiceTable();
         if (lastServicesSet != null) {
             return lastServicesSet;
         }
         if (serviceTable != null) {
-            lastServicesSet = new HashSet(serviceTable.values());
+            lastServicesSet = new HashSet<Service>(serviceTable.values());
         } else {
-            lastServicesSet = new HashSet();
+            lastServicesSet = new HashSet<Service>();
         }
         if (propertyServiceTable != null) {
             lastServicesSet.addAll(propertyServiceTable.values());
@@ -489,10 +426,6 @@
         return lastServicesSet;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     protected synchronized void putService(Provider.Service s) {
         if (s == null) {
             throw new NullPointerException();
@@ -507,24 +440,20 @@
         }
         servicesChanged();
         if (serviceTable == null) {
-            serviceTable = new TwoKeyHashMap(128);
+            serviceTable = new TwoKeyHashMap<Service>(128);
         }
         serviceTable.put(s.type, s.algorithm.toUpperCase(), s);
         if (s.aliases != null) {
             if (aliasTable == null) {
-                aliasTable = new TwoKeyHashMap(256);
+                aliasTable = new TwoKeyHashMap<Service>(256);
             }
-            for (Iterator it = s.getAliases(); it.hasNext();) {
-                aliasTable.put(s.type, ((String) it.next()).toUpperCase(), s);
+            for (Iterator<String> it = s.getAliases(); it.hasNext();) {
+                aliasTable.put(s.type, (it.next()).toUpperCase(), s);
             }
         }
         serviceInfoToProperties(s);
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     protected synchronized void removeService(Provider.Service s) {
         if (s == null) {
             throw new NullPointerException();
@@ -538,8 +467,8 @@
             serviceTable.remove(s.type, s.algorithm.toUpperCase());
         }
         if (aliasTable != null && s.aliases != null) {
-            for (Iterator it = s.getAliases(); it.hasNext();) {
-                aliasTable.remove(s.type, ((String) it.next()).toUpperCase());
+            for (Iterator<String> it = s.getAliases(); it.hasNext();) {
+                aliasTable.remove(s.type, (it.next()).toUpperCase());
             }
         }
         serviceInfoFromProperties(s);
@@ -549,13 +478,13 @@
     private void serviceInfoToProperties(Provider.Service s) {
         super.put(s.type + "." + s.algorithm, s.className);
         if (s.aliases != null) {
-            for (Iterator i = s.aliases.iterator(); i.hasNext();) {
+            for (Iterator<String> i = s.aliases.iterator(); i.hasNext();) {
                 super.put("Alg.Alias." + s.type + "." + i.next(), s.algorithm);
             }
         }
         if (s.attributes != null) {
-            for (Iterator i = s.attributes.entrySet().iterator(); i.hasNext();) {
-                Map.Entry entry = (Map.Entry) i.next();
+            for (Iterator<Map.Entry<String, String>> i = s.attributes.entrySet().iterator();
i.hasNext();) {
+                Map.Entry<String, String> entry = i.next();
                 super.put(s.type + "." + s.algorithm + " " + entry.getKey(),
                         entry.getValue());
             }
@@ -570,13 +499,13 @@
     private void serviceInfoFromProperties(Provider.Service s) {
         super.remove(s.type + "." + s.algorithm);
         if (s.aliases != null) {
-            for (Iterator i = s.aliases.iterator(); i.hasNext();) {
+            for (Iterator<String> i = s.aliases.iterator(); i.hasNext();) {
                 super.remove("Alg.Alias." + s.type + "." + i.next());
             }
         }
         if (s.attributes != null) {
-            for (Iterator i = s.attributes.entrySet().iterator(); i.hasNext();) {
-                Map.Entry entry = (Map.Entry) i.next();
+            for (Iterator<Map.Entry<String, String>> i = s.attributes.entrySet().iterator();
i.hasNext();) {
+                Map.Entry<String, String> entry = i.next();
                 super.remove(s.type + "." + s.algorithm + " " + entry.getKey());
             }
         }
@@ -610,9 +539,9 @@
                 propertyAliasTable.remove(serviceName, aliasName.toUpperCase());
             }
             if (propertyServiceTable != null) {
-                for (Iterator it = propertyServiceTable.values().iterator(); it
+                for (Iterator<Service> it = propertyServiceTable.values().iterator();
it
                         .hasNext();) {
-                    s = (Provider.Service) it.next();
+                    s = it.next();
                     if (s.aliases.contains(aliasName)) {
                         s.aliases.remove(aliasName);
                         return;
@@ -631,12 +560,11 @@
             serviceName = k.substring(0, j);
             algorithm = k.substring(j + 1);
             if (propertyServiceTable != null) {
-                Provider.Service ser = (Provider.Service) propertyServiceTable
-                        .remove(serviceName, algorithm.toUpperCase());
+                Provider.Service ser = propertyServiceTable.remove(serviceName, algorithm.toUpperCase());
                 if (ser != null && propertyAliasTable != null
                         && ser.aliases != null) {
-                    for (Iterator it = ser.aliases.iterator(); it.hasNext();) {
-                        propertyAliasTable.remove(serviceName, ((String) it
+                    for (Iterator<String> it = ser.aliases.iterator(); it.hasNext();)
{
+                        propertyAliasTable.remove(serviceName, (it
                                 .next()).toUpperCase());
                     }
                 }
@@ -657,7 +585,7 @@
         }
     }
 
-    // Update provider Servises if the properties was changed
+    // Update provider Services if the properties was changed
     private void updatePropertyServiceTable() {
         Object _key;
         Object _value;
@@ -667,9 +595,9 @@
         if (changedProperties == null || changedProperties.isEmpty()) {
             return;
         }
-        for (Iterator it = changedProperties.entrySet().iterator(); it
+        for (Iterator<Map.Entry<Object, Object>> it = changedProperties.entrySet().iterator();
it
                 .hasNext();) {
-            Map.Entry entry = (Map.Entry) it.next();
+            Map.Entry<Object, Object> entry = it.next();
             _key = entry.getKey();
             _value = entry.getValue();
             if (_key == null || _value == null || !(_key instanceof String)
@@ -692,7 +620,7 @@
                 String algUp = algorithm.toUpperCase();
                 Object o = null;
                 if (propertyServiceTable == null) {
-                    propertyServiceTable = new TwoKeyHashMap(128);
+                    propertyServiceTable = new TwoKeyHashMap<Service>(128);
                 } else {
                     o = propertyServiceTable.get(serviceName, algUp);
                 }
@@ -700,7 +628,7 @@
                     s = (Provider.Service) o;
                     s.aliases.add(aliasName);
                     if (propertyAliasTable == null) {
-                        propertyAliasTable = new TwoKeyHashMap(256);
+                        propertyAliasTable = new TwoKeyHashMap<Service>(256);
                     }
                     propertyAliasTable.put(serviceName,
                             aliasName.toUpperCase(), s);
@@ -708,13 +636,13 @@
                     String className = (String) changedProperties
                             .get(serviceName + "." + algorithm);
                     if (className != null) {
-                        List l = new ArrayList();
+                        List<String> l = new ArrayList<String>();
                         l.add(aliasName);
                         s = new Provider.Service(this, serviceName, algorithm,
-                                className, l, new HashMap());
+                                className, l, new HashMap<String, String>());
                         propertyServiceTable.put(serviceName, algUp, s);
                         if (propertyAliasTable == null) {
-                            propertyAliasTable = new TwoKeyHashMap(256);
+                            propertyAliasTable = new TwoKeyHashMap<Service>(256);
                         }
                         propertyAliasTable.put(serviceName, aliasName
                                 .toUpperCase(), s);
@@ -740,9 +668,9 @@
                     s.className = value;
                 } else {
                     s = new Provider.Service(this, serviceName, algorithm,
-                            value, new ArrayList(), new HashMap());
+                            value, new ArrayList<String>(), new HashMap<String,
String>());
                     if (propertyServiceTable == null) {
-                        propertyServiceTable = new TwoKeyHashMap(128);
+                        propertyServiceTable = new TwoKeyHashMap<Service>(128);
                     }
                     propertyServiceTable.put(serviceName, alg, s);
 
@@ -764,12 +692,12 @@
                     String className = (String) changedProperties
                             .get(serviceName + "." + algorithm);
                     if (className != null) {
-                        Map m = new HashMap();
+                        Map<String, String> m = new HashMap<String, String>();
                         m.put(attribute, value);
                         s = new Provider.Service(this, serviceName, algorithm,
-                                className, new ArrayList(), m);
+                                className, new ArrayList<String>(), m);
                         if (propertyServiceTable == null) {
-                            propertyServiceTable = new TwoKeyHashMap(128);
+                            propertyServiceTable = new TwoKeyHashMap<Service>(128);
                         }
                         propertyServiceTable.put(serviceName, alg, s);
                     }
@@ -806,7 +734,7 @@
         if (res != null) {
             return res;
         }
-        for (Enumeration e = propertyNames(); e.hasMoreElements();) {
+        for (Enumeration<?> e = propertyNames(); e.hasMoreElements();) {
             String pname = (String) e.nextElement();
             if (key.equalsIgnoreCase(pname)) {
                 return getProperty(pname);
@@ -815,10 +743,6 @@
         return null;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     *  
-     */
     public static class Service {
         // The provider
         private Provider provider;
@@ -839,17 +763,13 @@
         private Map<String,String> attributes;
 
         // Service implementation
-        private Class implementation = null;
+        private Class<?> implementation;
 
         // For newInstance() optimization
         private String lastClassName;
 
-        /**
-         * @com.intel.drl.spec_ref
-         *  
-         */
         public Service(Provider provider, String type, String algorithm,
-                String className, List<String> aliases, Map<String,String> attributes)
{
+                String className, List<String> aliases, Map<String, String> attributes)
{
             if (provider == null || type == null || algorithm == null
                     || className == null) {
                 throw new NullPointerException();
@@ -862,42 +782,22 @@
             this.attributes = attributes;
         }
 
-        /**
-         * @com.intel.drl.spec_ref
-         *  
-         */
         public final String getType() {
             return type;
         }
 
-        /**
-         * @com.intel.drl.spec_ref
-         *  
-         */
         public final String getAlgorithm() {
             return algorithm;
         }
 
-        /**
-         * @com.intel.drl.spec_ref
-         *  
-         */
         public final Provider getProvider() {
             return provider;
         }
 
-        /**
-         * @com.intel.drl.spec_ref
-         *  
-         */
         public final String getClassName() {
             return className;
         }
 
-        /**
-         * @com.intel.drl.spec_ref
-         *  
-         */
         public final String getAttribute(String name) {
             if (name == null) {
                 throw new NullPointerException();
@@ -908,20 +808,16 @@
             return attributes.get(name);
         }
 
-        Iterator getAliases() {
+        Iterator<String> getAliases() {
             return aliases.iterator();
         }
 
-        /**
-         * @com.intel.drl.spec_ref
-         *  
-         */
         public Object newInstance(Object constructorParameter)
                 throws NoSuchAlgorithmException {
             if (implementation == null || !className.equals(lastClassName)) {
-                NoSuchAlgorithmException result = (NoSuchAlgorithmException) AccessController
-                        .doPrivileged(new java.security.PrivilegedAction() {
-                            public Object run() {
+                NoSuchAlgorithmException result = AccessController
+                        .doPrivileged(new PrivilegedAction<NoSuchAlgorithmException>()
{
+                            public NoSuchAlgorithmException run() {
                                 ClassLoader cl = provider.getClass()
                                         .getClassLoader();
                                 if (cl == null) {
@@ -974,10 +870,6 @@
             }
         }
 
-        /**
-         * @com.intel.drl.spec_ref
-         *  
-         */
         public boolean supportsParameter(Object parameter) {
             return true;
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/TwoKeyHashMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/TwoKeyHashMap.java?rev=417010&r1=417009&r2=417010&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/TwoKeyHashMap.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/TwoKeyHashMap.java
Sun Jun 25 04:15:22 2006
@@ -14,11 +14,6 @@
  *  limitations under the License.
  */
 
-/**
-* @author Boris V. Kuznetsov
-* @version $Revision$
-*/
-
 package org.apache.harmony.security.utils;
 
 import java.util.AbstractCollection;
@@ -37,18 +32,18 @@
  * Reductive hash with two keys
  * 
  */
-public class TwoKeyHashMap extends AbstractMap {
+public class TwoKeyHashMap<V> extends AbstractMap<String, V> {
 
     static final float DEFAULT_LOAD_FACTOR = 0.75f;
     static final int DEFAULT_INITIAL_SIZE = 16;
     
-    private Set entrySet;
-    private Collection values;
+    private Set<Map.Entry<String, V>> entrySet;
+    private Collection<V> values;
     private int size;
     private int arrSize;
     private transient int modCount;
     
-    private Entry[] arr;
+    private Entry<V>[] arr;
 
     private float loadFactor;
     int threshold = 0;
@@ -85,7 +80,7 @@
     /**
      * Returns a collection view of the values 
      */
-    public Collection values() {
+    public Collection<V> values() {
         if (values == null) {
             values = new ValuesCollectionImpl();
         }
@@ -95,7 +90,7 @@
     /**
      * Returns a collection view of the mappings  
      */
-    public Set entrySet() {
+    public Set<Map.Entry<String, V>> entrySet() {
         if (entrySet == null) {
             entrySet = new EntrySetImpl();
         }
@@ -117,8 +112,8 @@
      * @param key2
      * @return
      */
-    public Object remove(Object key1, Object key2) {
-        Entry e = removeEntry(key1, key2);
+    public V remove(Object key1, Object key2) {
+        Entry<V> e = removeEntry(key1, key2);
         return null != e ? e.value : null;
     }
     
@@ -129,7 +124,7 @@
      * @param value
      * @return
      */
-    public Object put(Object key1, Object key2, Object value) {
+    public V put(String key1, String key2, V value) {
         if (key1 == null && key2 == null) {
             int index = arrSize;
             if (arr[index] == null) {
@@ -138,7 +133,7 @@
                 modCount++;
                 return null;
             } else {
-                Object oldValue = arr[index].value;
+                V oldValue = arr[index].value;
                 arr[index].value = value;
                 return oldValue;
             }
@@ -146,11 +141,11 @@
 
         int hash = key1.hashCode() + key2.hashCode();
         int index = (hash & 0x7fffffff) % arrSize;
-        Entry e = arr[index];
+        Entry<V> e = arr[index];
 
         while (e != null) {
             if (hash == e.hash && key1.equals(e.getKey1()) && key2.equals(e.getKey2()))
{
-                Object oldValue = e.value;
+                V oldValue = e.value;
                 e.value = value;
                 return oldValue;
             }
@@ -176,12 +171,12 @@
         if (newArrSize < 0) {
             newArrSize = Integer.MAX_VALUE - 1;
         }
-        Entry[] newArr = new Entry[newArrSize + 1];
+        Entry<V>[] newArr = new Entry[newArrSize + 1];
 
         for (int i = 0; i < arr.length - 1; i++) {
-            Entry entry = arr[i];
+            Entry<V> entry = arr[i];
             while (entry != null) {
-                Entry next = entry.next;
+                Entry<V> next = entry.next;
 
                 int newIndex = (entry.hash & 0x7fffffff) % newArrSize;
                 entry.next = newArr[newIndex];
@@ -218,8 +213,8 @@
      * @param key2
      * @return
      */
-    public Object get(Object key1, Object key2) {
-        Entry e = findEntry(key1, key2);
+    public V get(Object key1, Object key2) {
+        Entry<V> e = findEntry(key1, key2);
         if (e != null) {
             return e.value;
         }
@@ -249,16 +244,16 @@
      * @param next
      * @return
      */
-    Entry createEntry(int hashCode, Object key1, Object key2, 
-            Object value, Entry next) {
-        return new Entry(hashCode, key1, key2, value, next);
+    Entry<V> createEntry(int hashCode, String key1, String key2, 
+            V value, Entry<V> next) {
+        return new Entry<V>(hashCode, key1, key2, value, next);
     }
 
     /**
      * Creates entries iterator
      * @return
      */
-    Iterator createEntrySetIterator() {
+    Iterator<Map.Entry<String, V>> createEntrySetIterator() {
         return new EntryIteratorImpl();
     }
 
@@ -266,7 +261,7 @@
      * Creates values iterator
      * @return
      */
-    Iterator createValueCollectionIterator() {
+    Iterator<V> createValueCollectionIterator() {
         return new ValueIteratorImpl();
     }
 
@@ -275,45 +270,49 @@
      * Entry implementation for the TwoKeyHashMap class
      * 
      */
-    static class Entry { 
+    static class Entry<V> implements Map.Entry<String, V> { 
         int hash;
-        Object key1;
-        Object key2;
-        Object value;
-        Entry next;
+        String key1;
+        String key2;
+        V value;
+        Entry<V> next;
 
-        public Entry(int hash, Object key1, Object key2, Object value, Entry next) {
+        public Entry(int hash, String key1, String key2, V value, Entry<V> next) {
             this.hash = hash;
             this.key1 = key1;
             this.key2 = key2;
             this.value = value;
             this.next = next;
         }
+        
+        public String getKey() {
+            return key1 + key2;
+        }
 
-        public Object getKey1() {
+        public String getKey1() {
             return key1;
         }
         
-        public Object getKey2() {
+        public String getKey2() {
             return key2;
         }
 
-        public Object getValue() {
+        public V getValue() {
             return value;
         }
 
-        public Object setValue(Object value) {
-            Object oldValue = this.value;
+        public V setValue(V value) {
+            V oldValue = this.value;
             this.value = value;
             return oldValue;
         }
 
         public boolean equals(Object obj) {
-            if (!(obj instanceof Map.Entry)) {
+            if (!(obj instanceof Entry)) {
                 return false;
             }
 
-            Entry e = (Entry) obj;
+            Entry<?> e = (Entry<?>) obj;
             Object getKey1 = e.getKey1();
             Object getKey2 = e.getKey2();
             Object getValue = e.getValue();
@@ -336,7 +335,7 @@
         
     }
     
-    class EntrySetImpl extends AbstractSet {
+    class EntrySetImpl extends AbstractSet<Map.Entry<String, V>> {
         public int size() {
             return size;
         }
@@ -354,13 +353,13 @@
                 return false;
             }
 
-            Entry entry = (Entry) obj;
-            Entry entry2 = findEntry(entry.getKey1(), entry.getKey2());
+            Entry<?> entry = (Entry<?>) obj;
+            Entry<V> entry2 = findEntry(entry.getKey1(), entry.getKey2());
             if (entry2 == null) {
                 return false;
             }
             Object value = entry.getValue();
-            Object value2 = entry.getValue();
+            Object value2 = entry2.getValue();
             return value == null ? value2 == null : value.equals(value2);
         }
 
@@ -371,19 +370,19 @@
             return removeEntry(((Entry) obj).getKey1(), ((Entry)obj).getKey2()) != null;
         }
 
-        public Iterator iterator() {
+        public Iterator<Map.Entry<String, V>> iterator() {
             return createEntrySetIterator();
         }
     }
 
     // Iterates Entries inside the Map
-    class EntryIteratorImpl implements Iterator {
+    class EntryIteratorImpl implements Iterator<Map.Entry<String, V>> {
         private int startModCount;
-        private boolean found = false;
+        private boolean found;
         private int curr = -1;
         private int returned_index = -1;
-        private Entry curr_entry = null;
-        private Entry returned_entry = null;
+        private Entry<V> curr_entry;
+        private Entry<V> returned_entry;
 
         EntryIteratorImpl() {
             startModCount = modCount;
@@ -407,7 +406,7 @@
             return found = (curr_entry != null);
         }
 
-        public Object next() {
+        public Map.Entry<String, V> next() {
             if (modCount != startModCount) {
                 throw new ConcurrentModificationException();
             }
@@ -418,7 +417,7 @@
             found = false;
             returned_index = curr;
             returned_entry = curr_entry;
-            return curr_entry;
+            return (Map.Entry<String, V>)curr_entry;
         }
 
         public void remove() {
@@ -430,8 +429,8 @@
                 throw new ConcurrentModificationException();
             }
 
-            Entry p = null;
-            Entry e = arr[returned_index];
+            Entry<V> p = null;
+            Entry<V> e = arr[returned_index];
             while (e != returned_entry) {
                 p = e;
                 e = e.next;
@@ -447,14 +446,15 @@
             returned_index = -1;
         }
     }
-    private final Entry findEntry(Object key1, Object key2) {
+    
+    private final Entry<V> findEntry(Object key1, Object key2) {
         if (key1 == null && key2 == null) {
             return arr[arrSize];
         }
 
         int hash = key1.hashCode() + key2.hashCode();
         int index = (hash & 0x7fffffff) % arrSize;
-        Entry e = arr[index];
+        Entry<V> e = arr[index];
 
         while (e != null) {
             if (hash == e.hash && key1.equals(e.getKey1()) && key2.equals(e.getKey2()))
{
@@ -466,11 +466,11 @@
     }
     
     // Removes entry
-    private final Entry removeEntry(Object key1, Object key2) {
+    private final Entry<V> removeEntry(Object key1, Object key2) {
         if (key1 == null && key2 == null) {
             int index = arrSize;
             if (arr[index] != null) {
-                Entry ret = arr[index];
+                Entry<V> ret = arr[index];
                 arr[index] = null;
                 size--;
                 modCount++;
@@ -482,8 +482,8 @@
         int hash = key1.hashCode() + key2.hashCode();
         int index = (hash & 0x7fffffff) % arrSize;
 
-        Entry e = arr[index];
-        Entry prev = e;
+        Entry<V> e = arr[index];
+        Entry<V> prev = e;
         while (e != null) {
             if (hash == e.hash && key1.equals(e.getKey1()) && key2.equals(e.getKey2()))
{
                 if (prev == e) {
@@ -505,7 +505,7 @@
     /**
      * An instance is returned by the values() call.
      */
-    class ValuesCollectionImpl extends AbstractCollection {
+    class ValuesCollectionImpl extends AbstractCollection<V> {
         public int size() {
             return size;
         }
@@ -518,7 +518,7 @@
             return size == 0;
         }
 
-        public Iterator iterator() {
+        public Iterator<V> iterator() {
             return createValueCollectionIterator();
         }
         
@@ -526,9 +526,25 @@
             return containsValue(obj);
         }
     }
-    class ValueIteratorImpl extends EntryIteratorImpl {
-        public Object next() {
-            return ((Entry) super.next()).value;
+    
+    class ValueIteratorImpl implements Iterator<V> {
+        private EntryIteratorImpl itr;
+
+        ValueIteratorImpl() {
+            super();
+            this.itr = new EntryIteratorImpl();
+        }
+
+        public V next() {
+            return itr.next().getValue();
+        }
+
+        public void remove() {
+            itr.remove();
+        }
+
+        public boolean hasNext() {
+            return itr.hasNext();
         }
     }
 }



Mime
View raw message