Index: /modules/luni/src/main/java/java/util/MapEntry.java =================================================================== --- /modules/luni/src/main/java/java/util/MapEntry.java (revision 409283) +++ /modules/luni/src/main/java/java/util/MapEntry.java (working copy) @@ -24,8 +24,8 @@ K key; V value; - interface Type { - Object get(MapEntry entry); + interface Type { + RT get(MapEntry entry); } MapEntry(K theKey) { Index: /modules/luni/src/main/java/java/util/HashMap.java =================================================================== --- /modules/luni/src/main/java/java/util/HashMap.java (revision 409283) +++ /modules/luni/src/main/java/java/util/HashMap.java (working copy) @@ -30,7 +30,7 @@ transient int elementCount; - transient Entry[] elementData; + transient Entry[] elementData; final float loadFactor; @@ -51,9 +51,9 @@ } public Object clone() { - Entry entry = (Entry) super.clone(); + Entry entry = (Entry) super.clone(); if (next != null) - entry.next = (Entry) next.clone(); + entry.next = (Entry) next.clone(); return entry; } @@ -66,22 +66,22 @@ } } - static class HashMapIterator implements Iterator { + static class HashMapIterator implements Iterator { private int position = 0; int expectedModCount; - final MapEntry.Type type; + final MapEntry.Type type; boolean canRemove = false; - Entry entry; + Entry entry; - Entry lastEntry; + Entry lastEntry; - final HashMap associatedMap; + final HashMap associatedMap; - HashMapIterator(MapEntry.Type value, HashMap hm) { + HashMapIterator(MapEntry.Type value, HashMap hm) { associatedMap = hm; type = value; expectedModCount = hm.modCount; @@ -104,12 +104,12 @@ throw new ConcurrentModificationException(); } - public Object next() { + public E next() { checkConcurrentMod(); if (!hasNext()) throw new NoSuchElementException(); - Entry result; + MapEntry result; if (entry == null) { result = lastEntry = associatedMap.elementData[position++]; entry = lastEntry.next; @@ -142,14 +142,14 @@ } } - static class HashMapEntrySet extends AbstractSet { - private final HashMap associatedMap; + static class HashMapEntrySet extends AbstractSet> { + private final HashMap associatedMap; - public HashMapEntrySet(HashMap hm) { + public HashMapEntrySet(HashMap hm) { associatedMap = hm; } - HashMap hashMap() { + HashMap hashMap() { return associatedMap; } @@ -178,9 +178,9 @@ return false; } - public Iterator iterator() { - return new HashMapIterator(new MapEntry.Type() { - public Object get(MapEntry entry) { + public Iterator> iterator() { + return new HashMapIterator,KT,VT>(new MapEntry.Type, KT, VT>() { + public Map.Entry get(MapEntry entry) { return entry; } }, associatedMap); @@ -193,8 +193,8 @@ * @param s * @return Reference to the element array */ - Entry[] newElementArray(int s) { - return new Entry[s]; + Entry[] newElementArray(int s) { + return (Entry[])new Entry[s]; } /** @@ -255,7 +255,7 @@ * @param map * the mappings to add */ - public HashMap(Map map) { + public HashMap(Map map) { this(map.size() < 6 ? 11 : map.size() * 2); putAll(map); } @@ -283,12 +283,12 @@ */ public Object clone() { try { - HashMap map = (HashMap) super.clone(); + HashMap map = (HashMap) super.clone(); map.elementData = newElementArray(elementData.length); - Entry entry; + Entry entry; for (int i = 0; i < elementData.length; i++) { if ((entry = elementData[i]) != null) - map.elementData[i] = (Entry) entry.clone(); + map.elementData[i] = (Entry) entry.clone(); } return map; } catch (CloneNotSupportedException e) { @@ -337,7 +337,7 @@ public boolean containsValue(Object value) { if (value != null) { for (int i = elementData.length; --i >= 0;) { - Entry entry = elementData[i]; + Entry entry = elementData[i]; while (entry != null) { if (value.equals(entry.value)) return true; @@ -346,7 +346,7 @@ } } else { for (int i = elementData.length; --i >= 0;) { - Entry entry = elementData[i]; + Entry entry = elementData[i]; while (entry != null) { if (entry.value == null) return true; @@ -364,8 +364,8 @@ * * @return a Set of the mappings */ - public Set entrySet() { - return new HashMapEntrySet(this); + public Set> entrySet() { + return new HashMapEntrySet(this); } /** @@ -383,7 +383,7 @@ return null; } - Entry getEntry(Object key) { + Entry getEntry(Object key) { int index = getModuloHash(key); return findEntry(key, index); } @@ -394,8 +394,8 @@ return (key.hashCode() & 0x7FFFFFFF) % elementData.length; } - Entry findEntry(Object key, int index) { - Entry m; + Entry findEntry(Object key, int index) { + Entry m; m = elementData[index]; if (key != null) { while (m != null && !keysEqual(key, m)) { @@ -428,7 +428,7 @@ */ public Set keySet() { if (keySet == null) { - keySet = new AbstractSet() { + keySet = new AbstractSet() { public boolean contains(Object object) { return containsKey(object); } @@ -449,9 +449,9 @@ return false; } - public Iterator iterator() { - return new HashMapIterator(new MapEntry.Type() { - public Object get(MapEntry entry) { + public Iterator iterator() { + return new HashMapIterator(new MapEntry.Type() { + public K get(MapEntry entry) { return entry.key; } }, HashMap.this); @@ -489,8 +489,8 @@ return result; } - Entry createEntry(Object key, int index, Object value) { - Entry entry = new Entry(key, value); + Entry createEntry(K key, int index, V value) { + Entry entry = new Entry(key, value); entry.next = elementData[index]; elementData[index] = entry; return entry; @@ -502,7 +502,7 @@ * @param map * the Map to copy mappings from */ - public void putAll(Map map) { + public void putAll(Map map) { super.putAll(map); } @@ -510,14 +510,14 @@ int length = elementData.length << 1; if (length == 0) length = 1; - Entry[] newData = newElementArray(length); + Entry[] newData = newElementArray(length); for (int i = 0; i < elementData.length; i++) { - Entry entry = elementData[i]; + Entry entry = elementData[i]; while (entry != null) { Object key = entry.key; int index = key == null ? 0 : (key.hashCode() & 0x7FFFFFFF) % length; - Entry next = entry.next; + Entry next = entry.next; entry.next = newData[index]; newData[index] = entry; entry = next; @@ -543,10 +543,10 @@ return null; } - Entry removeEntry(Object key) { + Entry removeEntry(Object key) { int index = 0; - Entry entry; - Entry last = null; + Entry entry; + Entry last = null; if (key != null) { index = (key.hashCode() & 0x7FFFFFFF) % elementData.length; entry = elementData[index]; @@ -590,7 +590,7 @@ */ public Collection values() { if (valuesCollection == null) { - valuesCollection = new AbstractCollection() { + valuesCollection = new AbstractCollection() { public boolean contains(Object object) { return containsValue(object); } @@ -603,9 +603,9 @@ HashMap.this.clear(); } - public Iterator iterator() { - return new HashMapIterator(new MapEntry.Type() { - public Object get(MapEntry entry) { + public Iterator iterator() { + return new HashMapIterator(new MapEntry.Type() { + public V get(MapEntry entry) { return entry.value; } }, HashMap.this); @@ -632,12 +632,12 @@ ClassNotFoundException { stream.defaultReadObject(); int length = stream.readInt(); - elementData = new Entry[length]; + elementData = (Entry[])new Entry[length]; elementCount = stream.readInt(); for (int i = elementCount; --i >= 0;) { - Object key = stream.readObject(); + K key = (K)stream.readObject(); int index = (key.hashCode() & 0x7FFFFFFF) % length; - createEntry(key, index, stream.readObject()); + createEntry(key, index, (V)stream.readObject()); } } }