Index: ChangeLog =================================================================== RCS file: /cvsroot/classpath/classpath/ChangeLog,v retrieving revision 1.2386.2.48 diff -u -3 -p -u -r1.2386.2.48 ChangeLog --- ChangeLog 12 Jan 2005 20:06:42 -0000 1.2386.2.48 +++ ChangeLog 13 Jan 2005 11:07:08 -0000 @@ -1,3 +1,40 @@ +2005-01-13 Andrew John Hughes + + * java/util/Arrays.java: + (sort(T[],int,int,Comparator)): Typed + Object[] to T[] + * java/util/Collections.java; + (compare(T,T,)): typed generically + (binarySearch(List,T,Comparator)): + re-typed and added casts to List + (rotate(List, int)): added (incorrect?) + super type to compile + (shuffle(List): likewise + (shuffle(List,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> + (putAll(Map)): cast and foreach + statement added + (putAllInternal(Map)): 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): re-typed to unique I from T + * java/util/TreeSet.java: + cast set to SortedSet before using + 2005-01-12 Andrew John Hughes * java/util/Collections.java Index: java/util/Arrays.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/util/Arrays.java,v retrieving revision 1.20.2.4 diff -u -3 -p -u -r1.20.2.4 Arrays.java --- java/util/Arrays.java 12 Jan 2005 01:12:48 -0000 1.20.2.4 +++ java/util/Arrays.java 13 Jan 2005 11:07:10 -0000 @@ -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; Index: java/util/Collections.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/util/Collections.java,v retrieving revision 1.28.2.7 diff -u -3 -p -u -r1.28.2.7 Collections.java --- java/util/Collections.java 12 Jan 2005 20:06:43 -0000 1.28.2.7 +++ java/util/Collections.java 13 Jan 2005 11:07:10 -0000 @@ -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 int compare(T o1, T o2, Comparator 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 int binarySearch(List l, T key, Comparator c) + public static int binarySearch(List l, T key, + Comparator c) { int pos = 0; int low = 0; @@ -573,7 +574,7 @@ public class Collections // if the list is sequential-access. if (isSequential(l)) { - ListIterator itr = l.listIterator(); + ListIterator itr = ((List) 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) 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 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 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 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 address@hidden #singletonMap(Object)}. This class name * is required for compatibility with Sun's JDK serializability. * - * @author Eric Blake + * @author Eric Blake (address@hidden) */ private static final class SingletonMap extends AbstractMap implements Serializable @@ -1563,7 +1567,7 @@ public class Collections /** * Cache the entry set. */ - private transient Set> entries; + private transient Set> entries; /** * Construct a singleton. @@ -1582,13 +1586,16 @@ public class Collections public Set> entrySet() { if (entries == null) - entries = singleton(new AbstractMap.BasicMapEntry(k, v) - { - public V setValue(V o) - { - throw new UnsupportedOperationException(); - } - }); + { + Map.Entry entry = new AbstractMap.BasicMapEntry(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 l, int i, int j) { l.set(i, l.set(j, l.get(i))); } @@ -3306,7 +3314,7 @@ public class Collections * The implementation of address@hidden #unmodifiableMap(Map)}. This * class name is required for compatibility with Sun's JDK serializability. * - * @author Eric Blake + * @author Eric Blake (address@hidden) */ private static class UnmodifiableMap implements Map, Serializable { @@ -3366,7 +3374,7 @@ public class Collections public Set> entrySet() { if (entries == null) - entries = new UnmodifiableEntrySet>(m.entrySet()); + entries = new UnmodifiableEntrySet>(m.entrySet()); return entries; } @@ -3376,7 +3384,7 @@ public class Collections * * @author Eric Blake */ - private static final class UnmodifiableEntrySet> + private static final class UnmodifiableEntrySet extends UnmodifiableSet implements Serializable { @@ -3401,18 +3409,18 @@ public class Collections { public T next() { - final T e = super.next(); - return new Map.Entry() + 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(); } Index: java/util/HashMap.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/util/HashMap.java,v retrieving revision 1.28.2.4 diff -u -3 -p -u -r1.28.2.4 HashMap.java --- java/util/HashMap.java 12 Jan 2005 01:12:48 -0000 1.28.2.4 +++ java/util/HashMap.java 13 Jan 2005 11:07:10 -0000 @@ -154,7 +154,7 @@ public class HashMap extends Abstr /** * The cache for address@hidden #entrySet()}. */ - private transient Set> entries; + private transient Set> entries; /** * Class to represent an entry in the hash table. Holds a single key-value @@ -380,11 +380,11 @@ public class HashMap extends Abstr */ public void putAll(Map m) { - Iterator> itr - = m.entrySet().iterator(); - while (itr.hasNext()) + Map addMap; + + addMap = (Map) m; + for (Map.Entry e : addMap.entrySet()) { - Map.Entry 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 extends Abstr */ void putAllInternal(Map m) { - Iterator> itr - = m.entrySet().iterator(); + Map addMap; + + addMap = (Map) m; size = 0; - while (itr.hasNext()) + for (Map.Entry e : addMap.entrySet()) { size++; - Map.Entry e = itr.next(); K key = e.getKey(); int idx = hash(key); addEntry(key, e.getValue(), idx, false); Index: java/util/Hashtable.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/util/Hashtable.java,v retrieving revision 1.32.2.4 diff -u -3 -p -u -r1.32.2.4 Hashtable.java --- java/util/Hashtable.java 12 Jan 2005 13:13:56 -0000 1.32.2.4 +++ java/util/Hashtable.java 13 Jan 2005 11:07:10 -0000 @@ -172,7 +172,7 @@ public class Hashtable extends Dic /** * The cache for address@hidden #entrySet()}. */ - private transient Set> entries; + private transient Set> entries; /** * Class to represent an entry in the hash table. Holds a single key-value @@ -511,13 +511,12 @@ public class Hashtable extends Dic */ public synchronized void putAll(Map m) { - Iterator> itr - = m.entrySet().iterator(); + Map addMap; + + addMap = (Map) m; - while (itr.hasNext()) + for (Map.Entry e : addMap.entrySet()) { - Map.Entry e - = (Map.Entry) itr.next(); // Optimize in case the Entry is one of our own. if (e instanceof AbstractMap.BasicMapEntry) { @@ -865,15 +864,14 @@ public class Hashtable extends Dic */ void putAllInternal(Map m) { - Iterator> itr - = m.entrySet().iterator(); + Map addMap; + + addMap = (Map) m; size = 0; - while (itr.hasNext()) + for (Map.Entry e : addMap.entrySet()) { size++; - Map.Entry e - = (Map.Entry) itr.next(); K key = e.getKey(); int idx = hash(key); HashEntry he = new HashEntry(key, e.getValue()); Index: java/util/LinkedHashMap.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/util/LinkedHashMap.java,v retrieving revision 1.6.2.1 diff -u -3 -p -u -r1.6.2.1 LinkedHashMap.java --- java/util/LinkedHashMap.java 10 Jan 2005 18:25:48 -0000 1.6.2.1 +++ java/util/LinkedHashMap.java 13 Jan 2005 11:07:10 -0000 @@ -132,16 +132,16 @@ public class LinkedHashMap extends * 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 extends HashEntry { /** * The predecessor in the iteration list. If this entry is the root * (eldest), pred points to the newest entry. */ - LinkedHashEntry pred; + LinkedHashEntry pred; /** The successor in the iteration list, null if this is the newest. */ - LinkedHashEntry succ; + LinkedHashEntry succ; /** * Simple constructor. @@ -149,7 +149,7 @@ public class LinkedHashMap extends * @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 extends * * @return the value of this key as it is removed */ - Object cleanup() + V cleanup() { if (this == root) { @@ -339,7 +339,7 @@ public class LinkedHashMap extends public V get(Object key) { int idx = hash(key); - HashEntry e = buckets[idx]; + HashEntry e = buckets[idx]; while (e != null) { if (equals(key, e.key)) @@ -408,7 +408,7 @@ public class LinkedHashMap extends * @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]; Index: java/util/LinkedList.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/util/LinkedList.java,v retrieving revision 1.23.2.4 diff -u -3 -p -u -r1.23.2.4 LinkedList.java --- java/util/LinkedList.java 12 Jan 2005 01:12:48 -0000 1.23.2.4 +++ java/util/LinkedList.java 13 Jan 2005 11:07:11 -0000 @@ -701,7 +701,7 @@ public class LinkedList extends Abstr Entry 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 extends Abstr * position in the list and the two list entries it is between. * * @author Original author unknown - * @author Eric Blake + * @author Eric Blake (address@hidden) */ - private final class LinkedListItr implements ListIterator + private final class LinkedListItr + implements ListIterator { /** Number of modifications we know about. */ private int knownMod = modCount; /** Entry that will be returned by next(). */ - private Entry next; + private Entry next; /** Entry that will be returned by previous(). */ - private Entry previous; + private Entry previous; /** Entry that will be affected by remove() or set(). */ - private Entry lastReturned; + private Entry lastReturned; /** Index of `next'. */ private int position; @@ -823,11 +824,11 @@ public class LinkedList extends Abstr if (index == size) { next = null; - previous = last; + previous = (Entry) last; } else { - next = getEntry(index); + next = (Entry) getEntry(index); previous = next.previous; } position = index; @@ -899,7 +900,7 @@ public class LinkedList extends Abstr * @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 extends Abstr * @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 extends Abstr next = lastReturned.next; previous = lastReturned.previous; - removeEntry(lastReturned); + removeEntry((Entry) lastReturned); knownMod++; lastReturned = null; @@ -959,26 +960,26 @@ public class LinkedList extends Abstr * @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 e = new Entry(o); + Entry e = new Entry(o); e.previous = previous; e.next = next; if (previous != null) previous.next = e; else - first = e; + first = (Entry) e; if (next != null) next.previous = e; else - last = e; + last = (Entry) e; previous = e; lastReturned = null; @@ -991,7 +992,7 @@ public class LinkedList extends Abstr * @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) Index: java/util/TreeSet.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/util/TreeSet.java,v retrieving revision 1.15.2.4 diff -u -3 -p -u -r1.15.2.4 TreeSet.java --- java/util/TreeSet.java 12 Jan 2005 01:12:48 -0000 1.15.2.4 +++ java/util/TreeSet.java 13 Jan 2005 11:07:11 -0000 @@ -149,8 +149,10 @@ public class TreeSet extends Abstract */ public TreeSet(SortedSet sortedSet) { + Iterator itr; + map = new TreeMap(sortedSet.comparator()); - Iterator itr = sortedSet.iterator(); + itr = ((SortedSet) sortedSet).iterator(); ((TreeMap) map).putKeysLinear(itr, sortedSet.size()); }