I'm checking this in.

This adds generics to various parts of javax.naming, and it also fixes
a couple other warnings along the way.  Naming now has 6 warnings in
my build.

Tom

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

        * javax/naming/spi/Resolver.java: Fixed comments and imports.
        * javax/naming/ldap/InitialLdapContext.java (InitialLdapContext):
        Genericized.
        * javax/naming/directory/BasicAttributes.java (attributes):
        Genericized.
        (BasicAttributes): Updated.
        (get): Likewise.
        (getAll): Likewise.
        (getIDs): Rewrote.
        (readObject): Updated.
        (BasicAttributesEnumeration): Genericized.
        * javax/naming/directory/BasicAttribute.java (BasicAttribute):
        Genericized.
        (clone): Likewise.
        (readObject): Likewise.
        * javax/naming/Reference.java (Reference): Genericized.
        (clone): Likewise.
        (get): Likewise.
        (get): Likewise.
        * javax/naming/InitialContext.java (colon_list): Genericized.
        (merge): Likewise.
        * javax/naming/CompoundName.java (elts): Genericized.
        (CompoundName): Updated.
        (addAll): Likewise.
        (compareTo): Likewise.
        (endsWith): Likewise.
        (get): Likewise.
        (hashCode): Likewise.
        (startsWith): Likewise.
        (readObject): Likewise.
        * javax/naming/CompositeName.java (elts): Genericized.
        (CompositeName): Updated.
        (addAll): Likewise.
        (compareTo): Likewise.
        (get): Likewise.
        (getPrefix): Likewise.
        (getSuffix): Likewise.
        (toString): Likewise.
        (readObject): Likewise.

Index: javax/naming/CompositeName.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/naming/CompositeName.java,v
retrieving revision 1.7
diff -u -r1.7 CompositeName.java
--- javax/naming/CompositeName.java     10 Dec 2006 20:25:47 -0000      1.7
+++ javax/naming/CompositeName.java     17 Dec 2006 22:30:43 -0000
@@ -58,16 +58,16 @@
 {
   private static final long serialVersionUID = 1667768148915813118L;
   
-  private transient Vector elts;  
+  private transient Vector<String> elts;  
 
   public CompositeName ()
   {
-    elts = new Vector ();
+    elts = new Vector<String> ();
   }
 
   protected CompositeName (Enumeration<String> comps)
   {
-    elts = new Vector ();
+    elts = new Vector<String> ();
     try
       {
        while (comps.hasMoreElements ())
@@ -80,7 +80,7 @@
 
   public CompositeName (String n) throws InvalidNameException
   {
-    elts = new Vector ();
+    elts = new Vector<String> ();
     // Parse the string into its components.
     final char no_quote = 'x'; // Use 'x' to mean no quoting.
     char quote = no_quote;
@@ -151,7 +151,7 @@
 
   public Name addAll (int posn, Name n) throws InvalidNameException
   {
-    Enumeration e = n.getAll ();
+    Enumeration<String> e = n.getAll ();
     try
       {
        while (e.hasMoreElements ())
@@ -168,7 +168,7 @@
 
   public Name addAll (Name suffix) throws InvalidNameException
   {
-    Enumeration e = suffix.getAll ();
+    Enumeration<String> e = suffix.getAll ();
     try
       {
        while (e.hasMoreElements ())
@@ -193,8 +193,8 @@
     int last = Math.min (cn.elts.size (), elts.size ());
     for (int i = 0; i < last; ++i)
       {
-       String f = (String) elts.get (i);
-       int comp = f.compareTo ((String) cn.elts.get (i));
+       String f = elts.get (i);
+       int comp = f.compareTo (cn.elts.get (i));
        if (comp != 0)
          return comp;
       }
@@ -227,7 +227,7 @@
 
   public String get (int posn)
   {
-    return (String) elts.get (posn);
+    return elts.get (posn);
   }
 
   public Enumeration<String> getAll ()
@@ -239,7 +239,7 @@
   {
     CompositeName cn = new CompositeName ();
     for (int i = 0; i < posn; ++i)
-      cn.elts.add ((String) elts.get (i));
+      cn.elts.add (elts.get (i));
     return cn;
   }
 
@@ -249,7 +249,7 @@
       throw new ArrayIndexOutOfBoundsException (posn);
     CompositeName cn = new CompositeName ();
     for (int i = posn; i < elts.size (); ++i)
-      cn.elts.add ((String) elts.get (i));
+      cn.elts.add (elts.get (i));
     return cn;
   }
 
@@ -299,7 +299,7 @@
       {
        // For simplicity we choose to always quote using escapes and
        // never quotes.
-       String elt = (String) elts.get (i);
+       String elt = elts.get (i);
        if (i > 0
            || (i == elts.size () - 1 && elt.equals ("")))
          result.append ('/');
@@ -327,9 +327,9 @@
     throws IOException, ClassNotFoundException
   {
     int size = s.readInt();
-    elts = new Vector(size);
+    elts = new Vector<String>(size);
     for (int i = 0; i < size; i++)
-      elts.add(s.readObject());
+      elts.add((String) s.readObject());
   }
 
   private void writeObject(ObjectOutputStream s) throws IOException
Index: javax/naming/CompoundName.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/naming/CompoundName.java,v
retrieving revision 1.12
diff -u -r1.12 CompoundName.java
--- javax/naming/CompoundName.java      10 Dec 2006 20:25:47 -0000      1.12
+++ javax/naming/CompoundName.java      17 Dec 2006 22:30:43 -0000
@@ -68,14 +68,14 @@
 
   private CompoundName (Properties syntax)
   {
-    elts = new Vector ();
+    elts = new Vector<String> ();
     mySyntax = syntax;
     initializeSyntax ();
   }
 
   protected CompoundName (Enumeration<String> comps, Properties syntax)
   {
-    elts = new Vector ();
+    elts = new Vector<String> ();
     mySyntax = syntax;
     initializeSyntax ();
     try
@@ -91,7 +91,7 @@
   public CompoundName (String n, Properties syntax)
     throws InvalidNameException
   {
-    elts = new Vector ();
+    elts = new Vector<String> ();
     mySyntax = syntax;
     initializeSyntax ();
 
@@ -186,7 +186,7 @@
        int len = elts.size ();
        for (i = 0; i < len / 2; ++i)
          {
-           Object t = elts.set (i, elts.get (len - i - 1));
+           String t = elts.set (i, elts.get (len - i - 1));
            elts.set (len - i - 1, t);
          }
       }
@@ -210,7 +210,7 @@
 
   public Name addAll (int posn, Name n) throws InvalidNameException
   {
-    Enumeration e = n.getAll ();
+    Enumeration<String> e = n.getAll ();
     try
       {
        while (e.hasMoreElements ())
@@ -227,7 +227,7 @@
 
   public Name addAll (Name suffix) throws InvalidNameException
   {
-    Enumeration e = suffix.getAll ();
+    Enumeration<String> e = suffix.getAll ();
     try
       {
        while (e.hasMoreElements ())
@@ -252,8 +252,8 @@
     int last = Math.min (cn.elts.size (), elts.size ());
     for (int i = 0; i < last; ++i)
       {
-       String f = canonicalize ((String) elts.get (i));
-       int comp = f.compareTo (canonicalize ((String) cn.elts.get (i)));
+       String f = canonicalize (elts.get (i));
+       int comp = f.compareTo (canonicalize (cn.elts.get (i)));
        if (comp != 0)
          return comp;
       }
@@ -270,8 +270,8 @@
     int delta = elts.size () - cn.elts.size ();
     for (int i = 0; i < cn.elts.size (); ++i)
       {
-       String f = canonicalize ((String) elts.get (delta + i));
-       if (! f.equals (canonicalize ((String) cn.elts.get (i))))
+       String f = canonicalize (elts.get (delta + i));
+       if (! f.equals (canonicalize (cn.elts.get (i))))
          return false;
       }
     return true;
@@ -286,7 +286,7 @@
 
   public String get (int posn)
   {
-    return (String) elts.get (posn);
+    return elts.get (posn);
   }
 
   public Enumeration<String> getAll ()
@@ -316,7 +316,7 @@
   {
     int h = 0;
     for (int i = 0; i < elts.size (); ++i)
-      h += canonicalize ((String) elts.get (i)).hashCode ();
+      h += canonicalize (elts.get (i)).hashCode ();
     return h;
   }
 
@@ -344,8 +344,8 @@
       return false;
     for (int i = 0; i < cn.elts.size (); ++i)
       {
-       String f = canonicalize ((String) elts.get (i));
-       if (! f.equals (canonicalize ((String) cn.elts.get (i))))
+       String f = canonicalize (elts.get (i));
+       if (! f.equals (canonicalize (cn.elts.get (i))))
          return false;
       }
     return true;
@@ -383,7 +383,7 @@
        // Find the appropriate element.  FIXME: not clear what FLAT
        // means.
        int offset = (direction == RIGHT_TO_LEFT) ? (size - i - 1) : i;
-       String element = (String) elts.get (offset);
+       String element = elts.get (offset);
        if (i > 0
            || (i == size - 1 && element.equals ("")))
          result.append (separator);
@@ -478,7 +478,7 @@
   {
     mySyntax = (Properties) s.readObject();
     int count = s.readInt();
-    elts = new Vector(count);
+    elts = new Vector<String>(count);
     for (int i = 0; i < count; i++)
       elts.addElement((String) s.readObject());
   }
@@ -499,7 +499,7 @@
   protected transient Properties mySyntax;
 
   // The actual elements.
-  private transient Vector elts;
+  private transient Vector<String> elts;
 
   // The following are all used for syntax.
   private transient int direction;
Index: javax/naming/InitialContext.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/naming/InitialContext.java,v
retrieving revision 1.11
diff -u -r1.11 InitialContext.java
--- javax/naming/InitialContext.java    10 Dec 2006 20:25:47 -0000      1.11
+++ javax/naming/InitialContext.java    17 Dec 2006 22:30:43 -0000
@@ -80,10 +80,10 @@
    * be appended after the colon to the first possible value. Used in
    * [EMAIL PROTECTED] #merge(Hashtable, Hashtable)}
    */
-  static final HashSet colon_list;
+  static final HashSet<String> colon_list;
   static
     {
-      colon_list = new HashSet();
+      colon_list = new HashSet<String>();
       colon_list.add(Context.OBJECT_FACTORIES);
       colon_list.add(Context.URL_PKG_PREFIXES);
       colon_list.add(Context.STATE_FACTORIES);
@@ -262,7 +262,8 @@
    *          in this table.
    * @param additional the second table, from where additional values are taken
    */  
-  static void merge (Hashtable primary, Hashtable additional)
+  static void merge (Hashtable<Object, Object> primary,
+                     Hashtable<Object, Object> additional)
   {
     Enumeration en = additional.keys();
     
Index: javax/naming/Reference.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/naming/Reference.java,v
retrieving revision 1.6
diff -u -r1.6 Reference.java
--- javax/naming/Reference.java 10 Dec 2006 20:25:47 -0000      1.6
+++ javax/naming/Reference.java 17 Dec 2006 22:30:43 -0000
@@ -83,7 +83,7 @@
   public Reference (String className)
   {
     this.className = className;
-    addrs = new Vector ();
+    addrs = new Vector<RefAddr> ();
   }
   
   /**
@@ -93,7 +93,7 @@
   public Reference (String className, RefAddr addr)
   {
     this.className = className;
-    addrs = new Vector ();
+    addrs = new Vector<RefAddr> ();
     addrs.add (addr);
   }
    
@@ -112,7 +112,7 @@
     this.className = className;
     this.classFactory = factoryClassName;
     this.classFactoryLocation = factoryLocation;
-    addrs = new Vector ();
+    addrs = new Vector<RefAddr> ();
   }
 
   /**
@@ -131,7 +131,7 @@
     this.className = className;
     this.classFactory = factoryClassName;
     this.classFactoryLocation = factoryLocation;
-    addrs = new Vector ();
+    addrs = new Vector<RefAddr> ();
     addrs.add (addr);
   }
 
@@ -164,7 +164,7 @@
   {
     Reference r = new Reference (className, classFactory,
                                 classFactoryLocation);
-    r.addrs = (Vector) addrs.clone ();
+    r.addrs = (Vector<RefAddr>) addrs.clone ();
     return r;
   }
 
@@ -193,7 +193,7 @@
    */
   public RefAddr get (int posn)
   {
-    return (RefAddr) addrs.get (posn);
+    return addrs.get (posn);
   }
   
   /**
@@ -208,7 +208,7 @@
   {
     for (int i = 0; i < addrs.size (); ++i)
       {
-       RefAddr r = (RefAddr) addrs.get (i);
+       RefAddr r = addrs.get (i);
        if (addrType.equals (r.getType ()))
          return r;
       }
Index: javax/naming/directory/BasicAttribute.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/naming/directory/BasicAttribute.java,v
retrieving revision 1.7
diff -u -r1.7 BasicAttribute.java
--- javax/naming/directory/BasicAttribute.java  10 Dec 2006 20:25:47 -0000      
1.7
+++ javax/naming/directory/BasicAttribute.java  17 Dec 2006 22:30:44 -0000
@@ -78,7 +78,7 @@
   {
     attrID = id;
     this.ordered = ordered;
-    values = new Vector ();
+    values = new Vector<Object> ();
   }
 
   public BasicAttribute (String id, Object value)
@@ -90,7 +90,7 @@
   {
     attrID = id;
     this.ordered = ordered;
-    values = new Vector ();
+    values = new Vector<Object> ();
     values.add (value);
   }
 
@@ -118,7 +118,7 @@
     BasicAttribute c = new BasicAttribute ();
     c.attrID = attrID;
     c.ordered = ordered;
-    c.values = (Vector) values.clone ();
+    c.values = (Vector<Object>) values.clone ();
     return c;
   }
 
@@ -307,7 +307,7 @@
   {
     s.defaultReadObject();
     int size = s.readInt();
-    values = new Vector(size);
+    values = new Vector<Object>(size);
     for (int i=0; i < size; i++)
       values.add(s.readObject());
   }
Index: javax/naming/directory/BasicAttributes.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/naming/directory/BasicAttributes.java,v
retrieving revision 1.8
diff -u -r1.8 BasicAttributes.java
--- javax/naming/directory/BasicAttributes.java 10 Dec 2006 20:25:47 -0000      
1.8
+++ javax/naming/directory/BasicAttributes.java 17 Dec 2006 22:30:44 -0000
@@ -63,7 +63,7 @@
   public BasicAttributes (boolean ignoreCase)
   {
     this.ignoreCase = ignoreCase;
-    this.attributes = new Vector ();
+    this.attributes = new Vector<Attribute>();
   }
 
   public BasicAttributes (String attrID, Object val)
@@ -74,7 +74,7 @@
   public BasicAttributes (String attrID, Object val, boolean ignoreCase)
   {
     this.ignoreCase = ignoreCase;
-    attributes = new Vector ();
+    attributes = new Vector<Attribute>();
     attributes.add (new BasicAttribute (attrID, val));
   }
 
@@ -82,7 +82,7 @@
   {
     // Slightly inefficient as we make a garbage Vector here.
     BasicAttributes ba = new BasicAttributes (ignoreCase);
-    ba.attributes = (Vector) attributes.clone ();
+    ba.attributes = (Vector<Attribute>) attributes.clone ();
     return ba;
   }
 
@@ -117,7 +117,7 @@
   {
     for (int i = 0; i < attributes.size (); ++i)
       {
-       Attribute at = (Attribute) attributes.get (i);
+       Attribute at = attributes.get (i);
        if ((ignoreCase && attrID.equalsIgnoreCase (at.getID ()))
            || (! ignoreCase && attrID.equals (at.getID ())))
          return at;
@@ -128,12 +128,38 @@
 
   public NamingEnumeration<Attribute> getAll ()
   {
-    return new BasicAttributesEnumeration (false);
+    return new BasicAttributesEnumeration();
   }
 
   public NamingEnumeration<String> getIDs ()
   {
-    return new BasicAttributesEnumeration (true);
+    final NamingEnumeration<Attribute> attrs = getAll();
+    return new NamingEnumeration<String>() {
+      public boolean hasMore() throws NamingException
+      {
+        return attrs.hasMore();
+      }
+      
+      public boolean hasMoreElements()
+      {
+        return attrs.hasMoreElements();
+      }
+
+      public String next() throws NamingException
+      {
+        return attrs.next().getID();
+      }
+
+      public String nextElement()
+      {
+        return attrs.nextElement().getID();
+      }
+
+      public void close() throws NamingException
+      {
+        attrs.close();
+      }
+    };
   }
 
   public int hashCode ()
@@ -197,16 +223,16 @@
   // This is set by the serialization spec.
   private boolean ignoreCase;
   // Package-private to avoid a trampoline.
-  transient Vector attributes;
+  transient Vector<Attribute> attributes;
 
   private void readObject(ObjectInputStream s) throws IOException,
       ClassNotFoundException
   {
     s.defaultReadObject();
     int size = s.readInt();
-    attributes = new Vector(size);    
+    attributes = new Vector<Attribute>(size);    
     for (int i = 0; i < size; i++)
-      attributes.add(s.readObject());
+      attributes.add((Attribute) s.readObject());
   }
 
   private void writeObject(ObjectOutputStream s) throws IOException
@@ -218,14 +244,13 @@
   }
 
   // Used when enumerating.
-  private class BasicAttributesEnumeration implements NamingEnumeration
+  private class BasicAttributesEnumeration
+    implements NamingEnumeration<Attribute>
   {
     int where = 0;
-    boolean id;
 
-    public BasicAttributesEnumeration (boolean id)
+    public BasicAttributesEnumeration ()
     {
-      this.id = id;
     }
 
     public void close () throws NamingException
@@ -237,7 +262,7 @@
       return hasMoreElements ();
     }
 
-    public Object next () throws NamingException
+    public Attribute next () throws NamingException
     {
       return nextElement ();
     }
@@ -247,13 +272,13 @@
       return where < attributes.size ();
     }
 
-    public Object nextElement () throws NoSuchElementException
+    public Attribute nextElement () throws NoSuchElementException
     {
       if (where >= attributes.size ())
        throw new NoSuchElementException ("no more elements");
-      Attribute at = (Attribute) attributes.get (where);
+      Attribute at = attributes.get (where);
       ++where;
-      return id ? (Object) at.getID () : (Object) at;
+      return at;
     }
   }
 }
Index: javax/naming/ldap/InitialLdapContext.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/naming/ldap/InitialLdapContext.java,v
retrieving revision 1.5
diff -u -r1.5 InitialLdapContext.java
--- javax/naming/ldap/InitialLdapContext.java   10 Dec 2006 20:25:47 -0000      
1.5
+++ javax/naming/ldap/InitialLdapContext.java   17 Dec 2006 22:30:44 -0000
@@ -66,13 +66,13 @@
   {
     super (false);
 
-    Hashtable myenv = null;
+    Hashtable<Object, Object> myenv = null;
     if (connControls != null)
       {
        if (environment == null)
-         myenv = new Hashtable ();
+         myenv = new Hashtable<Object, Object> ();
        else
-         myenv = (Hashtable) environment.clone ();
+         myenv = (Hashtable<Object, Object>) environment.clone ();
        myenv.put ("java.naming.ldap.control.connect",
                         connControls);
       }
Index: javax/naming/spi/Resolver.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/naming/spi/Resolver.java,v
retrieving revision 1.7
diff -u -r1.7 Resolver.java
--- javax/naming/spi/Resolver.java      10 Dec 2006 20:25:47 -0000      1.7
+++ javax/naming/spi/Resolver.java      17 Dec 2006 22:30:45 -0000
@@ -41,15 +41,14 @@
 import javax.naming.Context;
 import javax.naming.Name;
 import javax.naming.NamingException;
-import javax.naming.NotContextException;
  
 /**
-+  * <p>Represents the object, capable for the at least partial name 
resolution.
-+  * The object is not necessay capable for the complete name resolution and
-+  * need not implement the [EMAIL PROTECTED] Context}.</p>
-+  * <p>
-+  * Both passed parameters and returned results are owned by the caller.</p>
-+  * 
+ * <p>Represents the object, capable for the at least partial name resolution.
+ * The object is not necessay capable for the complete name resolution and
+ * need not implement the [EMAIL PROTECTED] Context}.</p>
+ * <p>
+ * Both passed parameters and returned results are owned by the caller.</p>
+ * 
  * @author Warren Levy ([EMAIL PROTECTED])
  */
 public interface Resolver

Reply via email to