commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r814997 [14/18] - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/ java/org/apache/commons/collections/bidimap/ java/org/apache/commons/collections/buffer/ java/org/apac...
Date Tue, 15 Sep 2009 05:30:02 GMT
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java Tue Sep 15 05:29:56 2009
@@ -39,11 +39,11 @@
  *
  * @author Stephen Colebourne
  */
-public abstract class AbstractTestOrderedMapIterator extends AbstractTestMapIterator {
+public abstract class AbstractTestOrderedMapIterator<K, V> extends AbstractTestMapIterator<K, V> {
 
     /**
      * JUnit constructor.
-     * 
+     *
      * @param testName  the test class name
      */
     public AbstractTestOrderedMapIterator(String testName) {
@@ -51,14 +51,10 @@
     }
 
     //-----------------------------------------------------------------------
-    public final OrderedMapIterator makeEmptyOrderedMapIterator() {
-        return (OrderedMapIterator) makeEmptyMapIterator();
-    }
+    public abstract OrderedMapIterator<K, V> makeEmptyIterator();
+
+    public abstract OrderedMapIterator<K, V> makeObject();
 
-    public final OrderedMapIterator makeFullOrderedMapIterator() {
-        return (OrderedMapIterator) makeFullMapIterator();
-    }
-    
     //-----------------------------------------------------------------------
     /**
      * Test that the empty list iterator contract is correct.
@@ -69,9 +65,8 @@
         }
 
         super.testEmptyMapIterator();
-        
-        OrderedMapIterator it = makeEmptyOrderedMapIterator();
-        Map map = getMap();
+
+        OrderedMapIterator<K, V> it = makeEmptyIterator();
         assertEquals(false, it.hasPrevious());
         try {
             it.previous();
@@ -89,29 +84,29 @@
         }
 
         super.testFullMapIterator();
-        
-        OrderedMapIterator it = makeFullOrderedMapIterator();
-        Map map = getMap();
-        
+
+        OrderedMapIterator<K, V> it = makeObject();
+        Map<K, V> map = getMap();
+
         assertEquals(true, it.hasNext());
         assertEquals(false, it.hasPrevious());
-        Set set = new HashSet();
+        Set<K> set = new HashSet<K>();
         while (it.hasNext()) {
             // getKey
-            Object key = it.next();
+            K key = it.next();
             assertSame("it.next() should equals getKey()", key, it.getKey());
             assertTrue("Key must be in map",  map.containsKey(key));
             assertTrue("Key must be unique", set.add(key));
-            
+
             // getValue
-            Object value = it.getValue();
+            V value = it.getValue();
             if (isGetStructuralModify() == false) {
                 assertSame("Value must be mapped to key", map.get(key), value);
             }
             assertTrue("Value must be in map",  map.containsValue(value));
 
             assertEquals(true, it.hasPrevious());
-            
+
             verify();
         }
         while (it.hasPrevious()) {
@@ -120,7 +115,7 @@
             assertSame("it.previous() should equals getKey()", key, it.getKey());
             assertTrue("Key must be in map",  map.containsKey(key));
             assertTrue("Key must be unique", set.remove(key));
-            
+
             // getValue
             Object value = it.getValue();
             if (isGetStructuralModify() == false) {
@@ -129,11 +124,11 @@
             assertTrue("Value must be in map",  map.containsValue(value));
 
             assertEquals(true, it.hasNext());
-            
+
             verify();
         }
     }
-    
+
     //-----------------------------------------------------------------------
     /**
      * Test that the iterator order matches the keySet order.
@@ -143,27 +138,27 @@
             return;
         }
 
-        OrderedMapIterator it = makeFullOrderedMapIterator();
-        Map map = getMap();
-        
-        assertEquals("keySet() not consistent", new ArrayList(map.keySet()), new ArrayList(map.keySet()));
-        
-        Iterator it2 = map.keySet().iterator();
+        OrderedMapIterator<K, V> it = makeObject();
+        Map<K, V> map = getMap();
+
+        assertEquals("keySet() not consistent", new ArrayList<K>(map.keySet()), new ArrayList<K>(map.keySet()));
+
+        Iterator<K> it2 = map.keySet().iterator();
         assertEquals(true, it.hasNext());
         assertEquals(true, it2.hasNext());
-        List list = new ArrayList();
+        List<K> list = new ArrayList<K>();
         while (it.hasNext()) {
-            Object key = it.next();
+            K key = it.next();
             assertEquals(it2.next(), key);
             list.add(key);
         }
         assertEquals(map.size(), list.size());
         while (it.hasPrevious()) {
-            Object key = it.previous();
+            K key = it.previous();
             assertEquals(list.get(list.size() - 1), key);
             list.remove(list.size() - 1);
         }
         assertEquals(0, list.size());
     }
-    
+
 }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayIterator.java Tue Sep 15 05:29:56 2009
@@ -34,7 +34,7 @@
  * @author Morgan Delagrange
  * @author Stephen Colebourne
  */
-public class TestArrayIterator extends AbstractTestIterator {
+public class TestArrayIterator<E> extends AbstractTestIterator<E> {
 
     protected String[] testArray = { "One", "Two", "Three" };
 
@@ -46,24 +46,23 @@
         super(testName);
     }
 
-    public Iterator makeEmptyIterator() {
-        return new ArrayIterator(new Object[0]);
+    public ArrayIterator<E> makeEmptyIterator() {
+        return new ArrayIterator<E>(new Object[0]);
     }
 
-    public Iterator makeFullIterator() {
-        return new ArrayIterator(testArray);
+    public ArrayIterator<E> makeObject() {
+        return new ArrayIterator<E>(testArray);
     }
 
     public boolean supportsRemove() {
         return false;
     }
 
-
     public void testIterator() {
-        Iterator iter = (Iterator) makeFullIterator();
+        Iterator<E> iter = makeObject();
         for (int i = 0; i < testArray.length; i++) {
             Object testValue = testArray[i];
-            Object iterValue = iter.next();
+            E iterValue = iter.next();
 
             assertEquals("Iteration value is correct", testValue, iterValue);
         }
@@ -71,7 +70,7 @@
         assertTrue("Iterator should now be empty", !iter.hasNext());
 
         try {
-            Object testValue = iter.next();
+            iter.next();
         } catch (Exception e) {
             assertTrue(
                 "NoSuchElementException must be thrown",
@@ -81,14 +80,13 @@
 
     public void testNullArray() {
         try {
-            Iterator iter = new ArrayIterator(null);
-
+            new ArrayIterator<Object>(null);
             fail("Constructor should throw a NullPointerException when constructed with a null array");
         } catch (NullPointerException e) {
             // expected
         }
 
-        ArrayIterator iter = new ArrayIterator();
+        ArrayIterator<Object> iter = new ArrayIterator<Object>();
         try {
             iter.setArray(null);
 
@@ -99,7 +97,7 @@
     }
     
     public void testReset() {
-        ArrayIterator it = (ArrayIterator) makeFullIterator();
+        ArrayIterator<E> it = makeObject();
         it.next();
         it.reset();
         assertEquals("One", it.next());

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayIterator2.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayIterator2.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayIterator2.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayIterator2.java Tue Sep 15 05:29:56 2009
@@ -30,7 +30,7 @@
  * @author Morgan Delagrange
  * @author James Strachan
  */
-public class TestArrayIterator2 extends AbstractTestIterator {
+public class TestArrayIterator2<E> extends AbstractTestIterator<E> {
 
     protected int[] testArray = { 2, 4, 6, 8 };
 
@@ -42,41 +42,32 @@
         super(testName);
     }
 
-    public Iterator makeEmptyIterator() {
-        return new ArrayIterator(new int[0]);
+    public ArrayIterator<E> makeEmptyIterator() {
+        return new ArrayIterator<E>(new int[0]);
     }
 
-    public Iterator makeFullIterator() {
-        return new ArrayIterator(testArray);
+    public ArrayIterator<E> makeObject() {
+        return new ArrayIterator<E>(testArray);
     }
 
-    /*
-     * We use these <code>makeArrayIterator</code> factory methods instead of
-     * directly calling the constructor so as to allow subclasses
-     * (e.g. TestArrayListIterator2) to use the existing test code.
-     * 
-     * @return ArrayIterator
-     */
-    public ArrayIterator makeArrayIterator() {
-        return (ArrayIterator) makeEmptyIterator();
+    public ArrayIterator<E> makeArrayIterator(Object array) {
+        return new ArrayIterator<E>(array);
     }
-    public ArrayIterator makeArrayIterator(Object array) {
-        return new ArrayIterator(array);
-    }
-    public ArrayIterator makeArrayIterator(Object array, int index) {
-        return new ArrayIterator(array, index);
+
+    public ArrayIterator<E> makeArrayIterator(Object array, int index) {
+        return new ArrayIterator<E>(array, index);
     }
-    public ArrayIterator makeArrayIterator(Object array, int start, int end) {
-        return new ArrayIterator(array, start, end);
+
+    public ArrayIterator<E> makeArrayIterator(Object array, int start, int end) {
+        return new ArrayIterator<E>(array, start, end);
     }
 
     public boolean supportsRemove() {
         return false;
     }
 
-
     public void testIterator() {
-        Iterator iter = (Iterator) makeFullIterator();
+        Iterator<E> iter = makeObject();
         for (int i = 0; i < testArray.length; i++) {
             Integer testValue = new Integer(testArray[i]);
             Number iterValue = (Number) iter.next();
@@ -87,7 +78,7 @@
         assertTrue("Iterator should now be empty", !iter.hasNext());
 
         try {
-            Object testValue = iter.next();
+            iter.next();
         } catch (Exception e) {
             assertTrue(
                 "NoSuchElementException must be thrown",
@@ -96,9 +87,9 @@
     }
 
     // proves that an ArrayIterator set with the constructor has the same number of elements
-    // as an ArrayIterator set with setArray(Object) 
+    // as an ArrayIterator set with setArray(Object)
     public void testSetArray() {
-        Iterator iter1 = makeArrayIterator(testArray);
+        Iterator<E> iter1 = makeArrayIterator(testArray);
         int count1 = 0;
         while (iter1.hasNext()) {
             ++count1;
@@ -107,7 +98,7 @@
 
         assertEquals("the count should be right using the constructor", count1, testArray.length);
 
-        ArrayIterator iter2 = makeArrayIterator();
+        ArrayIterator<E> iter2 = makeObject();
         iter2.setArray(testArray);
         int count2 = 0;
         while (iter2.hasNext()) {
@@ -119,7 +110,7 @@
     }
 
     public void testIndexedArray() {
-        Iterator iter = makeArrayIterator(testArray, 2);
+        Iterator<E> iter = makeArrayIterator(testArray, 2);
         int count = 0;
         while (iter.hasNext()) {
             ++count;

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayListIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayListIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayListIterator.java Tue Sep 15 05:29:56 2009
@@ -17,7 +17,6 @@
 package org.apache.commons.collections.iterators;
 
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.ListIterator;
 import java.util.NoSuchElementException;
 
@@ -30,7 +29,7 @@
  * @version $Revision$ $Date$
  * @author Neil O'Toole
  */
-public class TestArrayListIterator extends TestArrayIterator {
+public class TestArrayListIterator<E> extends TestArrayIterator<E> {
 
     public TestArrayListIterator(String testName) {
         super(testName);
@@ -40,16 +39,16 @@
         return new TestSuite(TestArrayListIterator.class);
     }
 
-    public Iterator makeEmptyIterator() {
-        return new ArrayListIterator(new Object[0]);
+    public ArrayListIterator<E> makeEmptyIterator() {
+        return new ArrayListIterator<E>(new Object[0]);
     }
 
-    public Iterator makeFullIterator() {
-        return new ArrayListIterator(testArray);
+    public ArrayListIterator<E> makeObject() {
+        return new ArrayListIterator<E>(testArray);
     }
 
-    public ListIterator makeArrayListIterator(Object array) {
-        return new ArrayListIterator(array);
+    public ArrayListIterator<E> makeArrayListIterator(Object array) {
+        return new ArrayListIterator<E>(array);
     }
 
     public boolean supportsRemove() {
@@ -61,7 +60,7 @@
      * <code>previous()</code>.
      */
     public void testListIterator() {
-        ListIterator iter = (ListIterator) makeFullIterator();
+        ListIterator<E> iter = makeObject();
 
         // TestArrayIterator#testIterator() has already tested the iterator forward,
         //  now we need to test it in reverse
@@ -81,7 +80,7 @@
         assertTrue("Iterator should now be empty", !iter.hasPrevious());
 
         try {
-            Object testValue = iter.previous();
+            iter.previous();
         } catch (Exception e) {
             assertTrue(
                 "NoSuchElementException must be thrown",
@@ -93,17 +92,18 @@
     /**
      * Tests the {@link java.util.ListIterator#set} operation.
      */
+    @SuppressWarnings("unchecked")
     public void testListIteratorSet() {
         String[] testData = new String[] { "a", "b", "c" };
 
         String[] result = new String[] { "0", "1", "2" };
 
-        ListIterator iter = (ListIterator) makeArrayListIterator(testData);
+        ListIterator<E> iter = makeArrayListIterator(testData);
         int x = 0;
 
         while (iter.hasNext()) {
             iter.next();
-            iter.set(Integer.toString(x));
+            iter.set((E) Integer.toString(x));
             x++;
         }
 
@@ -113,7 +113,7 @@
         iter = makeArrayListIterator(testArray);
 
         try {
-            iter.set("should fail");
+            iter.set((E) "should fail");
             fail("ListIterator#set should fail if next() or previous() have not yet been called.");
         } catch (IllegalStateException e) {
             // expected

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayListIterator2.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayListIterator2.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayListIterator2.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestArrayListIterator2.java Tue Sep 15 05:29:56 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.collections.iterators;
 
-import java.util.Iterator;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -27,7 +25,7 @@
  * @version $Revision$ $Date$
  * @author Neil O'Toole
  */
-public class TestArrayListIterator2 extends TestArrayIterator2 {
+public class TestArrayListIterator2<E> extends TestArrayIterator2<E> {
 
     public TestArrayListIterator2(String testName) {
         super(testName);
@@ -37,28 +35,24 @@
         return new TestSuite(TestArrayListIterator2.class);
     }
 
-    public Iterator makeEmptyIterator() {
-        return new ArrayListIterator(new int[0]);
-    }
-
-    public Iterator makeFullIterator() {
-        return new ArrayListIterator(testArray);
+    public ArrayListIterator<E> makeEmptyIterator() {
+        return new ArrayListIterator<E>(new int[0]);
     }
 
-    public ArrayIterator makeArrayIterator() {
-        return (ArrayIterator) makeEmptyIterator();
+    public ArrayListIterator<E> makeObject() {
+        return new ArrayListIterator<E>(testArray);
     }
 
-    public ArrayIterator makeArrayIterator(Object array) {
-        return new ArrayListIterator(array);
+    public ArrayListIterator<E> makeArrayListIterator(Object array) {
+        return new ArrayListIterator<E>(array);
     }
 
-    public ArrayIterator makeArrayIterator(Object array, int index) {
-        return new ArrayListIterator(array, index);
+    public ArrayListIterator<E> makeArrayListIterator(Object array, int index) {
+        return new ArrayListIterator<E>(array, index);
     }
 
-    public ArrayIterator makeArrayIterator(Object array, int start, int end) {
-        return new ArrayListIterator(array, start, end);
+    public ArrayListIterator<E> makeArrayListIterator(Object array, int start, int end) {
+        return new ArrayListIterator<E>(array, start, end);
     }
 
 }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestCollatingIterator.java Tue Sep 15 05:29:56 2009
@@ -18,7 +18,6 @@
 
 import java.util.ArrayList;
 import java.util.Comparator;
-import java.util.Iterator;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -31,56 +30,56 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public class TestCollatingIterator extends AbstractTestIterator {
+public class TestCollatingIterator extends AbstractTestIterator<Integer> {
 
     //------------------------------------------------------------ Conventional
-    
+
     public TestCollatingIterator(String testName) {
         super(testName);
     }
-    
+
     public static Test suite() {
         return new TestSuite(TestCollatingIterator.class);
     }
 
     //--------------------------------------------------------------- Lifecycle
 
-    private Comparator comparator = null;
-    private ArrayList evens = null; 
-    private ArrayList odds = null; 
-    private ArrayList fib = null; 
+    private Comparator<Integer> comparator = null;
+    private ArrayList<Integer> evens = null;
+    private ArrayList<Integer> odds = null;
+    private ArrayList<Integer> fib = null;
 
     public void setUp() throws Exception {
         super.setUp();
-        comparator = new ComparableComparator();
-        evens = new ArrayList();
-        odds = new ArrayList();
-        for(int i=0;i<20;i++) {
-            if(0 == i%2) {
-                evens.add(new Integer(i));
+        comparator = new ComparableComparator<Integer>();
+        evens = new ArrayList<Integer>();
+        odds = new ArrayList<Integer>();
+        for (int i = 0; i < 20; i++) {
+            if (0 == i % 2) {
+                evens.add(i);
             } else {
-                odds.add(new Integer(i));
+                odds.add(i);
             }
         }
-        fib = new ArrayList();
-        fib.add(new Integer(1));
-        fib.add(new Integer(1));
-        fib.add(new Integer(2));
-        fib.add(new Integer(3));
-        fib.add(new Integer(5));
-        fib.add(new Integer(8));
-        fib.add(new Integer(13));
-        fib.add(new Integer(21));
-    }       
+        fib = new ArrayList<Integer>();
+        fib.add(1);
+        fib.add(1);
+        fib.add(2);
+        fib.add(3);
+        fib.add(5);
+        fib.add(8);
+        fib.add(13);
+        fib.add(21);
+    }
 
     //---------------------------------------------------- TestIterator Methods
-    
-    public Iterator makeEmptyIterator() {
-        return new CollatingIterator(comparator);
+
+    public CollatingIterator<Integer> makeEmptyIterator() {
+        return new CollatingIterator<Integer>(comparator);
     }
 
-    public Iterator makeFullIterator() {
-        CollatingIterator iter = new CollatingIterator(comparator);
+    public CollatingIterator<Integer> makeObject() {
+        CollatingIterator<Integer> iter = new CollatingIterator<Integer>(comparator);
         iter.addIterator(evens.iterator());
         iter.addIterator(odds.iterator());
         iter.addIterator(fib.iterator());
@@ -90,38 +89,38 @@
     //------------------------------------------------------------------- Tests
 
     public void testGetSetComparator() {
-        CollatingIterator iter = new CollatingIterator();
+        CollatingIterator<Integer> iter = new CollatingIterator<Integer>();
         assertNull(iter.getComparator());
         iter.setComparator(comparator);
-        assertSame(comparator,iter.getComparator());
+        assertSame(comparator, iter.getComparator());
         iter.setComparator(null);
         assertNull(iter.getComparator());
     }
 
     public void testIterateEven() {
-        CollatingIterator iter = new CollatingIterator(comparator);
+        CollatingIterator<Integer> iter = new CollatingIterator<Integer>(comparator);
         iter.addIterator(evens.iterator());
-        for(int i=0;i<evens.size();i++) {
+        for (int i = 0; i < evens.size(); i++) {
             assertTrue(iter.hasNext());
-            assertEquals(evens.get(i),iter.next());
+            assertEquals(evens.get(i), iter.next());
             assertEquals(0,iter.getIteratorIndex());
         }
         assertTrue(!iter.hasNext());
     }
 
     public void testIterateEvenOdd() {
-        CollatingIterator iter = new CollatingIterator(comparator,evens.iterator(),odds.iterator());
-        for(int i=0;i<20;i++) {
+        CollatingIterator<Integer> iter = new CollatingIterator<Integer>(comparator, evens.iterator(), odds.iterator());
+        for (int i = 0; i < 20; i++) {
             assertTrue(iter.hasNext());
-            assertEquals(new Integer(i),iter.next());
+            assertEquals(new Integer(i), iter.next());
             assertEquals(i % 2,iter.getIteratorIndex());
         }
         assertTrue(!iter.hasNext());
     }
 
     public void testIterateOddEven() {
-        CollatingIterator iter = new CollatingIterator(comparator,odds.iterator(),evens.iterator());
-        for(int i=0;i<20;i++) {
+        CollatingIterator<Integer> iter = new CollatingIterator<Integer>(comparator, odds.iterator(), evens.iterator());
+        for (int i = 0; i < 20; i++) {
             assertTrue(iter.hasNext());
             assertEquals(new Integer(i),iter.next());
             assertEquals((i % 2) == 0 ? 1 : 0,iter.getIteratorIndex());
@@ -130,27 +129,26 @@
     }
 
     public void testIterateEvenEven() {
-        CollatingIterator iter = new CollatingIterator(comparator);
+        CollatingIterator<Integer> iter = new CollatingIterator<Integer>(comparator);
         iter.addIterator(evens.iterator());
         iter.addIterator(evens.iterator());
-        for(int i=0;i<evens.size();i++) {
+        for (int i = 0; i < evens.size(); i++) {
             assertTrue(iter.hasNext());
-            assertEquals(evens.get(i),iter.next());
+            assertEquals(evens.get(i), iter.next());
             assertEquals(0,iter.getIteratorIndex());
             assertTrue(iter.hasNext());
-            assertEquals(evens.get(i),iter.next());
+            assertEquals(evens.get(i), iter.next());
             assertEquals(1,iter.getIteratorIndex());
         }
         assertTrue(!iter.hasNext());
     }
 
-
     public void testIterateFibEvenOdd() {
-        CollatingIterator iter = new CollatingIterator(comparator);
+        CollatingIterator<Integer> iter = new CollatingIterator<Integer>(comparator);
         iter.addIterator(fib.iterator());
         iter.addIterator(evens.iterator());
         iter.addIterator(odds.iterator());
-        
+
         assertEquals(new Integer(0),iter.next());  // even   0
         assertEquals(1,iter.getIteratorIndex());
         assertEquals(new Integer(1),iter.next());  // fib    1
@@ -212,12 +210,13 @@
     }
 
     public void testRemoveFromSingle() {
-        CollatingIterator iter = new CollatingIterator(comparator);
+        CollatingIterator<Integer> iter = new CollatingIterator<Integer>(comparator);
         iter.addIterator(evens.iterator());
         int expectedSize = evens.size();
-        while(iter.hasNext()) {
-            Integer val = (Integer)(iter.next());
-            if(val.intValue() % 4 == 0) {
+        while (iter.hasNext()) {
+            Object o = iter.next();
+            Integer val = (Integer) o;
+            if (val.intValue() % 4 == 0) {
                 expectedSize--;
                 iter.remove();
             }
@@ -226,19 +225,20 @@
     }
 
     public void testRemoveFromDouble() {
-        CollatingIterator iter = new CollatingIterator(comparator);
+        CollatingIterator<Integer> iter = new CollatingIterator<Integer>(comparator);
         iter.addIterator(evens.iterator());
         iter.addIterator(odds.iterator());
         int expectedSize = evens.size() + odds.size();
-        while(iter.hasNext()) {
-            Integer val = (Integer)(iter.next());
-            if(val.intValue() % 4 == 0 || val.intValue() % 3 == 0 ) {
+        while (iter.hasNext()) {
+            Object o = iter.next();
+            Integer val = (Integer) o;
+            if (val.intValue() % 4 == 0 || val.intValue() % 3 == 0) {
                 expectedSize--;
                 iter.remove();
             }
         }
-        assertEquals(expectedSize,(evens.size() + odds.size()));
-    }   
+        assertEquals(expectedSize, (evens.size() + odds.size()));
+    }
 
 }
 

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java Tue Sep 15 05:29:56 2009
@@ -48,69 +48,69 @@
         junit.textui.TestRunner.main(testCaseName);
     }
 
-    private ArrayList list = null;
-    private ArrayList odds = null;
-    private ArrayList evens = null;
-    private ArrayList threes = null;
-    private ArrayList fours = null;
-    private ArrayList sixes = null;
-    private Predicate truePred = null;
-    private Predicate falsePred = null;
-    private Predicate evenPred = null;
-    private Predicate oddPred = null;
-    private Predicate threePred = null;
-    private Predicate fourPred = null;
+    private ArrayList<Integer> list = null;
+    private ArrayList<Integer> odds = null;
+    private ArrayList<Integer> evens = null;
+    private ArrayList<Integer> threes = null;
+    private ArrayList<Integer> fours = null;
+    private ArrayList<Integer> sixes = null;
+    private Predicate<Integer> truePred = null;
+    private Predicate<Integer> falsePred = null;
+    private Predicate<Integer> evenPred = null;
+    private Predicate<Integer> oddPred = null;
+    private Predicate<Integer> threePred = null;
+    private Predicate<Integer> fourPred = null;
     private Random random = new Random();
 
     public void setUp() {
-        list = new ArrayList();
-        odds = new ArrayList();
-        evens = new ArrayList();
-        threes = new ArrayList();
-        fours = new ArrayList();
-        sixes = new ArrayList();
-        for(int i=0;i<20;i++) {
+        list = new ArrayList<Integer>();
+        odds = new ArrayList<Integer>();
+        evens = new ArrayList<Integer>();
+        threes = new ArrayList<Integer>();
+        fours = new ArrayList<Integer>();
+        sixes = new ArrayList<Integer>();
+        for (int i = 0; i < 20; i++) {
             list.add(new Integer(i));
-            if(i%2 == 0) { evens.add(new Integer(i)); }
-            if(i%2 == 1) { odds.add(new Integer(i)); }
-            if(i%3 == 0) { threes.add(new Integer(i)); }
-            if(i%4 == 0) { fours.add(new Integer(i)); }
-            if(i%6 == 0) { sixes.add(new Integer(i)); }
+            if (i % 2 == 0) { evens.add(new Integer(i)); }
+            if (i % 2 == 1) { odds.add(new Integer(i)); }
+            if (i % 3 == 0) { threes.add(new Integer(i)); }
+            if (i % 4 == 0) { fours.add(new Integer(i)); }
+            if (i % 6 == 0) { sixes.add(new Integer(i)); }
         }
 
-        truePred = new Predicate() {
-            public boolean evaluate(Object x) { 
+        truePred = new Predicate<Integer>() {
+            public boolean evaluate(Integer x) { 
                 return true;
             }
         };
 
-        falsePred = new Predicate() {
-            public boolean evaluate(Object x) { 
+        falsePred = new Predicate<Integer>() {
+            public boolean evaluate(Integer x) { 
                 return true;
             }
         };
 
-        evenPred = new Predicate() {
-            public boolean evaluate(Object x) { 
-                return (((Integer)x).intValue()%2 == 0);
+        evenPred = new Predicate<Integer>() {
+            public boolean evaluate(Integer x) { 
+                return x % 2 == 0;
             }
         };
 
-        oddPred = new Predicate() {
-            public boolean evaluate(Object x) { 
-                return (((Integer)x).intValue()%2 == 1);
+        oddPred = new Predicate<Integer>() {
+            public boolean evaluate(Integer x) { 
+                return x % 2 == 1;
             }
         };
 
-        threePred = new Predicate() {
-            public boolean evaluate(Object x) { 
-                return (((Integer)x).intValue()%3 == 0);
+        threePred = new Predicate<Integer>() {
+            public boolean evaluate(Integer x) { 
+                return x % 3 == 0;
             }
         };
 
-        fourPred = new Predicate() {
-            public boolean evaluate(Object x) { 
-                return (((Integer)x).intValue()%4 == 0);
+        fourPred = new Predicate<Integer>() {
+            public boolean evaluate(Integer x) { 
+                return x % 4 == 0;
             }
         };
 
@@ -138,208 +138,207 @@
 
     public void testManual() {
         // do this one "by hand" as a sanity check
-        FilterListIterator filtered = new FilterListIterator(list.listIterator(),threePred);
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), threePred);
         
-        assertEquals(new Integer(0),filtered.next());
-        assertEquals(new Integer(3),filtered.next());
-        assertEquals(new Integer(6),filtered.next());
-        assertEquals(new Integer(9),filtered.next());
-        assertEquals(new Integer(12),filtered.next());
-        assertEquals(new Integer(15),filtered.next());
-        assertEquals(new Integer(18),filtered.next());
-
-        assertEquals(new Integer(18),filtered.previous());
-        assertEquals(new Integer(15),filtered.previous());
-        assertEquals(new Integer(12),filtered.previous());
-        assertEquals(new Integer(9),filtered.previous());
-        assertEquals(new Integer(6),filtered.previous());
-        assertEquals(new Integer(3),filtered.previous());
-        assertEquals(new Integer(0),filtered.previous());
+        assertEquals(new Integer(0), filtered.next());
+        assertEquals(new Integer(3), filtered.next());
+        assertEquals(new Integer(6), filtered.next());
+        assertEquals(new Integer(9), filtered.next());
+        assertEquals(new Integer(12), filtered.next());
+        assertEquals(new Integer(15), filtered.next());
+        assertEquals(new Integer(18), filtered.next());
+
+        assertEquals(new Integer(18), filtered.previous());
+        assertEquals(new Integer(15), filtered.previous());
+        assertEquals(new Integer(12), filtered.previous());
+        assertEquals(new Integer(9), filtered.previous());
+        assertEquals(new Integer(6), filtered.previous());
+        assertEquals(new Integer(3), filtered.previous());
+        assertEquals(new Integer(0), filtered.previous());
     
         assertTrue(!filtered.hasPrevious());
 
-        assertEquals(new Integer(0),filtered.next());
-        assertEquals(new Integer(3),filtered.next());
-        assertEquals(new Integer(6),filtered.next());
-        assertEquals(new Integer(9),filtered.next());
-        assertEquals(new Integer(12),filtered.next());
-        assertEquals(new Integer(15),filtered.next());
-        assertEquals(new Integer(18),filtered.next());
+        assertEquals(new Integer(0), filtered.next());
+        assertEquals(new Integer(3), filtered.next());
+        assertEquals(new Integer(6), filtered.next());
+        assertEquals(new Integer(9), filtered.next());
+        assertEquals(new Integer(12), filtered.next());
+        assertEquals(new Integer(15), filtered.next());
+        assertEquals(new Integer(18), filtered.next());
 
         assertTrue(!filtered.hasNext());
 
-        assertEquals(new Integer(18),filtered.previous());
-        assertEquals(new Integer(15),filtered.previous());
-        assertEquals(new Integer(12),filtered.previous());
-        assertEquals(new Integer(9),filtered.previous());
-        assertEquals(new Integer(6),filtered.previous());
-        assertEquals(new Integer(3),filtered.previous());
-        assertEquals(new Integer(0),filtered.previous());
-
-        assertEquals(new Integer(0),filtered.next());
-        assertEquals(new Integer(0),filtered.previous());
-        assertEquals(new Integer(0),filtered.next());
-        
-        assertEquals(new Integer(3),filtered.next());
-        assertEquals(new Integer(6),filtered.next());
-        assertEquals(new Integer(6),filtered.previous());
-        assertEquals(new Integer(3),filtered.previous());
-        assertEquals(new Integer(3),filtered.next());
-        assertEquals(new Integer(6),filtered.next());
-
-        assertEquals(new Integer(9),filtered.next());
-        assertEquals(new Integer(12),filtered.next());
-        assertEquals(new Integer(15),filtered.next());
-        assertEquals(new Integer(15),filtered.previous());
-        assertEquals(new Integer(12),filtered.previous());
-        assertEquals(new Integer(9),filtered.previous());
-
+        assertEquals(new Integer(18), filtered.previous());
+        assertEquals(new Integer(15), filtered.previous());
+        assertEquals(new Integer(12), filtered.previous());
+        assertEquals(new Integer(9), filtered.previous());
+        assertEquals(new Integer(6), filtered.previous());
+        assertEquals(new Integer(3), filtered.previous());
+        assertEquals(new Integer(0), filtered.previous());
+
+        assertEquals(new Integer(0), filtered.next());
+        assertEquals(new Integer(0), filtered.previous());
+        assertEquals(new Integer(0), filtered.next());
+
+        assertEquals(new Integer(3), filtered.next());
+        assertEquals(new Integer(6), filtered.next());
+        assertEquals(new Integer(6), filtered.previous());
+        assertEquals(new Integer(3), filtered.previous());
+        assertEquals(new Integer(3), filtered.next());
+        assertEquals(new Integer(6), filtered.next());
+
+        assertEquals(new Integer(9), filtered.next());
+        assertEquals(new Integer(12), filtered.next());
+        assertEquals(new Integer(15), filtered.next());
+        assertEquals(new Integer(15), filtered.previous());
+        assertEquals(new Integer(12), filtered.previous());
+        assertEquals(new Integer(9), filtered.previous());
     }
 
     public void testTruePredicate() {
-        FilterListIterator filtered = new FilterListIterator(list.listIterator(),truePred);
-        walkLists(list,filtered);
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), truePred);
+        walkLists(list, filtered);
     }
     
     public void testFalsePredicate() {
-        FilterListIterator filtered = new FilterListIterator(list.listIterator(),falsePred);
-        walkLists(new ArrayList(),filtered);
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), falsePred);
+        walkLists(new ArrayList<Integer>(), filtered);
     }
 
     public void testEvens() {
-        FilterListIterator filtered = new FilterListIterator(list.listIterator(),evenPred);
-        walkLists(evens,filtered);
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), evenPred);
+        walkLists(evens, filtered);
     }
     
     public void testOdds() {
-        FilterListIterator filtered = new FilterListIterator(list.listIterator(),oddPred);
-        walkLists(odds,filtered);
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), oddPred);
+        walkLists(odds, filtered);
     }
 
     public void testThrees() {
-        FilterListIterator filtered = new FilterListIterator(list.listIterator(),threePred);
-        walkLists(threes,filtered);
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), threePred);
+        walkLists(threes, filtered);
     }
 
     public void testFours() {
-        FilterListIterator filtered = new FilterListIterator(list.listIterator(),fourPred);
-        walkLists(fours,filtered);
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), fourPred);
+        walkLists(fours, filtered);
     }
 
     public void testNestedSixes() {
-        FilterListIterator filtered = new FilterListIterator(
-                                        new FilterListIterator(list.listIterator(),threePred),
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(
+                                        new FilterListIterator<Integer>(list.listIterator(), threePred),
                                         evenPred
                                       );
-        walkLists(sixes,filtered);
+        walkLists(sixes, filtered);
     }
 
     public void testNestedSixes2() {
-        FilterListIterator filtered = new FilterListIterator(
-                                        new FilterListIterator(list.listIterator(),evenPred),
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(
+                                        new FilterListIterator<Integer>(list.listIterator(), evenPred),
                                         threePred
                                       );
-        walkLists(sixes,filtered);
+        walkLists(sixes, filtered);
     }
 
     public void testNestedSixes3() {        
-        FilterListIterator filtered = new FilterListIterator(
-                                        new FilterListIterator(list.listIterator(),threePred),
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(
+                                        new FilterListIterator<Integer>(list.listIterator(), threePred),
                                         evenPred
                                       );
-        walkLists(sixes,new FilterListIterator(filtered,truePred));
+        walkLists(sixes, new FilterListIterator<Integer>(filtered, truePred));
     }
 
     public void testNextChangesPrevious() {
         {
-            FilterListIterator filtered = new FilterListIterator(list.listIterator(),threePred);
-            nextNextPrevious(threes.listIterator(),filtered);
+            FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), threePred);
+            nextNextPrevious(threes.listIterator(), filtered);
         }
     
         {
-            FilterListIterator filtered = new FilterListIterator(list.listIterator(),truePred);
-            nextNextPrevious(list.listIterator(),filtered);
+            FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), truePred);
+            nextNextPrevious(list.listIterator(), filtered);
         }
     }
 
     public void testPreviousChangesNext() {
         {
-            FilterListIterator filtered = new FilterListIterator(list.listIterator(),threePred);
-            ListIterator expected = threes.listIterator();
+            FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), threePred);
+            ListIterator<Integer> expected = threes.listIterator();
             walkForward(expected,filtered);
             previousPreviousNext(expected,filtered);
         }
         {
-            FilterListIterator filtered = new FilterListIterator(list.listIterator(),truePred);
-            ListIterator expected = list.listIterator();
-            walkForward(expected,filtered);
-            previousPreviousNext(expected,filtered);
+            FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), truePred);
+            ListIterator<Integer> expected = list.listIterator();
+            walkForward(expected, filtered);
+            previousPreviousNext(expected, filtered);
         }
     }
 
     public void testFailingHasNextBug() {
-        FilterListIterator filtered = new FilterListIterator(list.listIterator(),fourPred);
-        ListIterator expected = fours.listIterator();
-        while(expected.hasNext()) {
+        FilterListIterator<Integer> filtered = new FilterListIterator<Integer>(list.listIterator(), fourPred);
+        ListIterator<Integer> expected = fours.listIterator();
+        while (expected.hasNext()) {
             expected.next();
             filtered.next();
         }
         assertTrue(filtered.hasPrevious());
         assertTrue(!filtered.hasNext());
-        assertEquals(expected.previous(),filtered.previous());
+        assertEquals(expected.previous(), filtered.previous());
     }
 
     // Utilities
 
-    private void walkForward(ListIterator expected, ListIterator testing) {
-        while(expected.hasNext()) {
-            assertEquals(expected.nextIndex(),testing.nextIndex());
-            assertEquals(expected.previousIndex(),testing.previousIndex());
+    private void walkForward(ListIterator<?> expected, ListIterator<?> testing) {
+        while (expected.hasNext()) {
+            assertEquals(expected.nextIndex(), testing.nextIndex());
+            assertEquals(expected.previousIndex(), testing.previousIndex());
             assertTrue(testing.hasNext());
-            assertEquals(expected.next(),testing.next());
+            assertEquals(expected.next(), testing.next());
         }
     }
 
-    private void walkBackward(ListIterator expected, ListIterator testing) {
-        while(expected.hasPrevious()) {
-            assertEquals(expected.nextIndex(),testing.nextIndex());
-            assertEquals(expected.previousIndex(),testing.previousIndex());
+    private void walkBackward(ListIterator<?> expected, ListIterator<?> testing) {
+        while (expected.hasPrevious()) {
+            assertEquals(expected.nextIndex(), testing.nextIndex());
+            assertEquals(expected.previousIndex(), testing.previousIndex());
             assertTrue(testing.hasPrevious());
-            assertEquals(expected.previous(),testing.previous());
+            assertEquals(expected.previous(), testing.previous());
         }
     }
 
-    private void nextNextPrevious(ListIterator expected, ListIterator testing) {
+    private void nextNextPrevious(ListIterator<?> expected, ListIterator<?> testing) {
         // calls to next() should change the value returned by previous()
         // even after previous() has been set by a call to hasPrevious()
-        assertEquals(expected.next(),testing.next());
-        assertEquals(expected.hasPrevious(),testing.hasPrevious());
+        assertEquals(expected.next(), testing.next());
+        assertEquals(expected.hasPrevious(), testing.hasPrevious());
         Object expecteda = expected.next();
         Object testinga = testing.next();
-        assertEquals(expecteda,testinga);
+        assertEquals(expecteda, testinga);
         Object expectedb = expected.previous();
         Object testingb = testing.previous();
-        assertEquals(expecteda,expectedb);
-        assertEquals(testinga,testingb);
+        assertEquals(expecteda, expectedb);
+        assertEquals(testinga, testingb);
     }
 
-    private void previousPreviousNext(ListIterator expected, ListIterator testing) {
+    private void previousPreviousNext(ListIterator<?> expected, ListIterator<?> testing) {
         // calls to previous() should change the value returned by next()
         // even after next() has been set by a call to hasNext()
-        assertEquals(expected.previous(),testing.previous());
-        assertEquals(expected.hasNext(),testing.hasNext());
+        assertEquals(expected.previous(), testing.previous());
+        assertEquals(expected.hasNext(), testing.hasNext());
         Object expecteda = expected.previous();
         Object testinga = testing.previous();
-        assertEquals(expecteda,testinga);
+        assertEquals(expecteda, testinga);
         Object expectedb = expected.next();
         Object testingb = testing.next();
-        assertEquals(expecteda,testingb);
-        assertEquals(expecteda,expectedb);
-        assertEquals(testinga,testingb);
+        assertEquals(expecteda, testingb);
+        assertEquals(expecteda, expectedb);
+        assertEquals(testinga, testingb);
     }
 
-    private void walkLists(List list, ListIterator testing) {
-        ListIterator expected = list.listIterator();
+    private <E> void walkLists(List<E> list, ListIterator<E> testing) {
+        ListIterator<E> expected = list.listIterator();
 
         // walk all the way forward
         walkForward(expected,testing);
@@ -348,74 +347,73 @@
         walkBackward(expected,testing);
 
         // forward,back,forward
-        while(expected.hasNext()) {
-            assertEquals(expected.nextIndex(),testing.nextIndex());
-            assertEquals(expected.previousIndex(),testing.previousIndex());
+        while (expected.hasNext()) {
+            assertEquals(expected.nextIndex(), testing.nextIndex());
+            assertEquals(expected.previousIndex(), testing.previousIndex());
             assertTrue(testing.hasNext());
-            assertEquals(expected.next(),testing.next());
+            assertEquals(expected.next(), testing.next());
             assertTrue(testing.hasPrevious());
-            assertEquals(expected.previous(),testing.previous());
+            assertEquals(expected.previous(), testing.previous());
             assertTrue(testing.hasNext());
-            assertEquals(expected.next(),testing.next());
+            assertEquals(expected.next(), testing.next());
         }
 
-
         // walk all the way back
-        walkBackward(expected,testing);
+        walkBackward(expected, testing);
 
-        for(int i=0;i<list.size();i++) {
+        for (int i = 0; i < list.size(); i++) {
             // walk forward i
-            for(int j=0;j<i;j++) {
-                assertEquals(expected.nextIndex(),testing.nextIndex());
-                assertEquals(expected.previousIndex(),testing.previousIndex());
+            for (int j = 0; j < i; j++) {
+                assertEquals(expected.nextIndex(), testing.nextIndex());
+                assertEquals(expected.previousIndex(), testing.previousIndex());
                 assertTrue(expected.hasNext()); // if this one fails we've got a logic error in the test
                 assertTrue(testing.hasNext());
-                assertEquals(expected.next(),testing.next());
+                assertEquals(expected.next(), testing.next());
             }
             // walk back i/2
-            for(int j=0;j<i/2;j++) {
-                assertEquals(expected.nextIndex(),testing.nextIndex());
-                assertEquals(expected.previousIndex(),testing.previousIndex());
+            for (int j = 0; j < i / 2; j++) {
+                assertEquals(expected.nextIndex(), testing.nextIndex());
+                assertEquals(expected.previousIndex(), testing.previousIndex());
                 assertTrue(expected.hasPrevious()); // if this one fails we've got a logic error in the test
                 assertTrue(testing.hasPrevious());
-                assertEquals(expected.previous(),testing.previous());
+                assertEquals(expected.previous(), testing.previous());
             }
             // walk forward i/2
-            for(int j=0;j<i/2;j++) {
-                assertEquals(expected.nextIndex(),testing.nextIndex());
-                assertEquals(expected.previousIndex(),testing.previousIndex());
+            for (int j = 0; j < i / 2; j++) {
+                assertEquals(expected.nextIndex(), testing.nextIndex());
+                assertEquals(expected.previousIndex(), testing.previousIndex());
                 assertTrue(expected.hasNext()); // if this one fails we've got a logic error in the test
                 assertTrue(testing.hasNext());
-                assertEquals(expected.next(),testing.next());
+                assertEquals(expected.next(), testing.next());
             }
             // walk back i
-            for(int j=0;j<i;j++) {
-                assertEquals(expected.nextIndex(),testing.nextIndex());
-                assertEquals(expected.previousIndex(),testing.previousIndex());
+            for (int j = 0; j < i; j++) {
+                assertEquals(expected.nextIndex(), testing.nextIndex());
+                assertEquals(expected.previousIndex(), testing.previousIndex());
                 assertTrue(expected.hasPrevious()); // if this one fails we've got a logic error in the test
                 assertTrue(testing.hasPrevious());
-                assertEquals(expected.previous(),testing.previous());
+                assertEquals(expected.previous(), testing.previous());
             }
         }
 
         // random walk
         StringBuffer walkdescr = new StringBuffer(500);
-        for(int i=0;i<500;i++) {
-            if(random.nextBoolean()) {
+        for (int i = 0; i < 500; i++) {
+            if (random.nextBoolean()) {
                 // step forward
                 walkdescr.append("+");
-                if(expected.hasNext()) {
-                    assertEquals(walkdescr.toString(),expected.next(),testing.next());
+                if (expected.hasNext()) {
+                    assertEquals(walkdescr.toString(), expected.next(), testing.next());
                 }
             } else {
                 // step backward
                 walkdescr.append("-");
-                if(expected.hasPrevious()) {
-                    assertEquals(walkdescr.toString(),expected.previous(),testing.previous());
+                if (expected.hasPrevious()) {
+                    assertEquals(walkdescr.toString(), expected.previous(), testing.previous());
                 }
             }
-            assertEquals(walkdescr.toString(),expected.nextIndex(),testing.nextIndex());
-            assertEquals(walkdescr.toString(),expected.previousIndex(),testing.previousIndex());
+            assertEquals(walkdescr.toString(), expected.nextIndex(), testing.nextIndex());
+            assertEquals(walkdescr.toString(), expected.previousIndex(), testing.previousIndex());
         }
 
     }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestIteratorChain.java Tue Sep 15 05:29:56 2009
@@ -36,15 +36,15 @@
  * @author Mauricio S. Moura
  * @author Morgan Delagrange
  */
-public class TestIteratorChain extends AbstractTestIterator {
+public class TestIteratorChain extends AbstractTestIterator<String> {
 
     protected String[] testArray = {
         "One", "Two", "Three", "Four", "Five", "Six"
     };
 
-    protected List list1 = null;
-    protected List list2 = null;
-    protected List list3 = null;
+    protected List<String> list1 = null;
+    protected List<String> list2 = null;
+    protected List<String> list3 = null;
 
     public static Test suite() {
         return new TestSuite(TestIteratorChain.class);
@@ -55,24 +55,24 @@
     }
 
     public void setUp() {
-        list1 = new ArrayList();
+        list1 = new ArrayList<String>();
         list1.add("One");
         list1.add("Two");
         list1.add("Three");
-        list2 = new ArrayList();
+        list2 = new ArrayList<String>();
         list2.add("Four");
-        list3 = new ArrayList();
+        list3 = new ArrayList<String>();
         list3.add("Five");
         list3.add("Six");        
     }
 
-    public Iterator makeEmptyIterator() {
-        ArrayList list = new ArrayList();
-        return new IteratorChain(list.iterator());
+    public IteratorChain<String> makeEmptyIterator() {
+        ArrayList<String> list = new ArrayList<String>();
+        return new IteratorChain<String>(list.iterator());
     }
 
-    public Iterator makeFullIterator() {
-        IteratorChain chain = new IteratorChain();
+    public IteratorChain<String> makeObject() {
+        IteratorChain<String> chain = new IteratorChain<String>();
 
         chain.addIterator(list1.iterator());
         chain.addIterator(list2.iterator());
@@ -81,18 +81,18 @@
     }
 
     public void testIterator() {
-        Iterator iter = (Iterator) makeFullIterator();
-        for ( int i = 0; i < testArray.length; i++ ) {
+        Iterator<String> iter = makeObject();
+        for (int i = 0; i < testArray.length; i++) {
             Object testValue = testArray[i];            
             Object iterValue = iter.next();
 
             assertEquals( "Iteration value is correct", testValue, iterValue );
         }
 
-        assertTrue("Iterator should now be empty", ! iter.hasNext() );
+        assertTrue("Iterator should now be empty", !iter.hasNext());
 
         try {
-            Object testValue = iter.next();
+            iter.next();
         } catch (Exception e) {
             assertTrue("NoSuchElementException must be thrown", 
                        e.getClass().equals((new NoSuchElementException()).getClass()));
@@ -101,38 +101,34 @@
 
     public void testRemoveFromFilteredIterator() {
 
-        final Predicate myPredicate = new Predicate() {
-            public boolean evaluate( Object object ) {
-                Integer i = (Integer) object;
-                if (i.compareTo(new Integer(4)) < 0)
-                    return true;
-                return false;
+        final Predicate<Integer> myPredicate = new Predicate<Integer>() {
+            public boolean evaluate(Integer i) {
+                return i.compareTo(new Integer(4)) < 0;
             }
         };
 
-        List list1 = new ArrayList();
-        List list2 = new ArrayList();
+        List<Integer> list1 = new ArrayList<Integer>();
+        List<Integer> list2 = new ArrayList<Integer>();
 
         list1.add(new Integer(1));
         list1.add(new Integer(2));
         list2.add(new Integer(3));
         list2.add(new Integer(4)); // will be ignored by the predicate
 
-        Iterator it1 = IteratorUtils.filteredIterator(list1.iterator(), myPredicate );
-        Iterator it2 = IteratorUtils.filteredIterator(list2.iterator(), myPredicate );
+        Iterator<Integer> it1 = IteratorUtils.filteredIterator(list1.iterator(), myPredicate);
+        Iterator<Integer> it2 = IteratorUtils.filteredIterator(list2.iterator(), myPredicate);
 
-        Iterator it = IteratorUtils.chainedIterator(it1, it2);
+        Iterator<Integer> it = IteratorUtils.chainedIterator(it1, it2);
         while (it.hasNext()) {
             it.next();
             it.remove();
         }
-        assertEquals( 0, list1.size() );
-        assertEquals( 1, list2.size() );
-
+        assertEquals(0, list1.size());
+        assertEquals(1, list2.size());
     }
     
     public void testRemove() {
-        Iterator iter = (Iterator) makeFullIterator();
+        Iterator<String> iter = makeObject();
 
         try {
             iter.remove();
@@ -141,13 +137,13 @@
 
         }
 
-        for ( int i = 0; i < testArray.length; i++ ) {
-            Object testValue = testArray[i];            
-            Object iterValue = iter.next();
+        for (int i = 0; i < testArray.length; i++) {
+            String testValue = testArray[i];            
+            String iterValue = iter.next();
 
-            assertEquals( "Iteration value is correct", testValue, iterValue );
+            assertEquals("Iteration value is correct", testValue, iterValue);
 
-            if (! iterValue.equals("Four")) {
+            if (!iterValue.equals("Four")) {
                 iter.remove();
             }
         }
@@ -158,12 +154,12 @@
     }
 
     public void testFirstIteratorIsEmptyBug() {
-        List empty = new ArrayList();
-        List notEmpty = new ArrayList();
+        List<String> empty = new ArrayList<String>();
+        List<String> notEmpty = new ArrayList<String>();
         notEmpty.add("A");
         notEmpty.add("B");
         notEmpty.add("C");
-        IteratorChain chain = new IteratorChain();
+        IteratorChain<String> chain = new IteratorChain<String>();
         chain.addIterator(empty.iterator());
         chain.addIterator(notEmpty.iterator());
         assertTrue("should have next",chain.hasNext());
@@ -176,7 +172,7 @@
     }
     
     public void testEmptyChain() {
-        IteratorChain chain = new IteratorChain();
+        IteratorChain<Object> chain = new IteratorChain<Object>();
         assertEquals(false, chain.hasNext());
         try {
             chain.next();

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestLoopingIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestLoopingIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestLoopingIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestLoopingIterator.java Tue Sep 15 05:29:56 2009
@@ -48,7 +48,7 @@
      */
     public void testConstructorEx() throws Exception {
         try {
-            new LoopingIterator(null);
+            new LoopingIterator<Object>(null);
             fail();
         } catch (NullPointerException ex) {
         }
@@ -59,8 +59,8 @@
      * @throws Exception  If something unexpected occurs.
      */
     public void testLooping0() throws Exception {
-        List list = new ArrayList();
-        LoopingIterator loop = new LoopingIterator(list);
+        List<Object> list = new ArrayList<Object>();
+        LoopingIterator<Object> loop = new LoopingIterator<Object>(list);
         assertTrue("hasNext should return false", loop.hasNext() == false);
 
         try {
@@ -75,8 +75,8 @@
      * @throws Exception  If something unexpected occurs.
      */
     public void testLooping1() throws Exception {
-        List list = new ArrayList(Arrays.asList(new String[] { "a" }));
-        LoopingIterator loop = new LoopingIterator(list);
+        List<String> list = Arrays.asList(new String[] { "a" });
+        LoopingIterator<String> loop = new LoopingIterator<String>(list);
 
         assertTrue("1st hasNext should return true", loop.hasNext());
         assertEquals("a", loop.next());
@@ -94,8 +94,8 @@
      * @throws Exception  If something unexpected occurs.
      */
     public void testLooping2() throws Exception {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b" }));
-        LoopingIterator loop = new LoopingIterator(list);
+        List<String> list = Arrays.asList(new String[] { "a", "b" });
+        LoopingIterator<String> loop = new LoopingIterator<String>(list);
 
         assertTrue("1st hasNext should return true", loop.hasNext());
         assertEquals("a", loop.next());
@@ -113,8 +113,8 @@
      * @throws Exception  If something unexpected occurs.
      */
     public void testLooping3() throws Exception {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
-        LoopingIterator loop = new LoopingIterator(list);
+        List<String> list = Arrays.asList(new String[] { "a", "b", "c" });
+        LoopingIterator<String> loop = new LoopingIterator<String>(list);
 
         assertTrue("1st hasNext should return true", loop.hasNext());
         assertEquals("a", loop.next());
@@ -135,8 +135,8 @@
      * @throws Exception  If something unexpected occurs.
      */
     public void testRemoving1() throws Exception {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
-        LoopingIterator loop = new LoopingIterator(list);
+        List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "a", "b", "c" }));
+        LoopingIterator<String> loop = new LoopingIterator<String>(list);
         assertEquals("list should have 3 elements.", 3, list.size());
 
         assertTrue("1st hasNext should return true", loop.hasNext());
@@ -167,8 +167,8 @@
      * @throws Exception  If something unexpected occurs.
      */
     public void testReset() throws Exception {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
-        LoopingIterator loop = new LoopingIterator(list);
+        List<String> list = Arrays.asList(new String[] { "a", "b", "c" });
+        LoopingIterator<String> loop = new LoopingIterator<String>(list);
 
         assertEquals("a", loop.next());
         assertEquals("b", loop.next());
@@ -189,8 +189,8 @@
      * @throws Exception  If something unexpected occurs.
      */
     public void testSize() throws Exception {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
-        LoopingIterator loop = new LoopingIterator(list);
+        List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "a", "b", "c" }));
+        LoopingIterator<String> loop = new LoopingIterator<String>(list);
 
         assertEquals(3, loop.size());
         loop.next();

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestLoopingListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestLoopingListIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestLoopingListIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestLoopingListIterator.java Tue Sep 15 05:29:56 2009
@@ -47,7 +47,7 @@
      */
     public void testConstructorEx() throws Exception {
         try {
-            new LoopingListIterator(null);
+            new LoopingListIterator<Object>(null);
             fail();
         } catch (NullPointerException ex) {
         }
@@ -57,8 +57,8 @@
      * Tests whether an empty looping list iterator works.
      */
     public void testLooping0() throws Exception {
-        List list = new ArrayList();
-        LoopingListIterator loop = new LoopingListIterator(list);
+        List<Object> list = new ArrayList<Object>();
+        LoopingListIterator<Object> loop = new LoopingListIterator<Object>(list);
         assertFalse(loop.hasNext());
         assertFalse(loop.hasPrevious());
         
@@ -80,8 +80,8 @@
      * one element.
      */
     public void testLooping1() throws Exception {
-        List list = new ArrayList(Arrays.asList(new String[] { "a" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <a>
+        List<String> list = Arrays.asList(new String[] { "a" });
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a>
 
         assertTrue(loop.hasNext());
         assertEquals("a", loop.next());     // <a>
@@ -107,8 +107,8 @@
      * elements.
      */
     public void testLooping2() throws Exception {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <a> b
+        List<String> list = Arrays.asList(new String[] { "a", "b" });
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b
 
         assertTrue(loop.hasNext());
         assertEquals("a", loop.next());     // a <b>
@@ -137,8 +137,8 @@
      * the begin/end boundary of the list.
      */
     public void testJoggingNotOverBoundary() {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <a> b
+        List<String> list = Arrays.asList(new String[] { "a", "b" });
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b
     
         // Try jogging back and forth between the elements, but not
         // over the begin/end boundary.
@@ -157,8 +157,8 @@
      * begin/end boundary of the list.
      */
     public void testJoggingOverBoundary() {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <a> b
+        List<String> list = Arrays.asList(new String[] { "a", "b" });
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b
     
         // Try jogging back and forth between the elements, but not
         // over the begin/end boundary.
@@ -175,8 +175,8 @@
      * Tests removing an element from a wrapped ArrayList.
      */
     public void testRemovingElementsAndIteratingForward() {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <a> b c
+        List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "a", "b", "c" }));
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b c
 
         assertTrue(loop.hasNext());
         assertEquals("a", loop.next()); // a <b> c
@@ -205,8 +205,8 @@
      * Tests removing an element from a wrapped ArrayList.
      */
     public void testRemovingElementsAndIteratingBackwards() {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <a> b c
+        List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "a", "b", "c" }));
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b c
 
         assertTrue(loop.hasPrevious());
         assertEquals("c", loop.previous()); // a b <c>
@@ -235,8 +235,8 @@
      * Tests the reset method.
      */
     public void testReset() {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <a> b c
+        List<String> list = Arrays.asList(new String[] { "a", "b", "c" });
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b c
 
         assertEquals("a", loop.next()); // a <b> c
         assertEquals("b", loop.next()); // a b <c>
@@ -262,8 +262,8 @@
      * Tests the add method.
      */
     public void testAdd() {
-        List list = new ArrayList(Arrays.asList(new String[] { "b", "e", "f" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <b> e f
+        List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "b", "e", "f" }));
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <b> e f
 
         loop.add("a");                      // <a> b e f
         assertEquals("b", loop.next());     // a <b> e f
@@ -287,8 +287,8 @@
         assertEquals("f", loop.next());     // <a> b c d e f
         assertEquals("a", loop.next());     // a <b> c d e f
 
-        list = new ArrayList(Arrays.asList(new String[] { "b", "e", "f" }));
-        loop = new LoopingListIterator(list); // <b> e f        
+        list = new ArrayList<String>(Arrays.asList(new String[] { "b", "e", "f" }));
+        loop = new LoopingListIterator<String>(list); // <b> e f        
 
         loop.add("a");                      // a <b> e f
         assertEquals("a", loop.previous()); // a b e <f>
@@ -316,8 +316,8 @@
      * Tests nextIndex and previousIndex.
      */
     public void testNextAndPreviousIndex() {
-        List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <a> b c
+        List<String> list = Arrays.asList(new String[] { "a", "b", "c" });
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b c
 
         assertEquals(0, loop.nextIndex());
         assertEquals(2, loop.previousIndex());
@@ -347,8 +347,8 @@
      * Tests using the set method to change elements.
      */
     public void testSet() {
-        List list = new ArrayList(Arrays.asList(new String[] { "q", "r", "z" }));
-        LoopingListIterator loop = new LoopingListIterator(list); // <q> r z
+        List<String> list = Arrays.asList(new String[] { "q", "r", "z" });
+        LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <q> r z
 
         assertEquals("z", loop.previous()); // q r <z>
         loop.set("c");                      // q r <c>

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayIterator.java Tue Sep 15 05:29:56 2009
@@ -32,7 +32,7 @@
  * @author Morgan Delagrange
  * @author Stephen Colebourne
  */
-public class TestObjectArrayIterator extends AbstractTestIterator {
+public class TestObjectArrayIterator<E> extends AbstractTestIterator<E> {
 
     protected String[] testArray = { "One", "Two", "Three" };
 
@@ -44,28 +44,30 @@
         super(testName);
     }
 
-    public Iterator makeEmptyIterator() {
-        return new ObjectArrayIterator(new Object[0]);
+    @SuppressWarnings("unchecked")
+    public ObjectArrayIterator<E> makeEmptyIterator() {
+        return new ObjectArrayIterator<E>((E[]) new Object[0]);
     }
 
-    public Iterator makeFullIterator() {
-        return new ObjectArrayIterator(testArray);
+    @SuppressWarnings("unchecked")
+    public ObjectArrayIterator<E> makeObject() {
+        return new ObjectArrayIterator<E>((E[]) testArray);
     }
 
-    public ObjectArrayIterator makeArrayIterator() {
-        return new ObjectArrayIterator();
+    public ObjectArrayIterator<E> makeArrayIterator() {
+        return new ObjectArrayIterator<E>();
     }
 
-    public ObjectArrayIterator makeArrayIterator(Object[] array) {
-        return new ObjectArrayIterator(array);
+    public ObjectArrayIterator<E> makeArrayIterator(E[] array) {
+        return new ObjectArrayIterator<E>(array);
     }
 
-    public ObjectArrayIterator makeArrayIterator(Object[] array, int index) {
-        return new ObjectArrayIterator(array, index);
+    public ObjectArrayIterator<E> makeArrayIterator(E[] array, int index) {
+        return new ObjectArrayIterator<E>(array, index);
     }
 
-    public ObjectArrayIterator makeArrayIterator(Object[] array, int start, int end) {
-        return new ObjectArrayIterator(array, start, end);
+    public ObjectArrayIterator<E> makeArrayIterator(E[] array, int start, int end) {
+        return new ObjectArrayIterator<E>(array, start, end);
     }
 
     public boolean supportsRemove() {
@@ -73,10 +75,10 @@
     }
 
     public void testIterator() {
-        Iterator iter = (Iterator) makeFullIterator();
+        Iterator<E> iter = makeObject();
         for (int i = 0; i < testArray.length; i++) {
             Object testValue = testArray[i];
-            Object iterValue = iter.next();
+            E iterValue = iter.next();
 
             assertEquals("Iteration value is correct", testValue, iterValue);
         }
@@ -84,7 +86,7 @@
         assertTrue("Iterator should now be empty", !iter.hasNext());
 
         try {
-            Object testValue = iter.next();
+            iter.next();
         } catch (Exception e) {
             assertTrue(
                 "NoSuchElementException must be thrown",
@@ -94,14 +96,14 @@
 
     public void testNullArray() {
         try {
-            Iterator iter = makeArrayIterator(null);
+            makeArrayIterator(null);
 
             fail("Constructor should throw a NullPointerException when constructed with a null array");
         } catch (NullPointerException e) {
             // expected
         }
 
-        ObjectArrayIterator iter = makeArrayIterator();
+        ObjectArrayIterator<E> iter = makeArrayIterator();
         try {
             iter.setArray(null);
 
@@ -111,18 +113,20 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     public void testDoubleSet() {
-        ObjectArrayIterator it = makeArrayIterator();
-        it.setArray(new String[0]);
+        ObjectArrayIterator<E> it = makeArrayIterator();
+        it.setArray((E[]) new String[0]);
         try {
-            it.setArray(new String[0]);
+            it.setArray((E[]) new String[0]);
             fail();
         } catch (IllegalStateException ex) {
         }
     }
 
+    @SuppressWarnings("unchecked")
     public void testReset() {
-        ObjectArrayIterator it = makeArrayIterator(testArray);
+        ObjectArrayIterator<E> it = makeArrayIterator((E[]) testArray);
         it.next();
         it.reset();
         assertEquals("One", it.next());

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayListIterator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayListIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayListIterator.java Tue Sep 15 05:29:56 2009
@@ -17,7 +17,6 @@
 package org.apache.commons.collections.iterators;
 
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.ListIterator;
 import java.util.NoSuchElementException;
 
@@ -31,7 +30,7 @@
  *
  * @author Neil O'Toole
  */
-public class TestObjectArrayListIterator extends TestObjectArrayIterator {
+public class TestObjectArrayListIterator<E> extends TestObjectArrayIterator<E> {
 
     public TestObjectArrayListIterator(String testName) {
         super(testName);
@@ -41,16 +40,18 @@
         return new TestSuite(TestObjectArrayListIterator.class);
     }
 
-    public Iterator makeEmptyIterator() {
-        return new ObjectArrayListIterator(new Object[0]);
+    @SuppressWarnings("unchecked")
+    public ObjectArrayListIterator<E> makeEmptyIterator() {
+        return new ObjectArrayListIterator<E>((E[]) new Object[0]);
     }
 
-    public Iterator makeFullIterator() {
-        return new ObjectArrayListIterator(testArray);
+    @SuppressWarnings("unchecked")
+    public ObjectArrayListIterator<E> makeObject() {
+        return new ObjectArrayListIterator<E>((E[]) testArray);
     }
 
-    public ListIterator makeArrayListIterator(Object[] array) {
-        return new ObjectArrayListIterator(array);
+    public ObjectArrayListIterator<E> makeArrayListIterator(E[] array) {
+        return new ObjectArrayListIterator<E>(array);
     }
 
     /**
@@ -58,7 +59,7 @@
      * <code>previous()</code>.
      */
     public void testListIterator() {
-        ListIterator iter = (ListIterator) makeFullIterator();
+        ListIterator<E> iter = makeObject();
 
         // TestArrayIterator#testIterator() has already tested the iterator forward,
         //  now we need to test it in reverse
@@ -78,7 +79,7 @@
         assertTrue("Iterator should now be empty", !iter.hasPrevious());
 
         try {
-            Object testValue = iter.previous();
+            iter.previous();
         } catch (Exception e) {
             assertTrue(
                 "NoSuchElementException must be thrown",
@@ -90,27 +91,28 @@
     /**
      * Tests the {@link java.util.ListIterator#set} operation.
      */
+    @SuppressWarnings("unchecked")
     public void testListIteratorSet() {
         String[] testData = new String[] { "a", "b", "c" };
 
         String[] result = new String[] { "0", "1", "2" };
 
-        ListIterator iter = (ListIterator) makeArrayListIterator(testData);
+        ListIterator<E> iter = makeArrayListIterator((E[]) testData);
         int x = 0;
 
         while (iter.hasNext()) {
             iter.next();
-            iter.set(Integer.toString(x));
+            iter.set((E) Integer.toString(x));
             x++;
         }
 
         assertTrue("The two arrays should have the same value, i.e. {0,1,2}", Arrays.equals(testData, result));
 
         // a call to set() before a call to next() or previous() should throw an IllegalStateException
-        iter = makeArrayListIterator(testArray);
+        iter = makeArrayListIterator((E[]) testArray);
 
         try {
-            iter.set("should fail");
+            iter.set((E) "should fail");
             fail("ListIterator#set should fail if next() or previous() have not yet been called.");
         } catch (IllegalStateException e) {
             // expected

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayListIterator2.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayListIterator2.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayListIterator2.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestObjectArrayListIterator2.java Tue Sep 15 05:29:56 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.collections.iterators;
 
-import java.util.ListIterator;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -28,10 +26,10 @@
  *
  * @author Stephen Colebourne
  */
-public class TestObjectArrayListIterator2 extends AbstractTestListIterator {
+public class TestObjectArrayListIterator2<E> extends AbstractTestListIterator<E> {
 
     protected String[] testArray = { "One", "Two", "Three" };
-    
+
     public TestObjectArrayListIterator2(String testName) {
         super(testName);
     }
@@ -40,22 +38,24 @@
         return new TestSuite(TestObjectArrayListIterator2.class);
     }
 
-    public ListIterator makeEmptyListIterator() {
-        return new ObjectArrayListIterator(new Object[0]);
+    @SuppressWarnings("unchecked")
+    public ObjectArrayListIterator<E> makeEmptyIterator() {
+        return new ObjectArrayListIterator<E>((E[]) new Object[0]);
     }
 
-    public ListIterator makeFullListIterator() {
-        return new ObjectArrayListIterator(testArray);
+    @SuppressWarnings("unchecked")
+    public ObjectArrayListIterator<E> makeObject() {
+        return new ObjectArrayListIterator<E>((E[]) testArray);
     }
 
-    public ListIterator makeArrayListIterator(Object[] array) {
-        return new ObjectArrayListIterator(array);
+    public ObjectArrayListIterator<E> makeArrayListIterator(E[] array) {
+        return new ObjectArrayListIterator<E>(array);
     }
 
     public boolean supportsAdd() {
         return false;
     }
-    
+
     public boolean supportsRemove() {
         return false;
     }



Mime
View raw message