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 af38a4e [POOL-380] Deprecate PoolUtils.prefill(KeyedObjectPool,
Collection, int) in favor of KeyedObjectPool.addObjects(Collection, int).
af38a4e is described below
commit af38a4e32582cee6471110309a8f47ee441f9280
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Oct 8 11:19:49 2019 -0400
[POOL-380] Deprecate PoolUtils.prefill(KeyedObjectPool, Collection, int)
in favor of KeyedObjectPool.addObjects(Collection, int).
---
src/changes/changes.xml | 3 +++
.../org/apache/commons/pool2/KeyedObjectPool.java | 31 +++++++++++++++++++++-
.../java/org/apache/commons/pool2/ObjectPool.java | 2 +-
.../java/org/apache/commons/pool2/PoolUtils.java | 9 +++----
.../org/apache/commons/pool2/TestPoolUtils.java | 11 ++++----
5 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 41f66b0..68ea163 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -68,6 +68,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" issue="POOL-379" type="add" due-to="Gary Gregory">
Deprecate PoolUtils.prefill(KeyedObjectPool, K, int) in favor of
KeyedObjectPool.addObjects(K, int).
</action>
+ <action dev="ggregory" issue="POOL-380" type="add" due-to="Gary Gregory">
+ Deprecate PoolUtils.prefill(KeyedObjectPool, Collection, int) in favor
of KeyedObjectPool.addObjects(Collection, int).
+ </action>
</release>
<release version="2.7.0" date="2019-07-25" description="This is a feature
release (Java 8).">
<action dev="ggregory" issue="POOL-364" type="update" due-to="Gary
Gregory">
diff --git a/src/main/java/org/apache/commons/pool2/KeyedObjectPool.java
b/src/main/java/org/apache/commons/pool2/KeyedObjectPool.java
index cbafbb1..ccf9f72 100644
--- a/src/main/java/org/apache/commons/pool2/KeyedObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/KeyedObjectPool.java
@@ -17,6 +17,8 @@
package org.apache.commons.pool2;
import java.io.Closeable;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.NoSuchElementException;
/**
@@ -86,7 +88,34 @@ public interface KeyedObjectPool<K, V> extends Closeable {
UnsupportedOperationException;
/**
- * Calls {@link KeyedObjectPool#addObject(Object)} on
<code>keyedPool</code> with
+ * Calls {@link KeyedObjectPool#addObject(Object)} with each
+ * key in <code>keys</code> for <code>count</code> number of times. This
has
+ * the same effect as calling {@link #addObjects(Object, int)}
+ * for each key in the <code>keys</code> collection.
+ *
+ * @param keys
+ * {@link Collection} of keys to add objects for.
+ * @param count
+ * the number of idle objects to add for each <code>key</code>.
+ * @throws Exception
+ * when {@link KeyedObjectPool#addObject(Object)} fails.
+ * @throws IllegalArgumentException
+ * when <code>keyedPool</code>, <code>keys</code>, or any value
+ * in <code>keys</code> is <code>null</code>.
+ * @see #addObjects(Object, int)
+ */
+ default void addObjects(final Collection<K> keys, final int count) throws
Exception, IllegalArgumentException {
+ if (keys == null) {
+ throw new IllegalArgumentException(PoolUtils.MSG_NULL_KEYS);
+ }
+ final Iterator<K> iter = keys.iterator();
+ while (iter.hasNext()) {
+ addObjects(iter.next(), count);
+ }
+ }
+
+ /**
+ * Calls {@link KeyedObjectPool#addObject(Object)}
* <code>key</code> <code>count</code> number of times.
*
* @param key
diff --git a/src/main/java/org/apache/commons/pool2/ObjectPool.java
b/src/main/java/org/apache/commons/pool2/ObjectPool.java
index 18aa41e..6b8086a 100644
--- a/src/main/java/org/apache/commons/pool2/ObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/ObjectPool.java
@@ -76,7 +76,7 @@ public interface ObjectPool<T> extends Closeable {
UnsupportedOperationException;
/**
- * Calls {@link ObjectPool#addObject()} on <code>pool</code>
<code>count</code>
+ * Calls {@link ObjectPool#addObject()} <code>count</code>
* number of times.
*
* @param count
diff --git a/src/main/java/org/apache/commons/pool2/PoolUtils.java
b/src/main/java/org/apache/commons/pool2/PoolUtils.java
index 9d3d3c0..ad5706d 100644
--- a/src/main/java/org/apache/commons/pool2/PoolUtils.java
+++ b/src/main/java/org/apache/commons/pool2/PoolUtils.java
@@ -40,7 +40,7 @@ public final class PoolUtils {
private static final String MSG_MIN_IDLE = "minIdle must be non-negative.";
static final String MSG_NULL_KEY = "key must not be null.";
private static final String MSG_NULL_KEYED_POOL = "keyedPool must not be
null.";
- private static final String MSG_NULL_KEYS = "keys must not be null.";
+ static final String MSG_NULL_KEYS = "keys must not be null.";
private static final String MSG_NULL_POOL = "pool must not be null.";
/**
@@ -280,17 +280,16 @@ public final class PoolUtils {
* when <code>keyedPool</code>, <code>keys</code>, or any value
* in <code>keys</code> is <code>null</code>.
* @see #prefill(KeyedObjectPool, Object, int)
+ * @deprecated Use {@link KeyedObjectPool#addObjects(Collection, int)}.
*/
+ @Deprecated
public static <K, V> void prefill(final KeyedObjectPool<K, V> keyedPool,
final Collection<K> keys, final int count) throws Exception,
IllegalArgumentException {
if (keys == null) {
throw new IllegalArgumentException(MSG_NULL_KEYS);
}
- final Iterator<K> iter = keys.iterator();
- while (iter.hasNext()) {
- keyedPool.addObjects(iter.next(), count);
- }
+ keyedPool.addObjects(keys, count);
}
/**
diff --git a/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
b/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
index d99c6ae..a5fd2a6 100644
--- a/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
+++ b/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
@@ -292,6 +292,7 @@ public class TestPoolUtils {
}
}
+ @SuppressWarnings("deprecation")
@Test
public void testPrefillObjectPool() throws Exception {
try {
@@ -316,6 +317,7 @@ public class TestPoolUtils {
}
}
+ @SuppressWarnings("deprecation")
@Test
public void testPrefillKeyedObjectPool() throws Exception {
try {
@@ -324,8 +326,8 @@ public class TestPoolUtils {
} catch (final IllegalArgumentException iae) {
// expected
}
- try (@SuppressWarnings("unchecked")
- final KeyedObjectPool<Object, String> pool = new
GenericKeyedObjectPool<>(new TestGenericKeyedObjectPool.SimpleFactory<>())) {
+ try (final KeyedObjectPool<Object, String> pool = new
GenericKeyedObjectPool<>(
+ new TestGenericKeyedObjectPool.SimpleFactory<>())) {
PoolUtils.prefill(pool, (Object) null, 1);
fail("PoolUtils.prefill(KeyedObjectPool,Object,int) must not
accept null key.");
} catch (final IllegalArgumentException iae) {
@@ -347,6 +349,7 @@ public class TestPoolUtils {
}
}
+ @SuppressWarnings("deprecation")
@Test
public void testPrefillKeyedObjectPoolCollection() throws Exception {
try (@SuppressWarnings("unchecked")
@@ -364,6 +367,7 @@ public class TestPoolUtils {
final Set<String> keys = new HashSet<>();
PoolUtils.prefill(pool, keys, 0);
final List<String> expectedMethods = new ArrayList<>();
+ expectedMethods.add("addObjects");
assertEquals(expectedMethods, calledMethods);
calledMethods.clear();
@@ -372,9 +376,6 @@ public class TestPoolUtils {
keys.add("three");
final int count = 3;
PoolUtils.prefill(pool, keys, count);
- for (int i = 0; i < count; i++) {
- expectedMethods.add("addObjects");
- }
assertEquals(expectedMethods, calledMethods);
}
}