src/share/classes/java/util/IdentityHashMap.java

Print this page
rev 4788 : Fix bunch of generics warnings

*** 325,334 **** --- 325,335 ---- * The {@link #containsKey containsKey} operation may be used to * distinguish these two cases. * * @see #put(Object, Object) */ + @SuppressWarnings("unchecked") public V get(Object key) { Object k = maskNull(key); Object[] tab = table; int len = tab.length; int i = hash(k, len);
*** 429,438 **** --- 430,440 ---- int i = hash(k, len); Object item; while ( (item = tab[i]) != null) { if (item == k) { + @SuppressWarnings("unchecked") V oldValue = (V) tab[i + 1]; tab[i + 1] = value; return oldValue; } i = nextKeyIndex(i, len);
*** 522,531 **** --- 524,534 ---- while (true) { Object item = tab[i]; if (item == k) { modCount++; size--; + @SuppressWarnings("unchecked") V oldValue = (V) tab[i + 1]; tab[i + 1] = null; tab[i] = null; closeDeletion(i); return oldValue;
*** 636,646 **** */ public boolean equals(Object o) { if (o == this) { return true; } else if (o instanceof IdentityHashMap) { ! IdentityHashMap m = (IdentityHashMap) o; if (m.size() != size) return false; Object[] tab = m.table; for (int i = 0; i < tab.length; i+=2) { --- 639,649 ---- */ public boolean equals(Object o) { if (o == this) { return true; } else if (o instanceof IdentityHashMap) { ! IdentityHashMap<?,?> m = (IdentityHashMap<?,?>) o; if (m.size() != size) return false; Object[] tab = m.table; for (int i = 0; i < tab.length; i+=2) {
*** 648,658 **** if (k != null && !containsMapping(k, tab[i + 1])) return false; } return true; } else if (o instanceof Map) { ! Map m = (Map)o; return entrySet().equals(m.entrySet()); } else { return false; // o is not a Map } } --- 651,661 ---- if (k != null && !containsMapping(k, tab[i + 1])) return false; } return true; } else if (o instanceof Map) { ! Map<?,?> m = (Map<?,?>)o; return entrySet().equals(m.entrySet()); } else { return false; // o is not a Map } }
*** 696,706 **** * * @return a shallow copy of this map */ public Object clone() { try { ! IdentityHashMap<K,V> m = (IdentityHashMap<K,V>) super.clone(); m.entrySet = null; m.table = table.clone(); return m; } catch (CloneNotSupportedException e) { throw new InternalError(e); --- 699,709 ---- * * @return a shallow copy of this map */ public Object clone() { try { ! IdentityHashMap<?,?> m = (IdentityHashMap<?,?>) super.clone(); m.entrySet = null; m.table = table.clone(); return m; } catch (CloneNotSupportedException e) { throw new InternalError(e);
*** 766,776 **** Object[] tab = traversalTable; int len = tab.length; int d = deletedSlot; ! K key = (K) tab[d]; tab[d] = null; // vacate the slot tab[d + 1] = null; // If traversing a copy, remove in real table. // We can skip gap-closure on copy. --- 769,779 ---- Object[] tab = traversalTable; int len = tab.length; int d = deletedSlot; ! Object key = tab[d]; tab[d] = null; // vacate the slot tab[d + 1] = null; // If traversing a copy, remove in real table. // We can skip gap-closure on copy.
*** 816,831 **** --- 819,836 ---- } } } private class KeyIterator extends IdentityHashMapIterator<K> { + @SuppressWarnings("unchecked") public K next() { return (K) unmaskNull(traversalTable[nextIndex()]); } } private class ValueIterator extends IdentityHashMapIterator<V> { + @SuppressWarnings("unchecked") public V next() { return (V) traversalTable[nextIndex() + 1]; } }
*** 852,871 **** --- 857,879 ---- private Entry(int index) { this.index = index; } + @SuppressWarnings("unchecked") public K getKey() { checkIndexForEntryUse(); return (K) unmaskNull(traversalTable[index]); } + @SuppressWarnings("unchecked") public V getValue() { checkIndexForEntryUse(); return (V) traversalTable[index+1]; } + @SuppressWarnings("unchecked") public V setValue(V value) { checkIndexForEntryUse(); V oldValue = (V) traversalTable[index+1]; traversalTable[index+1] = value; // if shadowing, force into main table
*** 878,888 **** if (index < 0) return super.equals(o); if (!(o instanceof Map.Entry)) return false; ! Map.Entry e = (Map.Entry)o; return (e.getKey() == unmaskNull(traversalTable[index]) && e.getValue() == traversalTable[index+1]); } public int hashCode() { --- 886,896 ---- if (index < 0) return super.equals(o); if (!(o instanceof Map.Entry)) return false; ! Map.Entry<?,?> e = (Map.Entry<?,?>)o; return (e.getKey() == unmaskNull(traversalTable[index]) && e.getValue() == traversalTable[index+1]); } public int hashCode() {
*** 1107,1123 **** return new EntryIterator(); } public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; ! Map.Entry entry = (Map.Entry)o; return containsMapping(entry.getKey(), entry.getValue()); } public boolean remove(Object o) { if (!(o instanceof Map.Entry)) return false; ! Map.Entry entry = (Map.Entry)o; return removeMapping(entry.getKey(), entry.getValue()); } public int size() { return size; } --- 1115,1131 ---- return new EntryIterator(); } public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; ! Map.Entry<?,?> entry = (Map.Entry<?,?>)o; return containsMapping(entry.getKey(), entry.getValue()); } public boolean remove(Object o) { if (!(o instanceof Map.Entry)) return false; ! Map.Entry<?,?> entry = (Map.Entry<?,?>)o; return removeMapping(entry.getKey(), entry.getValue()); } public int size() { return size; }
*** 1211,1221 **** --- 1219,1231 ---- // Allow for 33% growth (i.e., capacity is >= 2* size()). init(capacity((size*4)/3)); // Read the keys and values, and put the mappings in the table for (int i=0; i<size; i++) { + @SuppressWarnings("unchecked") K key = (K) s.readObject(); + @SuppressWarnings("unchecked") V value = (V) s.readObject(); putForCreate(key, value); } }
*** 1224,1234 **** * update modCount, etc. */ private void putForCreate(K key, V value) throws IOException { ! K k = (K)maskNull(key); Object[] tab = table; int len = tab.length; int i = hash(k, len); Object item; --- 1234,1244 ---- * update modCount, etc. */ private void putForCreate(K key, V value) throws IOException { ! Object k = maskNull(key); Object[] tab = table; int len = tab.length; int i = hash(k, len); Object item;