commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ki...@apache.org
Subject svn commit: r1363514 [2/2] - in /commons/proper/functor/trunk/src: changes/ test/java/org/apache/commons/functor/ test/java/org/apache/commons/functor/core/collection/ test/java/org/apache/commons/functor/core/comparator/ test/java/org/apache/commons/f...
Date Thu, 19 Jul 2012 20:13:51 GMT
Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java?rev=1363514&r1=1363513&r2=1363514&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java
Thu Jul 19 20:13:49 2012
@@ -31,9 +31,9 @@ import org.apache.commons.functor.UnaryP
  * @version $Revision$ $Date$
  */
 @SuppressWarnings("unchecked")
-public class FunctoredMap implements Map {
-    public FunctoredMap(Map map) {
-        this.map = map;
+public class FunctoredMap<K, V> implements Map<K, V> {
+    public FunctoredMap(Map<? super K, ? super V> map) {
+        this.map = (Map<K, V>)map;
     }
 
     @Override
@@ -46,16 +46,16 @@ public class FunctoredMap implements Map
         return map.toString();
     }
 
-    public Collection values() {
+    public Collection<V> values() {
         return map.values();
     }
 
-    public Set keySet() {
+    public Set<K> keySet() {
         return map.keySet();
     }
 
-    public Object get(Object key) {
-        return onget.evaluate(map,key);
+    public V get(Object key) {
+        return onget.evaluate(map, (K)key);
     }
 
     public void clear() {
@@ -70,11 +70,11 @@ public class FunctoredMap implements Map
         return onput.evaluate(map, new Object[] { key, value });
     }
 
-    public void putAll(Map src) {
-        onputall.run(map, src);
+    public void putAll(Map<? extends K, ? extends V> src) {
+        onputall.run(map, (Map<K, V>)src);
     }
 
-    public Set entrySet() {
+    public Set<Map.Entry<K, V>> entrySet() {
         return map.entrySet();
     }
 
@@ -86,8 +86,8 @@ public class FunctoredMap implements Map
         return map.isEmpty();
     }
 
-    public Object remove(Object key) {
-        return onremove.evaluate(map,key);
+    public V remove(Object key) {
+        return onremove.evaluate(map, (K)key);
     }
 
     @Override
@@ -101,80 +101,80 @@ public class FunctoredMap implements Map
 
     // protected
 
-    protected void setOnClear(UnaryProcedure procedure) {
+    protected void setOnClear(UnaryProcedure<Map<K, V>> procedure) {
         onclear = procedure;
     }
 
-    protected void setOnPut(BinaryFunction function) {
+    protected void setOnPut(BinaryFunction<Map<K, V>, Object[], V> function)
{
         onput = function;
     }
 
-    protected void setOnGet(BinaryFunction function) {
+    protected void setOnGet(BinaryFunction<Map<K, V>, K, V> function) {
         onget = function;
     }
 
-    protected void setOnPutAll(BinaryProcedure procedure) {
+    protected void setOnPutAll(BinaryProcedure<Map<K, V>, Map<K, V>> procedure)
{
         onputall = procedure;
     }
 
-    protected void setOnRemove(BinaryFunction function) {
+    protected void setOnRemove(BinaryFunction<Map<K, V>, K, V> function) {
         onremove = function;
     }
 
     // attributes
 
-    protected static final BinaryFunction DEFAULT_ON_PUT = new BinaryFunction() {
-        public Object evaluate(Object a, Object b) {
-            Map map = (Map) a;
-            Object key = Array.get(b,0);
-            Object value = Array.get(b,1);
+    protected BinaryFunction<Map<K, V>, Object[], V> DEFAULT_ON_PUT = new BinaryFunction<Map<K,
V>, Object[], V>() {
+        public V evaluate(Map<K, V> a, Object[] b) {
+            Map<K, V> map = a;
+            K key = (K)Array.get(b,0);
+            V value = (V)Array.get(b,1);
             return map.put(key,value);
         }
     };
 
-    private BinaryFunction onput = DEFAULT_ON_PUT;
+    private BinaryFunction<Map<K, V>, Object[], V> onput = DEFAULT_ON_PUT;
 
-    protected static final BinaryFunction DEFAULT_ON_GET = new BinaryFunction() {
-        public Object evaluate(Object map, Object key) {
-            return ((Map) map).get(key);
+    protected BinaryFunction<Map<K, V>, K, V> DEFAULT_ON_GET = new BinaryFunction<Map<K,
V>, K, V>() {
+        public V evaluate(Map<K, V> map, K key) {
+            return map.get(key);
         }
     };
 
-    private BinaryFunction onget = DEFAULT_ON_GET;
-
-    protected static final BinaryProcedure DEFAULT_ON_PUT_ALL = new BinaryProcedure() {
-        public void run(Object a, Object b) {
-            Map dest = (Map) a;
-            Map src = (Map) b;
+    private BinaryFunction<Map<K, V>, K, V> onget = DEFAULT_ON_GET;
+    
+    protected BinaryProcedure<Map<K, V>, Map<K, V>> DEFAULT_ON_PUT_ALL
= new BinaryProcedure<Map<K, V>, Map<K, V>>() {
+        public void run(Map<K, V> a, Map<K, V> b) {
+            Map<K, V> dest = a;
+            Map<K, V> src = b;
             dest.putAll(src);
         }
     };
 
-    private BinaryProcedure onputall = DEFAULT_ON_PUT_ALL;
+    private BinaryProcedure<Map<K, V>, Map<K, V>> onputall = DEFAULT_ON_PUT_ALL;
 
-    protected static final BinaryFunction DEFAULT_ON_REMOVE = new BinaryFunction() {
-        public Object evaluate(Object a, Object key) {
-            Map map = (Map) a;
+    protected BinaryFunction<Map<K, V>, K, V> DEFAULT_ON_REMOVE = new BinaryFunction<Map<K,
V>, K, V>() {
+        public V evaluate(Map<K, V> a, K key) {
+            Map<K, V> map = a;
             return map.remove(key);
         }
     };
 
-    private BinaryFunction onremove = DEFAULT_ON_REMOVE;
+    private BinaryFunction<Map<K, V>, K, V> onremove = DEFAULT_ON_REMOVE;
 
-    protected static final UnaryProcedure DEFAULT_ON_CLEAR = new UnaryProcedure() {
-        public void run(Object map) {
-            ((Map) map).clear();
+    protected UnaryProcedure<Map<K, V>> DEFAULT_ON_CLEAR = new UnaryProcedure<Map<K,
V>>() {
+        public void run(Map<K, V> map) {
+            map.clear();
         }
     };
 
-    private UnaryProcedure onclear = DEFAULT_ON_CLEAR;
+    private UnaryProcedure<Map<K, V>> onclear = DEFAULT_ON_CLEAR;
 
-    private Map map = null;
+    private Map<K, V> map = null;
 
     // inner classes
 
-    protected static class ContainsKey implements UnaryPredicate {
-        ContainsKey(Map map) {
+    protected static class ContainsKey implements UnaryPredicate<Object> {
+        ContainsKey(Map<?, ?> map) {
             this.map = map;
         }
 
@@ -182,10 +182,10 @@ public class FunctoredMap implements Map
             return map.containsKey(obj);
         }
 
-        private Map map = null;
+        private Map<?, ?> map = null;
     }
 
-    protected static class Throw implements Procedure, UnaryProcedure, BinaryProcedure {
+    protected static class Throw<K, V> implements Procedure, UnaryProcedure<Map<K,
V>>, BinaryProcedure<K, V> {
         Throw(RuntimeException e) {
             this.klass = e.getClass();
         }
@@ -200,14 +200,14 @@ public class FunctoredMap implements Map
             }
         }
 
-        public void run(Object obj) {
+        public void run(Map<K, V> obj) {
             run();
         }
 
-        public void run(Object a, Object b) {
+        public void run(K a, V b) {
             run();
         }
 
-        private Class klass = null;
+        private Class<?> klass = null;
     }
 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/LazyMap.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/LazyMap.java?rev=1363514&r1=1363513&r2=1363514&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/LazyMap.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/LazyMap.java
Thu Jul 19 20:13:49 2012
@@ -24,17 +24,15 @@ import org.apache.commons.functor.UnaryF
 /**
  * @version $Revision$ $Date$
  */
-@SuppressWarnings("unchecked")
-public class LazyMap extends FunctoredMap {
-    public LazyMap(Map map, final UnaryFunction factory) {
+public class LazyMap<K, V> extends FunctoredMap<K, V> {
+    public LazyMap(Map<K, V> map, final UnaryFunction<K, V> factory) {
         super(map);
-        setOnGet(new BinaryFunction() {
-            public Object evaluate(Object m, Object key) {
-                Map map = (Map) m;
+        setOnGet(new BinaryFunction<Map<K,V>, K, V>() {
+            public V evaluate(Map<K, V> map, K key) {
                 if (map.containsKey(key)) {
                     return map.get(key);
                 } else {
-                    Object value = factory.evaluate(key);
+                    V value = factory.evaluate(key);
                     map.put(key,value);
                     return value;
                 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/PredicatedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/PredicatedMap.java?rev=1363514&r1=1363513&r2=1363514&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/PredicatedMap.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/PredicatedMap.java
Thu Jul 19 20:13:49 2012
@@ -29,26 +29,24 @@ import org.apache.commons.functor.core.c
 /**
  * @version $Revision$ $Date$
  */
-@SuppressWarnings("unchecked")
-public class PredicatedMap extends FunctoredMap {
-    public PredicatedMap(Map map, final UnaryPredicate keyPredicate, final UnaryPredicate
valuePredicate) {
+public class PredicatedMap<K, V> extends FunctoredMap<K, V> {
+    public PredicatedMap(Map<K, V> map, final UnaryPredicate<K> keyPredicate,
final UnaryPredicate<V> valuePredicate) {
         super(map);
-        setOnPut(new ConditionalBinaryFunction(
-            new BinaryPredicate() {
-                public boolean test(Object a, Object b) {
-                    return keyPredicate.test(Array.get(b,0)) &&
-                        valuePredicate.test(Array.get(b,1));
+        setOnPut(new ConditionalBinaryFunction<Map<K,V>, Object[], V>(
+            new BinaryPredicate<Map<K, V>, Object[]>() {
+                @SuppressWarnings("unchecked")
+                public boolean test(Map<K, V> a, Object[] b) {
+                    return keyPredicate.test((K)Array.get(b,0)) &&
+                        valuePredicate.test((V)Array.get(b,1));
                 }
             },
             DEFAULT_ON_PUT,
-            BinaryProcedureBinaryFunction.adapt(new Throw(new IllegalArgumentException()))));
+            BinaryProcedureBinaryFunction.<Map<K,V>, Object[], V>adapt(new Throw<Map<K,V>,
Object>(new IllegalArgumentException()))));
 
-        setOnPutAll(new BinaryProcedure() {
-            public void run(Object d, Object s) {
-                Map dest = (Map) d;
-                Map src = (Map) s;
-                for (Iterator iter = src.entrySet().iterator(); iter.hasNext(); ) {
-                    Map.Entry pair = (Map.Entry) iter.next();
+        setOnPutAll(new BinaryProcedure<Map<K, V>, Map<K, V>>() {
+            public void run(Map<K, V> dest, Map<K, V> src) {
+                for (Iterator<Map.Entry<K, V>> iter = src.entrySet().iterator();
iter.hasNext(); ) {
+                    Map.Entry<K, V> pair = iter.next();
                     if (keyPredicate.test(pair.getKey()) &&
                         valuePredicate.test(pair.getValue())) {
                         dest.put(pair.getKey(),pair.getValue());

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestFixedSizeMap.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestFixedSizeMap.java?rev=1363514&r1=1363513&r2=1363514&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestFixedSizeMap.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestFixedSizeMap.java
Thu Jul 19 20:13:49 2012
@@ -27,7 +27,6 @@ import junit.framework.TestSuite;
 /**
  * @version $Revision$ $Date$
  */
-@SuppressWarnings("unchecked")
 public class TestFixedSizeMap extends TestCase {
 
     public TestFixedSizeMap(String testName) {
@@ -38,20 +37,20 @@ public class TestFixedSizeMap extends Te
         return new TestSuite(TestFixedSizeMap.class);
     }
 
-    private Map baseMap = null;
-    private Map fixedMap = null;
+    private Map<Object, Object> baseMap = null;
+    private Map<Object, Object> fixedMap = null;
 
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        baseMap = new HashMap();
+        baseMap = new HashMap<Object, Object>();
         baseMap.put(new Integer(1),"one");
         baseMap.put(new Integer(2),"two");
         baseMap.put(new Integer(3),"three");
         baseMap.put(new Integer(4),"four");
         baseMap.put(new Integer(5),"five");
 
-        fixedMap = new FixedSizeMap(baseMap);
+        fixedMap = new FixedSizeMap<Object, Object>(baseMap);
     }
 
     @Override
@@ -73,7 +72,7 @@ public class TestFixedSizeMap extends Te
     }
 
     public void testCantPutNewPairViaPutAll() {
-        Map map = new HashMap();
+        Map<Object, Object> map = new HashMap<Object, Object>();
         map.put(new Integer(1),"uno");
         map.put("xyzzy","xyzzy");
         map.put(new Integer(2),"dos");
@@ -115,7 +114,7 @@ public class TestFixedSizeMap extends Te
     }
 
     public void testCanAssociateNewValueWithOldKeyViaPutAll() {
-        Map map = new HashMap();
+        Map<Object, Object> map = new HashMap<Object, Object>();
         map.put(new Integer(1),"uno");
         map.put(new Integer(2),"dos");
 

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestLazyMap.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestLazyMap.java?rev=1363514&r1=1363513&r2=1363514&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestLazyMap.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestLazyMap.java
Thu Jul 19 20:13:49 2012
@@ -30,7 +30,6 @@ import org.apache.commons.functor.core.c
 /**
  * @version $Revision$ $Date$
  */
-@SuppressWarnings("unchecked")
 public class TestLazyMap extends TestCase {
 
     public TestLazyMap(String testName) {
@@ -41,22 +40,22 @@ public class TestLazyMap extends TestCas
         return new TestSuite(TestLazyMap.class);
     }
 
-    private Map baseMap = null;
-    private Map lazyMap = null;
-    private Map expectedMap = null;
+    private Map<Object, Integer> baseMap = null;
+    private Map<Object, Integer> lazyMap = null;
+    private Map<Object, Integer> expectedMap = null;
 
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        expectedMap = new HashMap();
+        expectedMap = new HashMap<Object, Integer>();
         expectedMap.put("one",new Integer(3));
         expectedMap.put("two",new Integer(3));
         expectedMap.put("three", new Integer(5));
         expectedMap.put("four", new Integer(4));
         expectedMap.put("five", new Integer(4));
 
-        baseMap = new HashMap();
-        lazyMap = new LazyMap(baseMap,Size.instance());
+        baseMap = new HashMap<Object, Integer>();
+        lazyMap = new LazyMap<Object, Integer>(baseMap,Size.instance());
     }
 
     @Override
@@ -70,7 +69,7 @@ public class TestLazyMap extends TestCas
     // tests
 
     public void test() {
-        for (Iterator iter = expectedMap.keySet().iterator(); iter.hasNext();) {
+        for (Iterator<Object> iter = expectedMap.keySet().iterator(); iter.hasNext();)
{
             Object key = iter.next();
             assertFalse(baseMap.containsKey(key));
             assertFalse(lazyMap.containsKey(key));
@@ -82,7 +81,7 @@ public class TestLazyMap extends TestCas
         assertEquals(expectedMap,lazyMap);
         assertEquals(expectedMap,baseMap);
         baseMap.clear();
-        for (Iterator iter = expectedMap.keySet().iterator(); iter.hasNext();) {
+        for (Iterator<Object> iter = expectedMap.keySet().iterator(); iter.hasNext();)
{
             Object key = iter.next();
             assertFalse(baseMap.containsKey(key));
             assertFalse(lazyMap.containsKey(key));
@@ -98,8 +97,8 @@ public class TestLazyMap extends TestCas
 
     public void testBaseMapOverrides() {
         assertEquals(new Integer(5),lazyMap.get("xyzzy"));
-        baseMap.put("xyzzy","xyzzy");
-        assertEquals("xyzzy",lazyMap.get("xyzzy"));
+        baseMap.put("xyzzy",new Integer(3));
+        assertEquals(Integer.valueOf(3),lazyMap.get("xyzzy"));
     }
 
 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestPredicatedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestPredicatedMap.java?rev=1363514&r1=1363513&r2=1363514&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestPredicatedMap.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/TestPredicatedMap.java
Thu Jul 19 20:13:49 2012
@@ -29,7 +29,6 @@ import org.apache.commons.functor.core.I
 /**
  * @version $Revision$ $Date$
  */
-@SuppressWarnings("unchecked")
 public class TestPredicatedMap extends TestCase {
 
     public TestPredicatedMap(String testName) {
@@ -40,13 +39,13 @@ public class TestPredicatedMap extends T
         return new TestSuite(TestPredicatedMap.class);
     }
 
-    private Map baseMap = null;
-    private Map predicatedMap = null;
+    private Map<Object, Object> baseMap = null;
+    private Map<Object, Object> predicatedMap = null;
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        baseMap = new HashMap();
-        predicatedMap = new PredicatedMap(baseMap,IsInstance.of(String.class),IsInstance.of(Integer.class));
+        baseMap = new HashMap<Object, Object>();
+        predicatedMap = new PredicatedMap<Object, Object>(baseMap,IsInstance.of(String.class),IsInstance.of(Integer.class));
     }
 
     @Override
@@ -80,7 +79,7 @@ public class TestPredicatedMap extends T
     }
 
     public void testOnlyValidPairsAreAddedInPutAll() {
-        HashMap map = new HashMap();
+        HashMap<Object, Object> map = new HashMap<Object, Object>();
         map.put("one", new Integer(17));
         map.put("two", "rejected");
         map.put(new Integer(17), "xyzzy");

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java?rev=1363514&r1=1363513&r2=1363514&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
Thu Jul 19 20:13:49 2012
@@ -36,15 +36,15 @@ import org.junit.Test;
 @SuppressWarnings("unchecked")
 public class TestBaseGenerator {
 
-    private Generator simpleGenerator = null;
+    private Generator<Integer> simpleGenerator = null;
 
     // Lifecycle
     // ------------------------------------------------------------------------
 
     @Before
     public void setUp() throws Exception {
-        simpleGenerator = new BaseGenerator() {
-            public void run(UnaryProcedure proc) {
+        simpleGenerator = new BaseGenerator<Integer>() {
+            public void run(UnaryProcedure<? super Integer> proc) {
                 for (int i=0;i<5;i++) {
                     proc.run(new Integer(i));
                     if (isStopped()) {
@@ -54,10 +54,10 @@ public class TestBaseGenerator {
             }
         };
 
-        list = new ArrayList();
-        evens = new ArrayList();
-        doubled = new ArrayList();
-        listWithDuplicates = new ArrayList();
+        list = new ArrayList<Integer>();
+        evens = new ArrayList<Integer>();
+        doubled = new ArrayList<Integer>();
+        listWithDuplicates = new ArrayList<Integer>();
         sum = 0;
         for (int i=0;i<10;i++) {
             list.add(new Integer(i));
@@ -86,8 +86,8 @@ public class TestBaseGenerator {
     @Test
     public void testSimpleGenerator() {
         final StringBuffer result = new StringBuffer();
-        simpleGenerator.run(new UnaryProcedure() {
-            public void run(Object obj) {
+        simpleGenerator.run(new UnaryProcedure<Integer>() {
+            public void run(Integer obj) {
                 result.append(obj);
             }
         });
@@ -98,9 +98,9 @@ public class TestBaseGenerator {
     @Test
     public void testStop() {
         final StringBuffer result = new StringBuffer();
-        simpleGenerator.run(new UnaryProcedure() {
+        simpleGenerator.run(new UnaryProcedure<Integer>() {
             int i=0;
-            public void run(Object obj) {
+            public void run(Integer obj) {
                 result.append(obj);
                 if (i++ > 1) {
                     simpleGenerator.stop();
@@ -114,20 +114,20 @@ public class TestBaseGenerator {
     @Test
     public void testWrappingGenerator() {
         final StringBuffer result = new StringBuffer();
-        final Generator gen = new BaseGenerator(simpleGenerator) {
-            public void run(final UnaryProcedure proc) {
-                Generator wrapped = getWrappedGenerator();
+        final Generator<Integer> gen = new BaseGenerator<Integer>(simpleGenerator)
{
+            public void run(final UnaryProcedure<? super Integer> proc) {
+                Generator<Integer> wrapped = (Generator<Integer>)getWrappedGenerator();
                 assertSame(simpleGenerator, wrapped);
-                wrapped.run(new UnaryProcedure() {
-                    public void run(Object obj) {
-                        proc.run(new Integer(((Integer) obj).intValue() + 1));
+                wrapped.run(new UnaryProcedure<Integer>() {
+                    public void run(Integer obj) {
+                        proc.run(new Integer(obj.intValue() + 1));
                     }
                 });
             }
         };
 
-        gen.run(new UnaryProcedure() {
-            public void run(Object obj) {
+        gen.run(new UnaryProcedure<Integer>() {
+            public void run(Integer obj) {
                 result.append(obj);
             }
         });
@@ -136,9 +136,9 @@ public class TestBaseGenerator {
 
         // try to stop the wrapped generator
         final StringBuffer result2 = new StringBuffer();
-        gen.run(new UnaryProcedure() {
+        gen.run(new UnaryProcedure<Integer>() {
             int i=0;
-            public void run(Object obj) {
+            public void run(Integer obj) {
                 result2.append(obj);
                 if (i++ > 1) {
                     gen.stop();
@@ -154,30 +154,31 @@ public class TestBaseGenerator {
 
     @Test
     public void testTo() {
-        Collection col = (Collection) simpleGenerator.to(new CollectionTransformer());
+        Collection<Integer> col = (Collection<Integer>)simpleGenerator.to(new
CollectionTransformer<Integer>());
         assertEquals("[0, 1, 2, 3, 4]", col.toString());
 
-        Collection fillThis = new LinkedList();
-        col = (Collection) simpleGenerator.to(new CollectionTransformer(fillThis));
+        Collection<Integer> fillThis = new LinkedList<Integer>();
+        col = (Collection<Integer>) simpleGenerator.to(new CollectionTransformer<Integer>(fillThis));
         assertSame(fillThis, col);
         assertEquals("[0, 1, 2, 3, 4]", col.toString());
 
-        col = simpleGenerator.toCollection();
+        col = (Collection<Integer>)simpleGenerator.toCollection();
         assertEquals("[0, 1, 2, 3, 4]", col.toString());
         assertEquals("[0, 1, 2, 3, 4]", col.toString());
 
-        fillThis = new LinkedList();
-        col = simpleGenerator.to(fillThis);
+        fillThis = new LinkedList<Integer>();
+        col = (Collection<Integer>)simpleGenerator.to(fillThis);
         assertSame(fillThis, col);
         assertEquals("[0, 1, 2, 3, 4]", col.toString());
     }
 
     // Attributes
     // ------------------------------------------------------------------------
-    private List list = null;
-    private List doubled = null;
-    private List evens = null;
-    private List listWithDuplicates = null;
+    private List<Integer> list = null;
+    private List<Integer> doubled = null;
+    private List<Integer> evens = null;
+    private List<Integer> listWithDuplicates = null;
+    @SuppressWarnings("unused")
     private int sum = 0;
 //    private UnaryPredicate equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new
Integer(3));
 //    private UnaryPredicate equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new
Integer(23));
@@ -195,9 +196,9 @@ public class TestBaseGenerator {
     // Classes
     // ------------------------------------------------------------------------
 
-    static class Summer implements UnaryProcedure {
-        public void run(Object that) {
-            sum += ((Number) that).intValue();
+    static class Summer implements UnaryProcedure<Number> {
+        public void run(Number that) {
+            sum += (that).intValue();
         }
         public int sum = 0;
     }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java?rev=1363514&r1=1363513&r2=1363514&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java
Thu Jul 19 20:13:49 2012
@@ -19,9 +19,9 @@ package org.apache.commons.functor.gener
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
@@ -39,19 +39,19 @@ public class TestIteratorToGeneratorAdap
 
     @Override
     public Object makeFunctor() {
-        List list = new ArrayList();
+        List<String> list = new ArrayList<String>();
         list.add("1");
-        return new IteratorToGeneratorAdapter(list.iterator());
+        return new IteratorToGeneratorAdapter<String>(list.iterator());
     }
 
     // Lifecycle
     // ------------------------------------------------------------------------
 
-    private List list = null;
+    private List<String> list = null;
 
     @Before
     public void setUp() throws Exception {
-        list = new ArrayList();
+        list = new ArrayList<String>();
         list.add("1");
         list.add("two");
         list.add("c");
@@ -77,23 +77,23 @@ public class TestIteratorToGeneratorAdap
 
     @Test
     public void testGenerate() {
-        Iterator iter = list.iterator();
-        Generator gen = new IteratorToGeneratorAdapter(iter);
-        List list2 = new ArrayList();
-        list2.addAll(gen.toCollection());
+        Iterator<String> iter = list.iterator();
+        Generator<String> gen = new IteratorToGeneratorAdapter<String>(iter);
+        List<String> list2 = new ArrayList<String>();
+        list2.addAll((Collection<String>)gen.toCollection());
         assertEquals(list,list2);
     }
 
     @Test(expected = NullPointerException.class)
     public void testConstructNull() {
-        new IteratorToGeneratorAdapter(null);
+        new IteratorToGeneratorAdapter<Object>(null);
     }
 
     @Test
     public void testEquals() {
-        Iterator iter = list.iterator();
-        Generator gen = new IteratorToGeneratorAdapter(iter);
+        Iterator<String> iter = list.iterator();
+        Generator<String> gen = new IteratorToGeneratorAdapter<String>(iter);
         assertObjectsAreEqual(gen,gen);
-        assertObjectsAreEqual(gen,new IteratorToGeneratorAdapter(iter));
+        assertObjectsAreEqual(gen,new IteratorToGeneratorAdapter<String>(iter));
     }
 }
\ No newline at end of file

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java?rev=1363514&r1=1363513&r2=1363514&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java
Thu Jul 19 20:13:49 2012
@@ -95,11 +95,12 @@ public class TestEachElement extends Bas
     }
 
     @Test
+    @SuppressWarnings("unchecked")
     public void testWithMap() {
         List<?> col = (List<?>) EachElement.from(map).toCollection();
         int i = 0;
         for (;i<col.size();i++) {
-            Map.Entry entry = (Map.Entry) col.get(i);
+            Map.Entry<String, String> entry = (Map.Entry<String, String>) col.get(i);
             if (entry.getKey().equals("1")) {
                 assertEquals("1-1", entry.getValue());
             } else if (entry.getKey().equals("2")) {



Mime
View raw message