I'm checking this in.

This updates the prefs code to use generics.

This particular change caught an actual bug;
AbstractPreferences.cachedChildren was implemented incorrectly.

Tom

2006-12-18  Tom Tromey  <[EMAIL PROTECTED]>

        * java/util/prefs/Preferences.java (getFactory): Genericized.
        * java/util/prefs/AbstractPreferences.java (childCache): Genericized.
        (nodeListeners): Likewise.
        (preferenceListeners): Likewise.
        (cachedChildren): Rewrote.
        (childrenNames): Updated.
        (addNodeChangeListener): Likewise.
        (addPreferenceChangeListener): Likewise.
        * gnu/java/util/prefs/gconf/GConfNativePeer.java (getKeys):
        Genericized.
        (getChildrenNodes): Likewise.
        (gconf_client_all_nodes): Likewise.
        (gconf_client_all_keys): Likewise.
        * gnu/java/util/prefs/MemoryBasedPreferences.java (entries):
        Genericized.
        (keysSpi): Likewise.
        (getSpi): Likewise.
        * gnu/java/util/prefs/GConfBasedPreferences.java (childrenNamesSpi):
        Genericized.
        (keysSpi): Likewise.
        (postorderRemove): Likewise.
        * gnu/java/util/prefs/EventDispatcher.java (queue): Genericized.
        (run): Updated.

Index: gnu/java/util/prefs/EventDispatcher.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/util/prefs/EventDispatcher.java,v
retrieving revision 1.2
diff -u -r1.2 EventDispatcher.java
--- gnu/java/util/prefs/EventDispatcher.java    6 Jul 2006 18:17:37 -0000       
1.2
+++ gnu/java/util/prefs/EventDispatcher.java    17 Dec 2006 22:30:16 -0000
@@ -53,7 +53,7 @@
   // This is a queue of events to dispatch.  This thread waits on
   // the queue and when notified will remove events until the queue
   // is empty.
-  private static final ArrayList queue = new ArrayList();
+  private static final ArrayList<Runnable> queue = new ArrayList<Runnable>();
 
   // FIXME: this thread probably ought to go in some classpath-internal
   // ThreadGroup.  But we don't have that yet.
@@ -81,7 +81,7 @@
                     // Ignore.
                   }
               }
-            r = (Runnable) queue.remove(0);
+            r = queue.remove(0);
           }
         // Invoke outside the synchronization, so that 
         // we aren't blocking other threads from posting events.
Index: gnu/java/util/prefs/GConfBasedPreferences.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/util/prefs/GConfBasedPreferences.java,v
retrieving revision 1.3
diff -u -r1.3 GConfBasedPreferences.java
--- gnu/java/util/prefs/GConfBasedPreferences.java      27 Sep 2006 13:52:45 
-0000      1.3
+++ gnu/java/util/prefs/GConfBasedPreferences.java      17 Dec 2006 22:30:17 
-0000
@@ -41,7 +41,6 @@
 
 import java.security.Permission;
 
-import java.util.Iterator;
 import java.util.List;
 import java.util.prefs.AbstractPreferences;
 import java.util.prefs.BackingStoreException;
@@ -185,7 +184,7 @@
    */
   protected String[] childrenNamesSpi() throws BackingStoreException
   {
-    List nodeList = backend.getChildrenNodes(this.node);
+    List<String> nodeList = backend.getChildrenNodes(this.node);
     String[] nodes = new String[nodeList.size()];
     nodeList.toArray(nodes);
 
@@ -228,7 +227,7 @@
    */
   protected String[] keysSpi() throws BackingStoreException
   {
-    List keyList = backend.getKeys(this.node);
+    List<String> keyList = backend.getKeys(this.node);
     String[] keys = new String[keyList.size()];
     keyList.toArray(keys);
 
@@ -246,31 +245,24 @@
     try
       {
         // gets the listing of directories in this node
-        List dirs = backend.getChildrenNodes(directory);
+        List<String> dirs = backend.getChildrenNodes(directory);
 
         if (dirs.size() != 0)
           {
-            String currentDir = null;
-
-            for (Iterator itr = dirs.iterator(); itr.hasNext();)
+            for (String currentDir : dirs)
               {
-                currentDir = (String) itr.next();
-
                 // recursive search inside this directory
                 postorderRemove(currentDir);
               }
           }
 
         // remove all the keys associated to this directory
-        List entries = backend.getKeys(directory);
+        List<String> entries = backend.getKeys(directory);
 
         if (entries.size() != 0)
           {
-            String key = null;
-
-            for (Iterator keys = entries.iterator(); keys.hasNext();)
+            for (String key : entries)
               {
-                key = (String) keys.next();
                 this.removeSpi(key);
               }
           }
Index: gnu/java/util/prefs/MemoryBasedPreferences.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/util/prefs/MemoryBasedPreferences.java,v
retrieving revision 1.4
diff -u -r1.4 MemoryBasedPreferences.java
--- gnu/java/util/prefs/MemoryBasedPreferences.java     28 Feb 2006 16:53:16 
-0000      1.4
+++ gnu/java/util/prefs/MemoryBasedPreferences.java     17 Dec 2006 22:30:17 
-0000
@@ -52,7 +52,7 @@
     private final boolean isUser;
 
     /** Contains all the preference entries of this node. */
-    private HashMap entries = new HashMap();
+    private HashMap<String, String> entries = new HashMap<String, String>();
 
     /**
      * Creates a new preferences node with the given name and parent.
@@ -98,7 +98,7 @@
      * this node.
      */
     protected String[] keysSpi() throws BackingStoreException {
-        return (String[]) entries.keySet().toArray(new String[entries.size()]);
+        return entries.keySet().toArray(new String[entries.size()]);
     }
 
     /**
@@ -106,7 +106,7 @@
      * null when the key has not been set.
      */
     protected String getSpi(String key) {
-        return (String) entries.get(key);
+        return entries.get(key);
     }
 
     /**
Index: gnu/java/util/prefs/gconf/GConfNativePeer.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/util/prefs/gconf/GConfNativePeer.java,v
retrieving revision 1.3
diff -u -r1.3 GConfNativePeer.java
--- gnu/java/util/prefs/gconf/GConfNativePeer.java      27 Sep 2006 13:52:44 
-0000      1.3
+++ gnu/java/util/prefs/gconf/GConfNativePeer.java      17 Dec 2006 22:30:17 
-0000
@@ -147,7 +147,7 @@
    * @return a java.util.List of keys. If there are no keys in the given node, 
a
    *         list of size 0 is returned.
    */
-  public List getKeys(String node) throws BackingStoreException
+  public List<String> getKeys(String node) throws BackingStoreException
   {
     return gconf_client_all_keys(node);
   }
@@ -159,7 +159,7 @@
    * @param node the node to get subnodes from. If there are no subnodes in the
    *          given node, a list of size 0 is returned.
    */
-  public List getChildrenNodes(String node) throws BackingStoreException
+  public List<String> getChildrenNodes(String node) throws 
BackingStoreException
   {
     return gconf_client_all_nodes(node);
   }
@@ -295,7 +295,7 @@
    * @return A list of nodes under the given source node.
    */
   native
-  static final protected List gconf_client_all_nodes(String node)
+  static final protected List<String> gconf_client_all_nodes(String node)
     throws BackingStoreException;
   
   /**
@@ -305,7 +305,7 @@
    * @return A list of all keys stored in the given node.
    */
   native
-  static final protected List gconf_client_all_keys(String node)
+  static final protected List<String> gconf_client_all_keys(String node)
     throws BackingStoreException;
 
   /**
Index: java/util/prefs/AbstractPreferences.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/java/util/prefs/AbstractPreferences.java,v
retrieving revision 1.14
diff -u -r1.14 AbstractPreferences.java
--- java/util/prefs/AbstractPreferences.java    1 Mar 2006 17:10:18 -0000       
1.14
+++ java/util/prefs/AbstractPreferences.java    17 Dec 2006 22:30:42 -0000
@@ -45,6 +45,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.TreeSet;
@@ -97,17 +98,18 @@
      * accessed by earlier <code>getChild()</code> or <code>childSpi()</code>
      * invocations and that have not been removed.
      */
-    private HashMap childCache = new HashMap();
+    private HashMap<String, AbstractPreferences> childCache
+      = new HashMap<String, AbstractPreferences>();
 
     /**
      * A list of all the registered NodeChangeListener objects.
      */
-    private ArrayList nodeListeners;
+    private ArrayList<NodeChangeListener> nodeListeners;
 
     /**
      * A list of all the registered PreferenceChangeListener objects.
      */
-    private ArrayList preferenceListeners;
+    private ArrayList<PreferenceChangeListener> preferenceListeners;
 
     // constructor
 
@@ -202,7 +204,8 @@
      */
     protected final AbstractPreferences[] cachedChildren()
     {
-      return (AbstractPreferences[]) childCache.values().toArray();
+      Collection<AbstractPreferences> vals = childCache.values();
+      return vals.toArray(new AbstractPreferences[vals.size()]);
     }
 
     /**
@@ -228,7 +231,7 @@
             if (isRemoved())
                 throw new IllegalStateException("Node removed");
 
-            TreeSet childrenNames = new TreeSet();
+            TreeSet<String> childrenNames = new TreeSet<String>();
 
             // First get all cached node names
             childrenNames.addAll(childCache.keySet());
@@ -1165,7 +1168,7 @@
           if (listener == null)
             throw new NullPointerException("listener is null");
           if (nodeListeners == null)
-            nodeListeners = new ArrayList();
+            nodeListeners = new ArrayList<NodeChangeListener>();
           nodeListeners.add(listener);
         }
     }
@@ -1184,7 +1187,7 @@
           if (listener == null)
             throw new NullPointerException("listener is null");
           if (preferenceListeners == null)
-            preferenceListeners = new ArrayList();
+            preferenceListeners = new ArrayList<PreferenceChangeListener>();
           preferenceListeners.add(listener);
         }
     }
Index: java/util/prefs/Preferences.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/prefs/Preferences.java,v
retrieving revision 1.16
diff -u -r1.16 Preferences.java
--- java/util/prefs/Preferences.java    10 Dec 2006 20:25:46 -0000      1.16
+++ java/util/prefs/Preferences.java    17 Dec 2006 22:30:42 -0000
@@ -183,9 +183,9 @@
         // Get the factory
         if (factory == null) {
             // Caller might not have enough permissions
-            factory = (PreferencesFactory) AccessController.doPrivileged(
-                        new PrivilegedAction() {
-                            public Object run() {
+            factory = AccessController.doPrivileged(
+                        new PrivilegedAction<PreferencesFactory>() {
+                            public PreferencesFactory run() {
                                 PreferencesFactory pf = null;
                                 String className = System.getProperty
                                     ("java.util.prefs.PreferencesFactory");

Reply via email to