privateabstractclassHashIterator<E> implementsIterator<E> { Entry<K,V> next; // next entry to return int expectedModCount; // For fast-fail int index; // current slot Entry<K,V> current; // current entry
HashIterator() { expectedModCount = modCount; if (size > 0) { // advance to first entry Entry[] t = table; while (index < t.length && (next = t[index++]) == null) ; } }
publicfinalbooleanhasNext() { return next != null; }
final Entry<K,V> nextEntry() { if (modCount != expectedModCount) thrownewConcurrentModificationException(); Entry<K,V> e = next; if (e == null) thrownewNoSuchElementException();
if ((next = e.next) == null) { Entry[] t = table; while (index < t.length && (next = t[index++]) == null) ; } current = e; return e; }
publicvoidremove() { if (current == null) thrownewIllegalStateException(); if (modCount != expectedModCount) thrownewConcurrentModificationException(); Objectk= current.key; current = null; HashMap.this.removeEntryForKey(k); expectedModCount = modCount; } }