commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1221705 [6/9] - in /commons/proper/pool/branches/POOL_1_X: ./ src/java/org/apache/commons/pool/ src/java/org/apache/commons/pool/impl/ src/site/ src/site/xdoc/ src/test/org/apache/commons/pool/ src/test/org/apache/commons/pool/impl/ src/te...
Date Wed, 21 Dec 2011 13:03:55 GMT
Modified: commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/TestPoolUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/TestPoolUtils.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/TestPoolUtils.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/TestPoolUtils.java Wed Dec 21 13:03:54 2011
@@ -59,7 +59,7 @@ public class TestPoolUtils extends TestC
 
     public void testAdaptKeyedPoolableObjectFactory() throws Exception {
         try {
-            PoolUtils.adapt((KeyedPoolableObjectFactory)null);
+            PoolUtils.adapt((KeyedPoolableObjectFactory<Object, Object>)null);
             fail("PoolUtils.adapt(KeyedPoolableObjectFactory) must not allow null factory.");
         } catch (IllegalArgumentException iae) {
             // expected
@@ -68,47 +68,50 @@ public class TestPoolUtils extends TestC
 
     public void testAdaptKeyedPoolableObjectFactoryKey() throws Exception {
         try {
-            PoolUtils.adapt((KeyedPoolableObjectFactory)null, new Object());
+            PoolUtils.adapt((KeyedPoolableObjectFactory<Object, Object>)null, new Object());
             fail("PoolUtils.adapt(KeyedPoolableObjectFactory, key) must not allow null factory.");
         } catch (IllegalArgumentException iae) {
             // expected
         }
         try {
-            PoolUtils.adapt((KeyedPoolableObjectFactory)createProxy(KeyedPoolableObjectFactory.class, (List)null), null);
+            @SuppressWarnings("unchecked")
+            final KeyedPoolableObjectFactory<Object, Object> proxy = createProxy(KeyedPoolableObjectFactory.class, (List<String>)null);
+            PoolUtils.adapt(proxy, null);
             fail("PoolUtils.adapt(KeyedPoolableObjectFactory, key) must not allow null key.");
         } catch (IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final KeyedPoolableObjectFactory kpof =
-                (KeyedPoolableObjectFactory)createProxy(KeyedPoolableObjectFactory.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        final KeyedPoolableObjectFactory<Object, Object> kpof =
+                createProxy(KeyedPoolableObjectFactory.class, calledMethods);
 
-        final PoolableObjectFactory pof = PoolUtils.adapt(kpof);
-        final List expectedMethods = invokeEveryMethod(pof);
+        final PoolableObjectFactory<Object> pof = PoolUtils.adapt(kpof);
+        final List<String> expectedMethods = invokeEveryMethod(pof);
         assertEquals(expectedMethods, calledMethods);
     }
 
     public void testAdaptPoolableObjectFactory() throws Exception {
         try {
-            PoolUtils.adapt((PoolableObjectFactory)null);
+            PoolUtils.adapt((PoolableObjectFactory<?>)null);
             fail("PoolUtils.adapt(PoolableObjectFactory) must not allow null factory.");
         } catch (IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final PoolableObjectFactory pof =
-                (PoolableObjectFactory)createProxy(PoolableObjectFactory.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        final PoolableObjectFactory<?> pof =
+                createProxy(PoolableObjectFactory.class, calledMethods);
 
-        final KeyedPoolableObjectFactory kpof = PoolUtils.adapt(pof);
-        final List expectedMethods = invokeEveryMethod(kpof);
+        final KeyedPoolableObjectFactory<?, ?> kpof = PoolUtils.adapt(pof);
+        final List<String> expectedMethods = invokeEveryMethod(kpof);
         assertEquals(expectedMethods, calledMethods);
     }
 
     public void testAdaptKeyedObjectPool() throws Exception {
         try {
-            PoolUtils.adapt((KeyedObjectPool)null);
+            PoolUtils.adapt((KeyedObjectPool<Object ,?>)null);
             fail("PoolUtils.adapt(KeyedObjectPool) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
@@ -117,86 +120,96 @@ public class TestPoolUtils extends TestC
 
     public void testAdaptKeyedObjectPoolKey() throws Exception {
         try {
-            PoolUtils.adapt((KeyedObjectPool)null, new Object());
+            PoolUtils.adapt((KeyedObjectPool<Object, Object>)null, new Object());
             fail("PoolUtils.adapt(KeyedObjectPool, key) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
         try {
-            PoolUtils.adapt((KeyedObjectPool)createProxy(KeyedObjectPool.class, (List)null), null);
+            @SuppressWarnings("unchecked")
+            final KeyedObjectPool<Object, Object> proxy = createProxy(KeyedObjectPool.class, (List<String>)null);
+            PoolUtils.adapt(proxy, null);
             fail("PoolUtils.adapt(KeyedObjectPool, key) must not allow a null key.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final KeyedObjectPool kop = (KeyedObjectPool)createProxy(KeyedObjectPool.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        final KeyedObjectPool<Object, Object> kop = createProxy(KeyedObjectPool.class, calledMethods);
 
-        final ObjectPool op = PoolUtils.adapt(kop, new Object());
-        final List expectedMethods = invokeEveryMethod(op);
+        final ObjectPool<Object> op = PoolUtils.adapt(kop, new Object());
+        final List<String> expectedMethods = invokeEveryMethod(op);
         assertEquals(expectedMethods, calledMethods);
     }
 
     public void testAdaptObjectPool() throws Exception {
         try {
-            PoolUtils.adapt((ObjectPool)null);
+            PoolUtils.adapt((ObjectPool<?>)null);
             fail("PoolUtils.adapt(ObjectPool) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final ObjectPool op = (ObjectPool)createProxy(ObjectPool.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        final ObjectPool<Object> op = createProxy(ObjectPool.class, calledMethods);
 
-        final KeyedObjectPool kop = PoolUtils.adapt(op);
-        final List expectedMethods = invokeEveryMethod(kop);
+        final KeyedObjectPool<Object, Object> kop = PoolUtils.adapt(op);
+        final List<String> expectedMethods = invokeEveryMethod(kop);
         assertEquals(expectedMethods, calledMethods);
     }
 
     public void testCheckedPoolObjectPool() throws Exception {
         try {
-            PoolUtils.checkedPool((ObjectPool)null, Object.class);
+            PoolUtils.checkedPool((ObjectPool<Object>)null, Object.class);
             fail("PoolUtils.checkedPool(ObjectPool, Class) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
         try {
-            PoolUtils.checkedPool((ObjectPool)createProxy(ObjectPool.class, (List)null), null);
+            final ObjectPool<?> proxy = createProxy(ObjectPool.class, (List<String>)null);
+            PoolUtils.checkedPool(proxy, null);
             fail("PoolUtils.checkedPool(ObjectPool, Class) must not allow a null type.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        ObjectPool op = (ObjectPool)createProxy(ObjectPool.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        ObjectPool<Object> op = createProxy(ObjectPool.class, calledMethods);
 
-        ObjectPool cop = PoolUtils.checkedPool(op, Object.class);
-        final List expectedMethods = invokeEveryMethod(cop);
+        ObjectPool<Object> cop = PoolUtils.checkedPool(op, Object.class);
+        final List<String> expectedMethods = invokeEveryMethod(cop);
         assertEquals(expectedMethods, calledMethods);
 
-        op = new BaseObjectPool() {
+        op = new BaseObjectPool<Object>() {
             public Object borrowObject() throws Exception {
                 return new Integer(0);
             }
             public void returnObject(Object obj) {}
             public void invalidateObject(Object obj) {}
         };
-        cop = PoolUtils.checkedPool(op, String.class);
+        // cast to ObjectPool to be able to use String.class
+        @SuppressWarnings({ "rawtypes", "unchecked" })
+        final ObjectPool checkedPool = PoolUtils.checkedPool((ObjectPool)op, String.class);
+        @SuppressWarnings("unchecked")
+        final ObjectPool<Object> cop2 = checkedPool;
 
         try {
-            cop.borrowObject();
+            cop2.borrowObject();
             fail("borrowObject should have failed as Integer !instanceof String.");
         } catch (ClassCastException cce) {
             // expected
         }
         try {
-            cop.returnObject(new Integer(1));
+            cop2.returnObject(new Integer(1));
             fail("returnObject should have failed as Integer !instanceof String.");
         } catch (ClassCastException cce) {
             // expected
         }
         try {
-            cop.invalidateObject(new Integer(2));
+            cop2.invalidateObject(new Integer(2));
             fail("invalidateObject should have failed as Integer !instanceof String.");
         } catch (ClassCastException cce) {
             // expected
@@ -205,28 +218,29 @@ public class TestPoolUtils extends TestC
 
     public void testCheckedPoolKeyedObjectPool() throws Exception {
         try {
-            PoolUtils.checkedPool((KeyedObjectPool)null, Object.class);
+            PoolUtils.checkedPool((KeyedObjectPool<Object, Object>)null, Object.class);
             fail("PoolUtils.checkedPool(KeyedObjectPool, Class) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
         try {
-            PoolUtils.checkedPool((KeyedObjectPool)createProxy(KeyedObjectPool.class, (List)null), null);
+            PoolUtils.checkedPool((KeyedObjectPool<?, ?>)createProxy(KeyedObjectPool.class, (List<String>)null), null);
             fail("PoolUtils.checkedPool(KeyedObjectPool, Class) must not allow a null type.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        KeyedObjectPool op = (KeyedObjectPool)createProxy(KeyedObjectPool.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        KeyedObjectPool<Object, Object> op = createProxy(KeyedObjectPool.class, calledMethods);
 
-        KeyedObjectPool cop = PoolUtils.checkedPool(op, Object.class);
-        final List expectedMethods = invokeEveryMethod(cop);
+        KeyedObjectPool<Object, Object> cop = PoolUtils.checkedPool(op, Object.class);
+        final List<String> expectedMethods = invokeEveryMethod(cop);
         assertEquals(expectedMethods, calledMethods);
 
 
-        op = new BaseKeyedObjectPool() {
-            public Object borrowObject(Object key) {
+        op = new BaseKeyedObjectPool<Object, Object>() {
+            public Integer borrowObject(Object key) {
                 return new Integer(0);
             }
 
@@ -234,22 +248,25 @@ public class TestPoolUtils extends TestC
 
             public void invalidateObject(Object key, Object obj) {}
         };
-        cop = PoolUtils.checkedPool(op, String.class);
+        @SuppressWarnings("rawtypes")
+        final KeyedObjectPool rawPool = op;
+        @SuppressWarnings("unchecked")
+        KeyedObjectPool<Object, Object> cop2 = PoolUtils.checkedPool(rawPool, String.class);
 
         try {
-            cop.borrowObject(null);
+            cop2.borrowObject(null);
             fail("borrowObject should have failed as Integer !instanceof String.");
         } catch (ClassCastException cce) {
             // expected
         }
         try {
-            cop.returnObject(null, new Integer(1));
+            cop2.returnObject(null, new Integer(1));
             fail("returnObject should have failed as Integer !instanceof String.");
         } catch (ClassCastException cce) {
             // expected
         }
         try {
-            cop.invalidateObject(null, new Integer(2));
+            cop2.invalidateObject(null, new Integer(2));
             fail("invalidateObject should have failed as Integer !instanceof String.");
         } catch (ClassCastException cce) {
             // expected
@@ -264,26 +281,27 @@ public class TestPoolUtils extends TestC
             // expected
         }
         try {
-            final ObjectPool pool = (ObjectPool)createProxy(ObjectPool.class, (List)null);
+            final ObjectPool<?> pool = createProxy(ObjectPool.class, (List<String>)null);
             PoolUtils.checkMinIdle(pool, -1, 1);
             fail("PoolUtils.checkMinIdle(ObjectPool,,) must not accept negative min idle values.");
         } catch (IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
+        final List<String> calledMethods = new ArrayList<String>();
 
         // Test that the minIdle check doesn't add too many idle objects
-        final PoolableObjectFactory pof = (PoolableObjectFactory)createProxy(PoolableObjectFactory.class, calledMethods);
-        final ObjectPool op = new GenericObjectPool(pof);
+        @SuppressWarnings("unchecked")
+        final PoolableObjectFactory<Object> pof = createProxy(PoolableObjectFactory.class, calledMethods);
+        final ObjectPool<Object> op = new GenericObjectPool<Object>(pof);
         PoolUtils.checkMinIdle(op, 2, 100);
         Thread.sleep(400);
         assertEquals(2, op.getNumIdle());
         op.close();
         int makeObjectCount = 0;
-        final Iterator iter = calledMethods.iterator();
+        final Iterator<String> iter = calledMethods.iterator();
         while (iter.hasNext()) {
-            final String methodName = (String)iter.next();
+            final String methodName = iter.next();
             if ("makeObject".equals(methodName)) {
                 makeObjectCount++;
             }
@@ -297,14 +315,15 @@ public class TestPoolUtils extends TestC
             afe = null;
             try {
                 calledMethods.clear();
-                final ObjectPool pool = (ObjectPool)createProxy(ObjectPool.class, calledMethods);
+                @SuppressWarnings("unchecked")
+                final ObjectPool<Object> pool = createProxy(ObjectPool.class, calledMethods);
                 final TimerTask task = PoolUtils.checkMinIdle(pool, 1, CHECK_PERIOD); // checks minIdle immediately
 
                 Thread.sleep(CHECK_SLEEP_PERIOD); // will check CHECK_COUNT more times.
                 task.cancel();
                 task.toString();
 
-                final List expectedMethods = new ArrayList();
+                final List<String> expectedMethods = new ArrayList<String>();
                 for (int i=0; i < CHECK_COUNT; i++) {
                     expectedMethods.add("getNumIdle");
                     expectedMethods.add("addObject");
@@ -328,35 +347,38 @@ public class TestPoolUtils extends TestC
             // expected
         }
         try {
-            final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class, (List)null);
+            @SuppressWarnings("unchecked")
+            final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>)null);
             PoolUtils.checkMinIdle(pool, (Object)null, 1, 1);
             fail("PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must not accept null keys.");
         } catch (IllegalArgumentException iae) {
             // expected
         }
         try {
-            final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class, (List)null);
+            @SuppressWarnings("unchecked")
+            final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>)null);
             PoolUtils.checkMinIdle(pool, new Object(), -1, 1);
             fail("PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must not accept negative min idle values.");
         } catch (IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
+        final List<String> calledMethods = new ArrayList<String>();
         final Object key = new Object();
 
         // Test that the minIdle check doesn't add too many idle objects
-        final KeyedPoolableObjectFactory kpof = (KeyedPoolableObjectFactory)createProxy(KeyedPoolableObjectFactory.class, calledMethods);
-        final KeyedObjectPool kop = new GenericKeyedObjectPool(kpof);
+        @SuppressWarnings("unchecked")
+        final KeyedPoolableObjectFactory<Object, Object> kpof = createProxy(KeyedPoolableObjectFactory.class, calledMethods);
+        final KeyedObjectPool<Object, Object> kop = new GenericKeyedObjectPool<Object, Object>(kpof);
         PoolUtils.checkMinIdle(kop, key, 2, 100);
         Thread.sleep(400);
         assertEquals(2, kop.getNumIdle(key));
         assertEquals(2, kop.getNumIdle());
         kop.close();
         int makeObjectCount = 0;
-        final Iterator iter = calledMethods.iterator();
+        final Iterator<String> iter = calledMethods.iterator();
         while (iter.hasNext()) {
-            final String methodName = (String)iter.next();
+            final String methodName = iter.next();
             if ("makeObject".equals(methodName)) {
                 makeObjectCount++;
             }
@@ -370,14 +392,15 @@ public class TestPoolUtils extends TestC
             afe = null;
             try {
                 calledMethods.clear();
-                final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class, calledMethods);
+                @SuppressWarnings("unchecked")
+                final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, calledMethods);
                 final TimerTask task = PoolUtils.checkMinIdle(pool, key, 1, CHECK_PERIOD); // checks minIdle immediately
 
                 Thread.sleep(CHECK_SLEEP_PERIOD); // will check CHECK_COUNT more times.
                 task.cancel();
                 task.toString();
 
-                final List expectedMethods = new ArrayList();
+                final List<String> expectedMethods = new ArrayList<String>();
                 for (int i=0; i < CHECK_COUNT; i++) {
                     expectedMethods.add("getNumIdle");
                     expectedMethods.add("addObject");
@@ -395,8 +418,9 @@ public class TestPoolUtils extends TestC
 
     public void testCheckMinIdleKeyedObjectPoolKeys() throws Exception {
         try {
-            final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class, (List)null);
-            PoolUtils.checkMinIdle(pool, null, 1, 1);
+            @SuppressWarnings("unchecked")
+            final KeyedObjectPool<String, Object> pool = createProxy(KeyedObjectPool.class, (List<String>)null);
+            PoolUtils.checkMinIdle(pool, (Collection<String>)null, 1, 1);
             fail("PoolUtils.checkMinIdle(KeyedObjectPool,Collection,int,long) must not accept null keys.");
         } catch (IllegalArgumentException iae) {
             // expected
@@ -408,21 +432,22 @@ public class TestPoolUtils extends TestC
         do {
             afe = null;
             try {
-                final List calledMethods = new ArrayList();
-                final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class, calledMethods);
-                final Collection keys = new ArrayList(2);
+                final List<String> calledMethods = new ArrayList<String>();
+                @SuppressWarnings("unchecked")
+                final KeyedObjectPool<String, ?> pool = createProxy(KeyedObjectPool.class, calledMethods);
+                final Collection<String> keys = new ArrayList<String>(2);
                 keys.add("one");
                 keys.add("two");
-                final Map tasks = PoolUtils.checkMinIdle(pool, keys, 1, CHECK_PERIOD); // checks minIdle immediately
+                final Map<String, TimerTask> tasks = PoolUtils.checkMinIdle(pool, keys, 1, CHECK_PERIOD); // checks minIdle immediately
 
                 Thread.sleep(CHECK_SLEEP_PERIOD); // will check CHECK_COUNT more times.
-                final Iterator iter = tasks.values().iterator();
+                final Iterator<TimerTask> iter = tasks.values().iterator();
                 while (iter.hasNext()) {
-                    final TimerTask task = (TimerTask)iter.next();
+                    final TimerTask task = iter.next();
                     task.cancel();
                 }
 
-                final List expectedMethods = new ArrayList();
+                final List<String> expectedMethods = new ArrayList<String>();
                 for (int i=0; i < CHECK_COUNT * keys.size(); i++) {
                     expectedMethods.add("getNumIdle");
                     expectedMethods.add("addObject");
@@ -445,11 +470,11 @@ public class TestPoolUtils extends TestC
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final ObjectPool pool = (ObjectPool)createProxy(ObjectPool.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        final ObjectPool<?> pool = createProxy(ObjectPool.class, calledMethods);
 
         PoolUtils.prefill(pool, 0);
-        final List expectedMethods = new ArrayList();
+        final List<String> expectedMethods = new ArrayList<String>();
         assertEquals(expectedMethods, calledMethods);
 
         calledMethods.clear();
@@ -468,18 +493,20 @@ public class TestPoolUtils extends TestC
             // expected
         }
         try {
-            final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class, (List)null);
+            @SuppressWarnings("unchecked")
+            final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>)null);
             PoolUtils.prefill(pool, (Object)null, 1);
             fail("PoolUtils.prefill(KeyedObjectPool,Object,int) must not accept null key.");
         } catch (IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, calledMethods);
 
         PoolUtils.prefill(pool, new Object(), 0);
-        final List expectedMethods = new ArrayList();
+        final List<String> expectedMethods = new ArrayList<String>();
         assertEquals(expectedMethods, calledMethods);
 
         calledMethods.clear();
@@ -492,24 +519,26 @@ public class TestPoolUtils extends TestC
 
     public void testPrefillKeyedObjectPoolCollection() throws Exception {
         try {
-            final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class, (List)null);
-            PoolUtils.prefill(pool, null, 1);
+            @SuppressWarnings("unchecked")
+            final KeyedObjectPool<String, Object> pool = createProxy(KeyedObjectPool.class, (List<String>)null);
+            PoolUtils.prefill(pool, (Collection<String>)null, 1);
             fail("PoolUtils.prefill(KeyedObjectPool,Collection,int) must not accept null keys.");
         } catch (IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        final KeyedObjectPool<Number, Object> pool = createProxy(KeyedObjectPool.class, calledMethods);
 
-        final Set keys = new HashSet();
+        final Set<Number> keys = new HashSet<Number>();
         PoolUtils.prefill(pool, keys, 0);
-        final List expectedMethods = new ArrayList();
+        final List<String> expectedMethods = new ArrayList<String>();
         assertEquals(expectedMethods, calledMethods);
 
         calledMethods.clear();
         keys.add(new Integer(1));
-        keys.add("two");
+        keys.add(new Long(2));
         keys.add(new Double(3.1415926));
         PoolUtils.prefill(pool, keys, 3);
         for (int i=0; i < keys.size() * 3; i++) {
@@ -520,17 +549,18 @@ public class TestPoolUtils extends TestC
 
     public void testSynchronizedPoolObjectPool() throws Exception {
         try {
-            PoolUtils.synchronizedPool((ObjectPool)null);
+            PoolUtils.synchronizedPool((ObjectPool<Object>)null);
             fail("PoolUtils.synchronizedPool(ObjectPool) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final ObjectPool op = (ObjectPool)createProxy(ObjectPool.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        final ObjectPool<Object> op = createProxy(ObjectPool.class, calledMethods);
 
-        final ObjectPool sop = PoolUtils.synchronizedPool(op);
-        final List expectedMethods = invokeEveryMethod(sop);
+        final ObjectPool<Object> sop = PoolUtils.synchronizedPool(op);
+        final List<String> expectedMethods = invokeEveryMethod(sop);
         assertEquals(expectedMethods, calledMethods);
 
         // TODO: Anyone feel motivated to construct a test that verifies proper synchronization?
@@ -538,17 +568,18 @@ public class TestPoolUtils extends TestC
 
     public void testSynchronizedPoolKeyedObjectPool() throws Exception {
         try {
-            PoolUtils.synchronizedPool((KeyedObjectPool)null);
+            PoolUtils.synchronizedPool((KeyedObjectPool<Object, Object>)null);
             fail("PoolUtils.synchronizedPool(KeyedObjectPool) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final KeyedObjectPool kop = (KeyedObjectPool)createProxy(KeyedObjectPool.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        final KeyedObjectPool<Object, Object> kop = createProxy(KeyedObjectPool.class, calledMethods);
 
-        final KeyedObjectPool skop = PoolUtils.synchronizedPool(kop);
-        final List expectedMethods = invokeEveryMethod(skop);
+        final KeyedObjectPool<Object, Object> skop = PoolUtils.synchronizedPool(kop);
+        final List<String> expectedMethods = invokeEveryMethod(skop);
         assertEquals(expectedMethods, calledMethods);
 
         // TODO: Anyone feel motivated to construct a test that verifies proper synchronization?
@@ -556,18 +587,19 @@ public class TestPoolUtils extends TestC
 
     public void testSynchronizedPoolableFactoryPoolableObjectFactory() throws Exception {
         try {
-            PoolUtils.synchronizedPoolableFactory((PoolableObjectFactory)null);
+            PoolUtils.synchronizedPoolableFactory((PoolableObjectFactory<Object>)null);
             fail("PoolUtils.synchronizedPoolableFactory(PoolableObjectFactory) must not allow a null factory.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final PoolableObjectFactory pof =
-                (PoolableObjectFactory)createProxy(PoolableObjectFactory.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        final PoolableObjectFactory<Object> pof =
+                createProxy(PoolableObjectFactory.class, calledMethods);
 
-        final PoolableObjectFactory spof = PoolUtils.synchronizedPoolableFactory(pof);
-        final List expectedMethods = invokeEveryMethod(spof);
+        final PoolableObjectFactory<Object> spof = PoolUtils.synchronizedPoolableFactory(pof);
+        final List<String> expectedMethods = invokeEveryMethod(spof);
         assertEquals(expectedMethods, calledMethods);
 
         // TODO: Anyone feel motivated to construct a test that verifies proper synchronization?
@@ -575,18 +607,19 @@ public class TestPoolUtils extends TestC
 
     public void testSynchronizedPoolableFactoryKeyedPoolableObjectFactory() throws Exception {
         try {
-            PoolUtils.synchronizedPoolableFactory((KeyedPoolableObjectFactory)null);
+            PoolUtils.synchronizedPoolableFactory((KeyedPoolableObjectFactory<Object, Object>)null);
             fail("PoolUtils.synchronizedPoolableFactory(KeyedPoolableObjectFactory) must not allow a null factory.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
-        final KeyedPoolableObjectFactory kpof =
-                (KeyedPoolableObjectFactory)createProxy(KeyedPoolableObjectFactory.class, calledMethods);
+        final List<String> calledMethods = new ArrayList<String>();
+        @SuppressWarnings("unchecked")
+        final KeyedPoolableObjectFactory<Object, Object> kpof =
+                createProxy(KeyedPoolableObjectFactory.class, calledMethods);
 
-        final KeyedPoolableObjectFactory skpof = PoolUtils.synchronizedPoolableFactory(kpof);
-        final List expectedMethods = invokeEveryMethod(skpof);
+        final KeyedPoolableObjectFactory<Object, Object> skpof = PoolUtils.synchronizedPoolableFactory(kpof);
+        final List<String> expectedMethods = invokeEveryMethod(skpof);
         assertEquals(expectedMethods, calledMethods);
 
         // TODO: Anyone feel motivated to construct a test that verifies proper synchronization?
@@ -594,27 +627,27 @@ public class TestPoolUtils extends TestC
 
     public void testErodingPoolObjectPool() throws Exception {
         try {
-            PoolUtils.erodingPool((ObjectPool)null);
+            PoolUtils.erodingPool((ObjectPool<Object>)null);
             fail("PoolUtils.erodingPool(ObjectPool) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
         try {
-            PoolUtils.erodingPool((ObjectPool)null, 1f);
+            PoolUtils.erodingPool((ObjectPool<Object>)null, 1f);
             fail("PoolUtils.erodingPool(ObjectPool, float) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
         try {
-            PoolUtils.erodingPool((ObjectPool)null, 0);
+            PoolUtils.erodingPool((ObjectPool<Object>)null, 0);
             fail("PoolUtils.erodingPool(ObjectPool, float) must not allow a non-positive factor.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
+        final List<String> calledMethods = new ArrayList<String>();
         final InvocationHandler handler = new MethodCallLogger(calledMethods) {
             public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                 Object o = super.invoke(proxy, method, args);
@@ -628,9 +661,10 @@ public class TestPoolUtils extends TestC
 
         // If the logic behind PoolUtils.erodingPool changes then this will need to be tweaked.
         float factor = 0.01f; // about ~9 seconds until first discard
-        final ObjectPool pool = PoolUtils.erodingPool((ObjectPool)createProxy(ObjectPool.class, handler), factor);
+        @SuppressWarnings("unchecked")
+        final ObjectPool<Object> pool = PoolUtils.erodingPool((ObjectPool<Object>)createProxy(ObjectPool.class, handler), factor);
 
-        final List expectedMethods = new ArrayList();
+        final List<String> expectedMethods = new ArrayList<String>();
         assertEquals(expectedMethods, calledMethods);
 
         Object o = pool.borrowObject();
@@ -670,41 +704,41 @@ public class TestPoolUtils extends TestC
 
     public void testErodingPoolKeyedObjectPool() throws Exception {
         try {
-            PoolUtils.erodingPool((KeyedObjectPool)null);
+            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)null);
             fail("PoolUtils.erodingPool(KeyedObjectPool) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
         try {
-            PoolUtils.erodingPool((KeyedObjectPool)null, 1f);
+            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)null, 1f);
             fail("PoolUtils.erodingPool(KeyedObjectPool, float) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
         try {
-            PoolUtils.erodingPool((KeyedObjectPool)null, 0);
+            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)null, 0);
             fail("PoolUtils.erodingPool(ObjectPool, float) must not allow a non-positive factor.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
         try {
-            PoolUtils.erodingPool((KeyedObjectPool)null, 1f, true);
+            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)null, 1f, true);
             fail("PoolUtils.erodingPool(KeyedObjectPool, float, boolean) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
         try {
-            PoolUtils.erodingPool((KeyedObjectPool)null, 0, false);
+            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)null, 0, false);
             fail("PoolUtils.erodingPool(ObjectPool, float, boolean) must not allow a non-positive factor.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
+        final List<String> calledMethods = new ArrayList<String>();
         final InvocationHandler handler = new MethodCallLogger(calledMethods) {
             public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                 Object o = super.invoke(proxy, method, args);
@@ -718,9 +752,10 @@ public class TestPoolUtils extends TestC
 
         // If the logic behind PoolUtils.erodingPool changes then this will need to be tweaked.
         float factor = 0.01f; // about ~9 seconds until first discard
-        final KeyedObjectPool pool = PoolUtils.erodingPool((KeyedObjectPool)createProxy(KeyedObjectPool.class, handler), factor);
+        @SuppressWarnings("unchecked")
+        final KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)createProxy(KeyedObjectPool.class, handler), factor);
 
-        final List expectedMethods = new ArrayList();
+        final List<String> expectedMethods = new ArrayList<String>();
         assertEquals(expectedMethods, calledMethods);
 
         final Object key = "key";
@@ -762,27 +797,27 @@ public class TestPoolUtils extends TestC
     
     public void testErodingPerKeyKeyedObjectPool() throws Exception {
         try {
-            PoolUtils.erodingPool((KeyedObjectPool)null, 1, true);
+            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)null, 1, true);
             fail("PoolUtils.erodingPool(KeyedObjectPool) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
         try {
-            PoolUtils.erodingPool((KeyedObjectPool)null, 0, true);
+            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)null, 0, true);
             fail("PoolUtils.erodingPool(ObjectPool, float) must not allow a non-positive factor.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
         try {
-            PoolUtils.erodingPool((KeyedObjectPool)null, 1f, true);
+            PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)null, 1f, true);
             fail("PoolUtils.erodingPool(KeyedObjectPool, float, boolean) must not allow a null pool.");
         } catch(IllegalArgumentException iae) {
             // expected
         }
 
-        final List calledMethods = new ArrayList();
+        final List<String> calledMethods = new ArrayList<String>();
         final InvocationHandler handler = new MethodCallLogger(calledMethods) {
             public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                 Object o = super.invoke(proxy, method, args);
@@ -796,9 +831,10 @@ public class TestPoolUtils extends TestC
 
         // If the logic behind PoolUtils.erodingPool changes then this will need to be tweaked.
         float factor = 0.01f; // about ~9 seconds until first discard
-        final KeyedObjectPool pool = PoolUtils.erodingPool((KeyedObjectPool)createProxy(KeyedObjectPool.class, handler), factor, true);
+        @SuppressWarnings("unchecked")
+        final KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool((KeyedObjectPool<Object, Object>)createProxy(KeyedObjectPool.class, handler), factor, true);
 
-        final List expectedMethods = new ArrayList();
+        final List<String> expectedMethods = new ArrayList<String>();
         assertEquals(expectedMethods, calledMethods);
 
         final Object key = "key";
@@ -838,7 +874,7 @@ public class TestPoolUtils extends TestC
         assertEquals(expectedMethods, calledMethods);
     }
 
-    private static List invokeEveryMethod(ObjectPool op) throws Exception {
+    private static List<String> invokeEveryMethod(ObjectPool<Object> op) throws Exception {
         op.addObject();
         op.borrowObject();
         op.clear();
@@ -847,10 +883,12 @@ public class TestPoolUtils extends TestC
         op.getNumIdle();
         op.invalidateObject(new Object());
         op.returnObject(new Object());
-        op.setFactory((PoolableObjectFactory)createProxy(PoolableObjectFactory.class, (List)null));
+        @SuppressWarnings("unchecked")
+        final PoolableObjectFactory<Object> proxy = createProxy(PoolableObjectFactory.class, (List<String>)null);
+        op.setFactory(proxy);
         op.toString();
 
-        final List expectedMethods = Arrays.asList(new String[] {
+        final List<String> expectedMethods = Arrays.asList(new String[] {
                 "addObject", "borrowObject", "clear", "close",
                 "getNumActive", "getNumIdle", "invalidateObject",
                 "returnObject", "setFactory", "toString"
@@ -858,7 +896,7 @@ public class TestPoolUtils extends TestC
         return expectedMethods;
     }
 
-    private static List invokeEveryMethod(KeyedObjectPool kop) throws Exception {
+    private static List<String> invokeEveryMethod(KeyedObjectPool<Object, Object> kop) throws Exception {
         kop.addObject(null);
         kop.borrowObject(null);
         kop.clear();
@@ -870,10 +908,12 @@ public class TestPoolUtils extends TestC
         kop.getNumIdle(null);
         kop.invalidateObject(null, new Object());
         kop.returnObject(null, new Object());
-        kop.setFactory((KeyedPoolableObjectFactory)createProxy(KeyedPoolableObjectFactory.class, (List)null));
+        @SuppressWarnings("unchecked")
+        final KeyedPoolableObjectFactory<Object, Object> proxy = createProxy(KeyedPoolableObjectFactory.class, (List<String>)null);
+        kop.setFactory(proxy);
         kop.toString();
 
-        final List expectedMethods = Arrays.asList(new String[] {
+        final List<String> expectedMethods = Arrays.asList(new String[] {
                 "addObject", "borrowObject", "clear", "clear", "close",
                 "getNumActive", "getNumActive", "getNumIdle", "getNumIdle", "invalidateObject",
                 "returnObject", "setFactory", "toString"
@@ -881,7 +921,7 @@ public class TestPoolUtils extends TestC
         return expectedMethods;
     }
 
-    private static List invokeEveryMethod(PoolableObjectFactory pof) throws Exception {
+    private static List<String> invokeEveryMethod(PoolableObjectFactory<?> pof) throws Exception {
         pof.activateObject(null);
         pof.destroyObject(null);
         pof.makeObject();
@@ -889,14 +929,14 @@ public class TestPoolUtils extends TestC
         pof.validateObject(null);
         pof.toString();
 
-        final List expectedMethods = Arrays.asList(new String[] {
+        final List<String> expectedMethods = Arrays.asList(new String[] {
                 "activateObject", "destroyObject", "makeObject",
                 "passivateObject", "validateObject", "toString",
         });
         return expectedMethods;
     }
 
-    private static List invokeEveryMethod(KeyedPoolableObjectFactory kpof) throws Exception {
+    private static List<String> invokeEveryMethod(KeyedPoolableObjectFactory<?, ?> kpof) throws Exception {
         kpof.activateObject(null, null);
         kpof.destroyObject(null, null);
         kpof.makeObject(null);
@@ -904,25 +944,31 @@ public class TestPoolUtils extends TestC
         kpof.validateObject(null, null);
         kpof.toString();
 
-        final List expectedMethods = Arrays.asList(new String[] {
+        final List<String> expectedMethods = Arrays.asList(new String[] {
                 "activateObject", "destroyObject", "makeObject",
                 "passivateObject", "validateObject", "toString",
         });
         return expectedMethods;
     }
 
-    private static Object createProxy(final Class clazz, final List logger) {
+    /**
+     * Call sites can use <code>@SuppressWarnings("unchecked")</code>
+     */
+    private static <T> T createProxy(final Class<T> clazz, final List<String> logger) {
         return createProxy(clazz, new MethodCallLogger(logger));
     }
 
-    private static Object createProxy(final Class clazz, final InvocationHandler handler) {
-        return Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, handler);
+    /**
+     * Call sites can use <code>@SuppressWarnings("unchecked")</code>
+     */
+    private static <T> T createProxy(final Class<T> clazz, final InvocationHandler handler) {        
+        return clazz.cast(Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, handler));
     }
 
     private static class MethodCallLogger implements InvocationHandler {
-        private final List calledMethods;
+        private final List<String> calledMethods;
 
-        MethodCallLogger(final List calledMethods) {
+        MethodCallLogger(final List<String> calledMethods) {
             this.calledMethods = calledMethods;
         }
 

Modified: commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/VisitTracker.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/VisitTracker.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/VisitTracker.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/VisitTracker.java Wed Dec 21 13:03:54 2011
@@ -21,13 +21,13 @@ package org.apache.commons.pool;
  * validated, activated, passivated.
  *
  */
-public class VisitTracker {
+public class VisitTracker<K> {
     private int validateCount = 0;
     private int activateCount = 0;
     private int passivateCount = 0;
     private boolean destroyed = false;
     private int id = 0;
-    private Object key = null;
+    private K key = null;
     
     public VisitTracker() {
         super();
@@ -40,7 +40,7 @@ public class VisitTracker {
         reset();
     }
     
-    public VisitTracker(int id, Object key) {
+    public VisitTracker(int id, K key) {
         super();
         this.id = id;
         this.key = key;
@@ -90,7 +90,7 @@ public class VisitTracker {
     public int getId() {
         return id;
     }
-    public Object getKey() {
+    public K getKey() {
         return key;
     }
     public String toString() {

Modified: commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/VisitTrackerFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/VisitTrackerFactory.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/VisitTrackerFactory.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/VisitTrackerFactory.java Wed Dec 21 13:03:54 2011
@@ -22,41 +22,41 @@ package org.apache.commons.pool;
  * test Evictor runs.
  *
  */
-public class VisitTrackerFactory implements PoolableObjectFactory, 
-    KeyedPoolableObjectFactory {
+public class VisitTrackerFactory<K> implements PoolableObjectFactory<VisitTracker<K>>, 
+    KeyedPoolableObjectFactory<K, VisitTracker<K>> {
     private int nextId = 0;
     public VisitTrackerFactory() {
         super();
     }
-    public Object makeObject() {
-        return new VisitTracker(nextId++);
+    public VisitTracker<K> makeObject() {
+        return new VisitTracker<K>(nextId++);
     }
-    public Object makeObject(Object key) {
-        return new VisitTracker(nextId++, key);
+    public VisitTracker<K> makeObject(K key) {
+        return new VisitTracker<K>(nextId++, key);
     }
-    public void destroyObject(Object obj) {
-        ((VisitTracker) obj).destroy();
+    public void destroyObject(VisitTracker<K> obj) {
+        obj.destroy();
     }
-    public void destroyObject(Object key, Object obj) {
-        ((VisitTracker) obj).destroy();
+    public void destroyObject(K key, VisitTracker<K> obj) {
+        obj.destroy();
     }
-    public boolean validateObject(Object obj) {
-        return ((VisitTracker) obj).validate();
+    public boolean validateObject(VisitTracker<K> obj) {
+        return obj.validate();
     }
-    public boolean validateObject(Object key, Object obj) {
-        return ((VisitTracker) obj).validate();
+    public boolean validateObject(K key, VisitTracker<K> obj) {
+        return obj.validate();
     }
-    public void activateObject(Object obj) throws Exception {
-        ((VisitTracker) obj).activate();
+    public void activateObject(VisitTracker<K> obj) throws Exception {
+        obj.activate();
     }
-    public void activateObject(Object key, Object obj) throws Exception {
-        ((VisitTracker) obj).activate();
+    public void activateObject(K key, VisitTracker<K> obj) throws Exception {
+        obj.activate();
     }
-    public void passivateObject(Object obj) throws Exception {
-        ((VisitTracker) obj).passivate();
+    public void passivateObject(VisitTracker<K> obj) throws Exception {
+        obj.passivate();
     }
-    public void passivateObject(Object key, Object obj) throws Exception {
-        ((VisitTracker) obj).passivate();
+    public void passivateObject(K key, VisitTracker<K> obj) throws Exception {
+        obj.passivate();
     }
     public void resetId() {
         nextId = 0;

Modified: commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/Waiter.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/Waiter.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/Waiter.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/Waiter.java Wed Dec 21 13:03:54 2011
@@ -67,8 +67,8 @@ public class Waiter {
      * changing from active to inactive, lastPassivated is updated with the
      * current time.</p>
      * 
-     * <p>{@link WaiterFactory#activateObject(Object)} and
-     * {@link WaiterFactory#passivateObject(Object)} invoke this method on their
+     * <p>{@link WaiterFactory#activateObject(Waiter)} and
+     * {@link WaiterFactory#passivateObject(Waiter)} invoke this method on their
      * actual parameter, passing <code>true</code> and <code>false</code>,
      * respectively.</p>
      * 

Modified: commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/WaiterFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/WaiterFactory.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/WaiterFactory.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/test/org/apache/commons/pool/WaiterFactory.java Wed Dec 21 13:03:54 2011
@@ -32,8 +32,8 @@ import org.apache.commons.pool.KeyedPool
  * (per key) exceeds the configured max.
  *
  */
-public class WaiterFactory implements PoolableObjectFactory,
-KeyedPoolableObjectFactory {
+public class WaiterFactory<K> implements PoolableObjectFactory<Waiter>,
+KeyedPoolableObjectFactory<K, Waiter> {
     
     /** Latency of activateObject */
     private final long activateLatency;
@@ -60,7 +60,7 @@ KeyedPoolableObjectFactory {
     private long activeCount = 0;
     
     /** Count of (makes - destroys) per key since last reset */
-    private Map activeCounts = new HashMap();
+    private Map<K, Integer> activeCounts = new HashMap<K, Integer>();
     
     /** Maximum of (makes - destroys) - if exceeded IllegalStateException */
     private final long maxActive;  // GKOP 1.x calls this maxTotal
@@ -97,22 +97,22 @@ KeyedPoolableObjectFactory {
                 validateLatency, waiterLatency, maxActive, Long.MAX_VALUE, 0);
     }
 
-    public void activateObject(Object obj) throws Exception {
+    public void activateObject(Waiter obj) throws Exception {
         doWait(activateLatency);
-        ((Waiter) obj).setActive(true);
+        obj.setActive(true);
     }
 
-    public void destroyObject(Object obj) throws Exception {
+    public void destroyObject(Waiter obj) throws Exception {
         doWait(destroyLatency);
-        ((Waiter) obj).setValid(false);
-        ((Waiter) obj).setActive(false);
+        obj.setValid(false);
+        obj.setActive(false);
         // Decrement *after* destroy 
         synchronized (this) {
             activeCount--;
         }
     }
 
-    public Object makeObject() throws Exception {
+    public Waiter makeObject() throws Exception {
         // Increment and test *before* make
         synchronized (this) {
             if (activeCount >= maxActive) {
@@ -126,17 +126,17 @@ KeyedPoolableObjectFactory {
         return new Waiter(false, true, waiterLatency);
     }
 
-    public void passivateObject(Object arg0) throws Exception {
-        ((Waiter) arg0).setActive(false);
+    public void passivateObject(Waiter arg0) throws Exception {
+        arg0.setActive(false);
         doWait(passivateLatency);
         if (Math.random() < passivateInvalidationProbability) {
-            ((Waiter) arg0).setValid(false);
+            arg0.setValid(false);
         }
     }
 
-    public boolean validateObject(Object arg0) {
+    public boolean validateObject(Waiter arg0) {
         doWait(validateLatency);
-        return ((Waiter) arg0).isValid();
+        return arg0.isValid();
     }
     
     protected void doWait(long latency) {
@@ -152,9 +152,9 @@ KeyedPoolableObjectFactory {
         if (activeCounts.isEmpty()) {
             return;
         }
-        Iterator it = activeCounts.keySet().iterator();
+        Iterator<K> it = activeCounts.keySet().iterator();
         while (it.hasNext()) {
-            Object key = it.next();
+            K key = it.next();
             activeCounts.put(key, new Integer (0));
         }
     }
@@ -168,21 +168,21 @@ KeyedPoolableObjectFactory {
 
     // KeyedPoolableObjectFactory methods
     
-    public void activateObject(Object key, Object obj) throws Exception {
+    public void activateObject(K key, Waiter obj) throws Exception {
         activateObject(obj);
     }
 
-    public void destroyObject(Object key, Object obj) throws Exception {
+    public void destroyObject(K key, Waiter obj) throws Exception {
         destroyObject(obj);
         synchronized (this) {
-            Integer count = (Integer) activeCounts.get(key);
+            Integer count = activeCounts.get(key);
             activeCounts.put(key, new Integer(count.intValue() - 1));
         }
     }
 
-    public Object makeObject(Object key) throws Exception {
+    public Waiter makeObject(K key) throws Exception {
         synchronized (this) {
-            Integer count = (Integer) activeCounts.get(key);
+            Integer count = activeCounts.get(key);
             if (count == null) {
                 count = new Integer(1);
                 activeCounts.put(key, count);
@@ -200,11 +200,11 @@ KeyedPoolableObjectFactory {
         return makeObject();
     }
 
-    public void passivateObject(Object key, Object obj) throws Exception {
+    public void passivateObject(K key, Waiter obj) throws Exception {
         passivateObject(obj);
     }
 
-    public boolean validateObject(Object key, Object obj) {
+    public boolean validateObject(K key, Waiter obj) {
         return validateObject(obj);
     }
 



Mime
View raw message