summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-13 11:14:33 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-13 11:14:33 +0000
commit650c3ef25f102a8aca5a814dc13420377393bf9d (patch)
treee307016dc2e525190bb91c012c1f93f48d6a34eb
parentc7b18ce0b85ef6daeb088603efa49af0ad26d11f (diff)
downloadclasspath-650c3ef25f102a8aca5a814dc13420377393bf9d.tar.gz
2005-01-13 Andrew John Hughes <gnu_andrew@member.fsf.org>
* java/util/Arrays.java: (sort(T[],int,int,Comparator<? super T>)): Typed Object[] to T[] * java/util/Collections.java; (compare(T,T,<? super T>)): typed generically (binarySearch(List<? extends T>,T,Comparator<? super T>)): re-typed and added casts to List<T> (rotate(List<? super Object>, int)): added (incorrect?) super type to compile (shuffle(List<? super Object>): likewise (shuffle(List<? super Object, Random)): likewise (entrySet()): singleton version changed for accuracy (swap(List<? super Object>,int,int)): added (incorrect?) super type to compile (entrySet()): unmodifiable version removed invalid static typing of K and V * java/util/HashMap.java: (entries): re-typed to Set<Map.Entry<K,V>> (putAll(Map<? extends K, ? extends V>)): cast and foreach statement added (putAllInternal(Map<? extends K, ? extends V>)): likewise * java/util/Hashtable.java: same as for HashMap * java/util/LinkedHashEntry.java: (pred,succ): generically typed (LinkedHashEntry(K,V)): likewise (cleanup()): likewise (get(Object)): likewise (addEntry(K,V,int,boolean)): likewise * java/util/LinkedList.java: changed incorrect cast (LinkedListItr<I>): re-typed to unique I from T * java/util/TreeSet.java: cast set to SortedSet<T> before using
-rw-r--r--ChangeLog37
-rw-r--r--java/util/Arrays.java6
-rw-r--r--java/util/Collections.java60
-rw-r--r--java/util/HashMap.java18
-rw-r--r--java/util/Hashtable.java20
-rw-r--r--java/util/LinkedHashMap.java14
-rw-r--r--java/util/LinkedList.java33
-rw-r--r--java/util/TreeSet.java4
8 files changed, 119 insertions, 73 deletions
diff --git a/ChangeLog b/ChangeLog
index 71595fdae..29550ffe2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+2005-01-13 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * java/util/Arrays.java:
+ (sort(T[],int,int,Comparator<? super T>)): Typed
+ Object[] to T[]
+ * java/util/Collections.java;
+ (compare(T,T,<? super T>)): typed generically
+ (binarySearch(List<? extends T>,T,Comparator<? super T>)):
+ re-typed and added casts to List<T>
+ (rotate(List<? super Object>, int)): added (incorrect?)
+ super type to compile
+ (shuffle(List<? super Object>): likewise
+ (shuffle(List<? super Object, Random)): likewise
+ (entrySet()): singleton version changed for accuracy
+ (swap(List<? super Object>,int,int)): added (incorrect?)
+ super type to compile
+ (entrySet()): unmodifiable version removed invalid
+ static typing of K and V
+ * java/util/HashMap.java:
+ (entries): re-typed to Set<Map.Entry<K,V>>
+ (putAll(Map<? extends K, ? extends V>)): cast and foreach
+ statement added
+ (putAllInternal(Map<? extends K, ? extends V>)): likewise
+ * java/util/Hashtable.java:
+ same as for HashMap
+ * java/util/LinkedHashEntry.java:
+ (pred,succ): generically typed
+ (LinkedHashEntry(K,V)): likewise
+ (cleanup()): likewise
+ (get(Object)): likewise
+ (addEntry(K,V,int,boolean)): likewise
+ * java/util/LinkedList.java:
+ changed incorrect cast
+ (LinkedListItr<I>): re-typed to unique I from T
+ * java/util/TreeSet.java:
+ cast set to SortedSet<T> before using
+
2005-01-12 Andrew John Hughes <gnu_andrew@member.fsf.org>
* java/util/Collections.java
diff --git a/java/util/Arrays.java b/java/util/Arrays.java
index e799185a8..fbfec2663 100644
--- a/java/util/Arrays.java
+++ b/java/util/Arrays.java
@@ -2237,9 +2237,9 @@ public class Arrays
if (len <= 6)
return;
- Object[] src = a;
- Object[] dest = new Object[len];
- Object[] t = null; // t is used for swapping src and dest
+ T[] src = a;
+ T[] dest = (T[]) new Object[len];
+ T[] t = null; // t is used for swapping src and dest
// The difference of the fromIndex of the src and dest array.
int srcDestDiff = -fromIndex;
diff --git a/java/util/Collections.java b/java/util/Collections.java
index ebffa2aaf..1b14c5db5 100644
--- a/java/util/Collections.java
+++ b/java/util/Collections.java
@@ -501,7 +501,7 @@ public class Collections
* clever, but worth it for removing a duplicate of the search code.
* Note: This code is also used in Arrays (for sort as well as search).
*/
- static final int compare(Object o1, Object o2, Comparator<?> c)
+ static final <T> int compare(T o1, T o2, Comparator<? super T> c)
{
return c == null ? ((Comparable) o1).compareTo(o2) : c.compare(o1, o2);
}
@@ -563,7 +563,8 @@ public class Collections
* ordering (only possible when c is null)
* @see #sort(List, Comparator)
*/
- public static <T> int binarySearch(List<T> l, T key, Comparator<? super T> c)
+ public static <T> int binarySearch(List<? extends T> l, T key,
+ Comparator<? super T> c)
{
int pos = 0;
int low = 0;
@@ -573,7 +574,7 @@ public class Collections
// if the list is sequential-access.
if (isSequential(l))
{
- ListIterator<T> itr = l.listIterator();
+ ListIterator<T> itr = ((List<T>) l).listIterator();
int i = 0;
while (low <= hi)
{
@@ -597,7 +598,7 @@ public class Collections
while (low <= hi)
{
pos = (low + hi) >> 1;
- final int d = compare(key, l.get(pos), c);
+ final int d = compare(key, ((List<T>) l).get(pos), c);
if (d == 0)
return pos;
else if (d < 0)
@@ -1112,7 +1113,8 @@ public class Collections
* @throws UnsupportedOperationException if the list does not support set
* @since 1.4
*/
- public static void rotate(List<?> list, int distance)
+ /* FIXME: type should be List<?> but we can't do anything with this */
+ public static void rotate(List<? super Object> list, int distance)
{
int size = list.size();
distance %= size;
@@ -1174,7 +1176,8 @@ public class Collections
* @throws UnsupportedOperationException if l.listIterator() does not
* support the set operation
*/
- public static void shuffle(List<?> l)
+ /* FIXME: type should be List<?> but we can't do anything with this */
+ public static void shuffle(List<? super Object> l)
{
if (defaultRandom == null)
{
@@ -1217,10 +1220,11 @@ public class Collections
* @throws UnsupportedOperationException if l.listIterator() does not
* support the set operation
*/
- public static void shuffle(List<?> l, Random r)
+ /* FIXME: type should be List<?> but we can't do anything with this */
+ public static void shuffle(List<? super Object> l, Random r)
{
int lsize = l.size();
- ListIterator<?> i = l.listIterator(lsize);
+ ListIterator i = ((List) l).listIterator(lsize);
boolean sequential = isSequential(l);
Object[] a = null; // stores a copy of the list for the sequential case
@@ -1538,7 +1542,7 @@ public class Collections
* The implementation of {@link #singletonMap(Object)}. This class name
* is required for compatibility with Sun's JDK serializability.
*
- * @author Eric Blake <ebb9@email.byu.edu>
+ * @author Eric Blake (ebb9@email.byu.edu)
*/
private static final class SingletonMap<K, V> extends AbstractMap<K, V>
implements Serializable
@@ -1563,7 +1567,7 @@ public class Collections
/**
* Cache the entry set.
*/
- private transient Set<AbstractMap.BasicMapEntry<K, V>> entries;
+ private transient Set<Map.Entry<K, V>> entries;
/**
* Construct a singleton.
@@ -1582,13 +1586,16 @@ public class Collections
public Set<Map.Entry<K, V>> entrySet()
{
if (entries == null)
- entries = singleton(new AbstractMap.BasicMapEntry<K, V>(k, v)
- {
- public V setValue(V o)
- {
- throw new UnsupportedOperationException();
- }
- });
+ {
+ Map.Entry<K,V> entry = new AbstractMap.BasicMapEntry<K, V>(k, v)
+ {
+ public V setValue(V o)
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ entries = singleton(entry);
+ }
return entries;
}
@@ -1724,7 +1731,8 @@ public class Collections
* list.size()
* @since 1.4
*/
- public static void swap(List<?> l, int i, int j)
+ /* FIXME: type should be List<?> but we can't do anything with this */
+ public static void swap(List<? super Object> l, int i, int j)
{
l.set(i, l.set(j, l.get(i)));
}
@@ -3306,7 +3314,7 @@ public class Collections
* The implementation of {@link #unmodifiableMap(Map)}. This
* class name is required for compatibility with Sun's JDK serializability.
*
- * @author Eric Blake <ebb9@email.byu.edu>
+ * @author Eric Blake (ebb9@email.byu.edu)
*/
private static class UnmodifiableMap<K, V> implements Map<K, V>, Serializable
{
@@ -3366,7 +3374,7 @@ public class Collections
public Set<Map.Entry<K, V>> entrySet()
{
if (entries == null)
- entries = new UnmodifiableEntrySet<Map.Entry<K, V>>(m.entrySet());
+ entries = new UnmodifiableEntrySet<Map.Entry<K,V>>(m.entrySet());
return entries;
}
@@ -3376,7 +3384,7 @@ public class Collections
*
* @author Eric Blake <ebb9@email.byu.edu>
*/
- private static final class UnmodifiableEntrySet<T extends Map.Entry<K, V>>
+ private static final class UnmodifiableEntrySet<T>
extends UnmodifiableSet<T>
implements Serializable
{
@@ -3401,18 +3409,18 @@ public class Collections
{
public T next()
{
- final T e = super.next();
- return new Map.Entry<K, V>()
+ final Map.Entry e = (Map.Entry) super.next();
+ return (T) new Map.Entry()
{
public boolean equals(Object o)
{
return e.equals(o);
}
- public K getKey()
+ public Object getKey()
{
return e.getKey();
}
- public V getValue()
+ public Object getValue()
{
return e.getValue();
}
@@ -3420,7 +3428,7 @@ public class Collections
{
return e.hashCode();
}
- public V setValue(V value)
+ public Object setValue(Object value)
{
throw new UnsupportedOperationException();
}
diff --git a/java/util/HashMap.java b/java/util/HashMap.java
index 143a3a2ef..dfb9518b8 100644
--- a/java/util/HashMap.java
+++ b/java/util/HashMap.java
@@ -154,7 +154,7 @@ public class HashMap<K, V> extends AbstractMap<K, V>
/**
* The cache for {@link #entrySet()}.
*/
- private transient Set<HashEntry<K, V>> entries;
+ private transient Set<Map.Entry<K, V>> entries;
/**
* Class to represent an entry in the hash table. Holds a single key-value
@@ -380,11 +380,11 @@ public class HashMap<K, V> extends AbstractMap<K, V>
*/
public void putAll(Map<? extends K, ? extends V> m)
{
- Iterator<Map.Entry<? extends K, ? extends V>> itr
- = m.entrySet().iterator();
- while (itr.hasNext())
+ Map<K,V> addMap;
+
+ addMap = (Map<K,V>) m;
+ for (Map.Entry<K,V> e : addMap.entrySet())
{
- Map.Entry<? extends K, ? extends V> e = itr.next();
// Optimize in case the Entry is one of our own.
if (e instanceof AbstractMap.BasicMapEntry)
{
@@ -710,13 +710,13 @@ public class HashMap<K, V> extends AbstractMap<K, V>
*/
void putAllInternal(Map<? extends K, ? extends V> m)
{
- Iterator<Map.Entry<? extends K, ? extends V>> itr
- = m.entrySet().iterator();
+ Map<K,V> addMap;
+
+ addMap = (Map<K,V>) m;
size = 0;
- while (itr.hasNext())
+ for (Map.Entry<K,V> e : addMap.entrySet())
{
size++;
- Map.Entry<? extends K, ? extends V> e = itr.next();
K key = e.getKey();
int idx = hash(key);
addEntry(key, e.getValue(), idx, false);
diff --git a/java/util/Hashtable.java b/java/util/Hashtable.java
index 91f52c374..14a026ab7 100644
--- a/java/util/Hashtable.java
+++ b/java/util/Hashtable.java
@@ -172,7 +172,7 @@ public class Hashtable<K, V> extends Dictionary<K, V>
/**
* The cache for {@link #entrySet()}.
*/
- private transient Set<HashEntry<K, V>> entries;
+ private transient Set<Map.Entry<K, V>> entries;
/**
* Class to represent an entry in the hash table. Holds a single key-value
@@ -511,13 +511,12 @@ public class Hashtable<K, V> extends Dictionary<K, V>
*/
public synchronized void putAll(Map<? extends K, ? extends V> m)
{
- Iterator<Map.Entry<? extends K, ? extends V>> itr
- = m.entrySet().iterator();
+ Map<K,V> addMap;
+
+ addMap = (Map<K,V>) m;
- while (itr.hasNext())
+ for (Map.Entry<K,V> e : addMap.entrySet())
{
- Map.Entry<? extends K, ? extends V> e
- = (Map.Entry<? extends K, ? extends V>) itr.next();
// Optimize in case the Entry is one of our own.
if (e instanceof AbstractMap.BasicMapEntry)
{
@@ -865,15 +864,14 @@ public class Hashtable<K, V> extends Dictionary<K, V>
*/
void putAllInternal(Map<? extends K, ? extends V> m)
{
- Iterator<Map.Entry<? extends K, ? extends V>> itr
- = m.entrySet().iterator();
+ Map<K,V> addMap;
+
+ addMap = (Map<K,V>) m;
size = 0;
- while (itr.hasNext())
+ for (Map.Entry<K,V> e : addMap.entrySet())
{
size++;
- Map.Entry<? extends K, ? extends V> e
- = (Map.Entry<? extends K, ? extends V>) itr.next();
K key = e.getKey();
int idx = hash(key);
HashEntry<K, V> he = new HashEntry<K, V>(key, e.getValue());
diff --git a/java/util/LinkedHashMap.java b/java/util/LinkedHashMap.java
index 107affe30..b646d5149 100644
--- a/java/util/LinkedHashMap.java
+++ b/java/util/LinkedHashMap.java
@@ -132,16 +132,16 @@ public class LinkedHashMap<K,V> extends HashMap<K,V>
* Class to represent an entry in the hash table. Holds a single key-value
* pair and the doubly-linked insertion order list.
*/
- class LinkedHashEntry extends HashEntry
+ class LinkedHashEntry<K,V> extends HashEntry<K,V>
{
/**
* The predecessor in the iteration list. If this entry is the root
* (eldest), pred points to the newest entry.
*/
- LinkedHashEntry pred;
+ LinkedHashEntry<K,V> pred;
/** The successor in the iteration list, null if this is the newest. */
- LinkedHashEntry succ;
+ LinkedHashEntry<K,V> succ;
/**
* Simple constructor.
@@ -149,7 +149,7 @@ public class LinkedHashMap<K,V> extends HashMap<K,V>
* @param key the key
* @param value the value
*/
- LinkedHashEntry(Object key, Object value)
+ LinkedHashEntry(K key, V value)
{
super(key, value);
if (root == null)
@@ -198,7 +198,7 @@ public class LinkedHashMap<K,V> extends HashMap<K,V>
*
* @return the value of this key as it is removed
*/
- Object cleanup()
+ V cleanup()
{
if (this == root)
{
@@ -339,7 +339,7 @@ public class LinkedHashMap<K,V> extends HashMap<K,V>
public V get(Object key)
{
int idx = hash(key);
- HashEntry e = buckets[idx];
+ HashEntry<K,V> e = buckets[idx];
while (e != null)
{
if (equals(key, e.key))
@@ -408,7 +408,7 @@ public class LinkedHashMap<K,V> extends HashMap<K,V>
* @see #removeEldestEntry(Map.Entry)
* @see LinkedHashEntry#LinkedHashEntry(Object, Object)
*/
- void addEntry(Object key, Object value, int idx, boolean callRemove)
+ void addEntry(K key, V value, int idx, boolean callRemove)
{
LinkedHashEntry e = new LinkedHashEntry(key, value);
e.next = buckets[idx];
diff --git a/java/util/LinkedList.java b/java/util/LinkedList.java
index 46c32e5dc..4ca0a4e2f 100644
--- a/java/util/LinkedList.java
+++ b/java/util/LinkedList.java
@@ -701,7 +701,7 @@ public class LinkedList<T> extends AbstractSequentialList<T>
Entry<T> e = first;
for (int i = 0; i < size; i++)
{
- a[i] = (T) e.data;
+ a[i] = (S) e.data;
e = e.next;
}
return a;
@@ -794,21 +794,22 @@ public class LinkedList<T> extends AbstractSequentialList<T>
* position in the list and the two list entries it is between.
*
* @author Original author unknown
- * @author Eric Blake <ebb9@email.byu.edu>
+ * @author Eric Blake (ebb9@email.byu.edu)
*/
- private final class LinkedListItr implements ListIterator<T>
+ private final class LinkedListItr<I>
+ implements ListIterator<I>
{
/** Number of modifications we know about. */
private int knownMod = modCount;
/** Entry that will be returned by next(). */
- private Entry<T> next;
+ private Entry<I> next;
/** Entry that will be returned by previous(). */
- private Entry<T> previous;
+ private Entry<I> previous;
/** Entry that will be affected by remove() or set(). */
- private Entry<T> lastReturned;
+ private Entry<I> lastReturned;
/** Index of `next'. */
private int position;
@@ -823,11 +824,11 @@ public class LinkedList<T> extends AbstractSequentialList<T>
if (index == size)
{
next = null;
- previous = last;
+ previous = (Entry<I>) last;
}
else
{
- next = getEntry(index);
+ next = (Entry<I>) getEntry(index);
previous = next.previous;
}
position = index;
@@ -899,7 +900,7 @@ public class LinkedList<T> extends AbstractSequentialList<T>
* @throws ConcurrentModificationException if the list was modified
* @throws NoSuchElementException if there is no next
*/
- public T next()
+ public I next()
{
checkMod();
if (next == null)
@@ -917,7 +918,7 @@ public class LinkedList<T> extends AbstractSequentialList<T>
* @throws ConcurrentModificationException if the list was modified
* @throws NoSuchElementException if there is no previous
*/
- public T previous()
+ public I previous()
{
checkMod();
if (previous == null)
@@ -947,7 +948,7 @@ public class LinkedList<T> extends AbstractSequentialList<T>
next = lastReturned.next;
previous = lastReturned.previous;
- removeEntry(lastReturned);
+ removeEntry((Entry<T>) lastReturned);
knownMod++;
lastReturned = null;
@@ -959,26 +960,26 @@ public class LinkedList<T> extends AbstractSequentialList<T>
* @param o the element to add
* @throws ConcurrentModificationException if the list was modified
*/
- public void add(T o)
+ public void add(I o)
{
checkMod();
modCount++;
knownMod++;
size++;
position++;
- Entry<T> e = new Entry<T>(o);
+ Entry<I> e = new Entry<I>(o);
e.previous = previous;
e.next = next;
if (previous != null)
previous.next = e;
else
- first = e;
+ first = (Entry<T>) e;
if (next != null)
next.previous = e;
else
- last = e;
+ last = (Entry<T>) e;
previous = e;
lastReturned = null;
@@ -991,7 +992,7 @@ public class LinkedList<T> extends AbstractSequentialList<T>
* @throws ConcurrentModificationException if the list was modified
* @throws IllegalStateException if there was no last element
*/
- public void set(T o)
+ public void set(I o)
{
checkMod();
if (lastReturned == null)
diff --git a/java/util/TreeSet.java b/java/util/TreeSet.java
index d0b169b2c..b7789420b 100644
--- a/java/util/TreeSet.java
+++ b/java/util/TreeSet.java
@@ -149,8 +149,10 @@ public class TreeSet<T> extends AbstractSet<T>
*/
public TreeSet(SortedSet<? extends T> sortedSet)
{
+ Iterator<T> itr;
+
map = new TreeMap<T, String>(sortedSet.comparator());
- Iterator<? extends T> itr = sortedSet.iterator();
+ itr = ((SortedSet<T>) sortedSet).iterator();
((TreeMap<T, String>) map).putKeysLinear(itr, sortedSet.size());
}