This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git


The following commit(s) were added to refs/heads/master by this push:
     new bdb322e3 Use Collectors.toMap() instead of forEach() to build the 
result map
bdb322e3 is described below

commit bdb322e323f46ae89e752965450cb9f99d8d8a13
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Jul 8 18:24:07 2023 -0400

    Use Collectors.toMap() instead of forEach() to build the result map
---
 src/main/java/org/apache/commons/pool2/PoolUtils.java | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/pool2/PoolUtils.java 
b/src/main/java/org/apache/commons/pool2/PoolUtils.java
index 57324bd1..9c350c31 100644
--- a/src/main/java/org/apache/commons/pool2/PoolUtils.java
+++ b/src/main/java/org/apache/commons/pool2/PoolUtils.java
@@ -27,6 +27,8 @@ import java.util.TimerTask;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * This class consists exclusively of static methods that operate on or return
@@ -1360,9 +1362,8 @@ public final class PoolUtils {
         if (keys == null) {
             throw new IllegalArgumentException(MSG_NULL_KEYS);
         }
-        final Map<K, TimerTask> tasks = new HashMap<>(keys.size());
-        keys.forEach(key -> tasks.put(key, checkMinIdle(keyedPool, key, 
minIdle, periodMillis)));
-        return tasks;
+        return keys.stream().collect(Collectors.toMap(Function.identity(),
+                k -> checkMinIdle(keyedPool, k, minIdle, periodMillis), (k, v) 
-> v));
     }
 
     /**

Reply via email to