Skip to content

Commit

Permalink
Use enhanced for loops rather than iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Sep 2, 2021
1 parent faf335c commit 50fb382
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/main/java/org/apache/commons/pool2/KeyedObjectPool.java
Expand Up @@ -18,7 +18,6 @@

import java.io.Closeable;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;

/**
Expand Down Expand Up @@ -108,9 +107,8 @@ default void addObjects(final Collection<K> keys, final int count) throws Except
if (keys == null) {
throw new IllegalArgumentException(PoolUtils.MSG_NULL_KEYS);
}
final Iterator<K> iter = keys.iterator();
while (iter.hasNext()) {
addObjects(iter.next(), count);
for (final K key : keys) {
addObjects(key, count);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/apache/commons/pool2/PoolUtils.java
Expand Up @@ -19,7 +19,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Timer;
Expand Down Expand Up @@ -1351,9 +1350,7 @@ public static <K, V> Map<K, TimerTask> checkMinIdle(
throw new IllegalArgumentException(MSG_NULL_KEYS);
}
final Map<K, TimerTask> tasks = new HashMap<>(keys.size());
final Iterator<K> iter = keys.iterator();
while (iter.hasNext()) {
final K key = iter.next();
for (final K key : keys) {
final TimerTask task = checkMinIdle(keyedPool, key, minIdle, periodMillis);
tasks.put(key, task);
}
Expand Down

0 comments on commit 50fb382

Please sign in to comment.