classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] [generics] Patch: FYI: minor java.util fixes


From: Tom Tromey
Subject: [cp-patches] [generics] Patch: FYI: minor java.util fixes
Date: Thu, 6 Oct 2005 07:35:11 -0600 (MDT)

s
From:  Tom Tromey <address@hidden>
Reply-To:  address@hidden
BCC:  Tom Tromey <address@hidden>
X-Attribution:  Tom
Date: 06 Oct 2005 07:35:10 -0600
Message-ID: <address@hidden>
Lines: 319
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

I'm checking this in on the generics branch.

This fixes a few problems in java.util that were pointed out by japi.

Tom

2005-10-06  Tom Tromey  <address@hidden>

        * java/util/ListResourceBundle.java (getKeys): Fixed return type.
        * java/util/ResourceBundle.java (getKeys): Fixed return type.
        * java/util/AbstractMap.java (entrySet): Fixed return type.
        (clone): Updated.
        (equals): Likewise.
        (iterator): Likewise.
        * java/util/Collections.java (fill): Fixed argument type.
        (reverse): Likewise.
        (unmodifiableCollection): Likewise.
        (UnmodifiableCollection): Likewise.
        (UnmodifiableIterator): Likewise.
        (unmodifiableSet): Likewise.
        (UnmodifiableSet): Likewise.
        (unmodifiableList): Likewise.
        * java/util/TreeSet.java (TreeSet(SortedSet<T>)): Fixed argument
        type.
        (headSet): Fixed return type.
        * java/util/StringTokenizer.java: Implements Enumeration<Object>.

Index: java/util/AbstractMap.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/AbstractMap.java,v
retrieving revision 1.26.2.5
diff -u -r1.26.2.5 AbstractMap.java
--- java/util/AbstractMap.java  2 Aug 2005 20:12:29 -0000       1.26.2.5
+++ java/util/AbstractMap.java  6 Oct 2005 13:38:17 -0000
@@ -105,7 +105,7 @@
    * @return the entry set
    * @see Map.Entry
    */
-  public abstract Set entrySet();
+  public abstract Set<Map.Entry<K, V>> entrySet();
 
   /**
    * Remove all entries from this Map (optional operation). This default
@@ -134,7 +134,7 @@
    */
   protected Object clone() throws CloneNotSupportedException
   {
-    AbstractMap copy = (AbstractMap) super.clone();
+    AbstractMap<K, V> copy = (AbstractMap<K, V>) super.clone();
     // Clear out the caches; they are stale.
     copy.keys = null;
     copy.values = null;
@@ -201,7 +201,7 @@
   {
     return (o == this
            || (o instanceof Map
-               && entrySet().equals(((Map) o).entrySet())));
+               && entrySet().equals(((Map<K, V>) o).entrySet())));
   }
 
   /**
@@ -310,7 +310,7 @@
         */
         public Iterator<K> iterator()
         {
-          return new Iterator()
+          return new Iterator<K>()
           {
            /**
             * The iterator returned by <code>entrySet()</code>.
@@ -400,11 +400,14 @@
    */
   public void putAll(Map<? extends K, ? extends V> m)
   {
-    Iterator<Map.Entry<K, V>> entries = ((Map<K,V>) m).entrySet().iterator();
+    // FIXME: bogus circumlocution.
+    Iterator entries2 = m.entrySet().iterator();
+    Iterator<Map.Entry<? extends K, ? extends V>> entries
+      = (Iterator<Map.Entry<? extends K, ? extends V>>) entries2;
     int pos = m.size();
     while (--pos >= 0)
       {
-        Map.Entry<K, V> entry = entries.next();
+        Map.Entry<? extends K, ? extends V> entry = entries.next();
         put(entry.getKey(), entry.getValue());
       }
   }
@@ -543,7 +546,7 @@
         */
         public Iterator<V> iterator()
         {
-          return new Iterator()
+          return new Iterator<V>()
           {
            /**
             * The iterator returned by <code>entrySet()</code>.
Index: java/util/Collections.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Collections.java,v
retrieving revision 1.28.2.16
diff -u -r1.28.2.16 Collections.java
--- java/util/Collections.java  20 Sep 2005 18:46:30 -0000      1.28.2.16
+++ java/util/Collections.java  6 Oct 2005 13:38:18 -0000
@@ -820,9 +820,9 @@
    * @throws UnsupportedOperationException if l.listIterator() does not
    *         support the set operation.
    */
-  public static <T> void fill(List<T> l, T val)
+  public static <T> void fill(List<? super T> l, T val)
   {
-    ListIterator<T> itr = l.listIterator();
+    ListIterator<? super T> itr = l.listIterator();
     for (int i = l.size() - 1; i >= 0; --i)
       {
        itr.next();
@@ -1178,17 +1178,18 @@
    * @throws UnsupportedOperationException if l.listIterator() does not
    *         support the set operation
    */
-  public static <T> void reverse(List<T> l)
+  public static void reverse(List<?> l)
   {
-    ListIterator<T> i1 = l.listIterator();
+    ListIterator i1 = l.listIterator();
     int pos1 = 1;
     int pos2 = l.size();
-    ListIterator<T> i2 = l.listIterator(pos2);
+    ListIterator i2 = l.listIterator(pos2);
     while (pos1 < pos2)
       {
-       T o = i1.next();
-       i1.set(i2.previous());
-       i2.set(o);
+       Object o1 = i1.next();
+    Object o2 = i2.previous();
+       i1.set(o2);
+       i2.set(o1);
        ++pos1;
        --pos2;
       }
@@ -4183,7 +4184,7 @@
    * @return a read-only view of the collection
    * @see Serializable
    */
-  public static <T> Collection<T> unmodifiableCollection(Collection<T> c)
+  public static <T> Collection<T> unmodifiableCollection(Collection<? extends 
T> c)
   {
     return new UnmodifiableCollection<T>(c);
   }
@@ -4206,14 +4207,14 @@
      * The wrapped collection. Package visible for use by subclasses.
      * @serial the real collection
      */
-    final Collection<T> c;
+    final Collection<? extends T> c;
 
     /**
      * Wrap a given collection.
      * @param c the collection to wrap
      * @throws NullPointerException if c is null
      */
-    UnmodifiableCollection(Collection<T> c)
+    UnmodifiableCollection(Collection<? extends T> c)
     {
       this.c = c;
       if (c == null)
@@ -4430,13 +4431,13 @@
     /**
      * The wrapped iterator.
      */
-    private final Iterator<T> i;
+    private final Iterator<? extends T> i;
 
     /**
      * Only trusted code creates a wrapper.
      * @param i the wrapped iterator
      */
-    UnmodifiableIterator(Iterator<T> i)
+    UnmodifiableIterator(Iterator<? extends T> i)
     {
       this.i = i;
     }
@@ -5266,7 +5267,7 @@
    * @return a read-only view of the set
    * @see Serializable
    */
-  public static <T> Set<T> unmodifiableSet(Set<T> s)
+  public static <T> Set<T> unmodifiableSet(Set<? extends T> s)
   {
     return new UnmodifiableSet<T>(s);
   }
@@ -5290,7 +5291,7 @@
      * @param s the set to wrap
      * @throws NullPointerException if s is null
      */
-    UnmodifiableSet(Set<T> s)
+    UnmodifiableSet(Set<? extends T> s)
     {
       super(s);
     }
Index: java/util/ListResourceBundle.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/ListResourceBundle.java,v
retrieving revision 1.10.2.2
diff -u -r1.10.2.2 ListResourceBundle.java
--- java/util/ListResourceBundle.java   2 Aug 2005 20:12:30 -0000       1.10.2.2
+++ java/util/ListResourceBundle.java   6 Oct 2005 13:38:19 -0000
@@ -108,21 +108,21 @@
    *
    * @return an enumeration of the keys
    */
-  public Enumeration getKeys()
+  public Enumeration<String> getKeys()
   {
     // We make a new Set that holds all the keys, then return an enumeration
     // for that. This prevents modifications from ruining the enumeration,
     // as well as ignoring duplicates.
     final Object[][] contents = getContents();
-    Set s = new HashSet();
+    Set<String> s = new HashSet<String>();
     int i = contents.length;
     while (--i >= 0)
-      s.add(contents[i][0]);
+      s.add((String) contents[i][0]);
     ResourceBundle bundle = parent;
     // Eliminate tail recursion.
     while (bundle != null)
       {
-        Enumeration e = bundle.getKeys();
+        Enumeration<String> e = bundle.getKeys();
         while (e.hasMoreElements())
           s.add(e.nextElement());
         bundle = bundle.parent;
Index: java/util/PropertyResourceBundle.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/PropertyResourceBundle.java,v
retrieving revision 1.14.2.1
diff -u -r1.14.2.1 PropertyResourceBundle.java
--- java/util/PropertyResourceBundle.java       2 Aug 2005 20:12:30 -0000       
1.14.2.1
+++ java/util/PropertyResourceBundle.java       6 Oct 2005 13:38:19 -0000
@@ -126,15 +126,17 @@
    *
    * @return an enumeration of the keys
    */
-  public Enumeration getKeys()
+  public Enumeration<String> getKeys()
   {
     if (parent == null)
-      return properties.propertyNames();
+      // FIXME: bogus cast.
+      return (Enumeration<String>) properties.propertyNames();
     // We make a new Set that holds all the keys, then return an enumeration
     // for that. This prevents modifications from ruining the enumeration,
     // as well as ignoring duplicates.
-    Set s = new HashSet();
-    Enumeration e = properties.propertyNames();
+    Set<String> s = new HashSet<String>();
+    // FIXME: bogus cast.
+    Enumeration<String> e = (Enumeration<String>) properties.propertyNames();
     while (e.hasMoreElements())
       s.add(e.nextElement());
     ResourceBundle bundle = parent;
Index: java/util/ResourceBundle.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/ResourceBundle.java,v
retrieving revision 1.24.2.6
diff -u -r1.24.2.6 ResourceBundle.java
--- java/util/ResourceBundle.java       20 Sep 2005 18:46:30 -0000      1.24.2.6
+++ java/util/ResourceBundle.java       6 Oct 2005 13:38:19 -0000
@@ -443,7 +443,7 @@
    *
    * @return an enumeration of the keys
    */
-  public abstract Enumeration getKeys();
+  public abstract Enumeration<String> getKeys();
 
   /**
    * Tries to load a class or a property file with the specified name.
Index: java/util/StringTokenizer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/StringTokenizer.java,v
retrieving revision 1.12.2.2
diff -u -r1.12.2.2 StringTokenizer.java
--- java/util/StringTokenizer.java      2 Aug 2005 20:12:30 -0000       1.12.2.2
+++ java/util/StringTokenizer.java      6 Oct 2005 13:38:19 -0000
@@ -58,7 +58,7 @@
  * @see java.io.StreamTokenizer
  * @status updated to 1.4
  */
-public class StringTokenizer implements Enumeration
+public class StringTokenizer implements Enumeration<Object>
 {
   // WARNING: StringTokenizer is a CORE class in the bootstrap cycle. See the
   // comments in vm/reference/java/lang/Runtime for implications of this fact.
Index: java/util/TreeSet.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/TreeSet.java,v
retrieving revision 1.15.2.7
diff -u -r1.15.2.7 TreeSet.java
--- java/util/TreeSet.java      2 Aug 2005 20:12:30 -0000       1.15.2.7
+++ java/util/TreeSet.java      6 Oct 2005 13:38:19 -0000
@@ -147,7 +147,7 @@
    *        and will initialize itself with all its elements
    * @throws NullPointerException if sortedSet is null
    */
-  public TreeSet(SortedSet<? extends T> sortedSet)
+  public TreeSet(SortedSet<T> sortedSet)
   {
     Iterator<T> itr;
 
@@ -278,7 +278,7 @@
    * @throws NullPointerException if to is null, but the comparator does not
    *         tolerate null elements
    */
-  public SortedSet headSet(T to)
+  public SortedSet<T> headSet(T to)
   {
     return new TreeSet<T>(map.headMap(to));
   }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]