Created
March 20, 2015 01:54
-
-
Save ThomasLau/27c9880b5af7e5989ded to your computer and use it in GitHub Desktop.
new function method HashTable.forEach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressWarnings("unchecked") | |
@Override | |
public synchronized void forEach(BiConsumer<? super K, ? super V> action) { | |
Objects.requireNonNull(action); // explicit check required in case | |
// table is empty. | |
final int expectedModCount = modCount; | |
Entry<?, ?>[] tab = table; | |
for (Entry<?, ?> entry : tab) { | |
while (entry != null) { | |
action.accept((K)entry.key, (V)entry.value); | |
entry = entry.next; | |
if (expectedModCount != modCount) { | |
throw new ConcurrentModificationException(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment