commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r815115 - /commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java
Date Tue, 15 Sep 2009 05:57:07 GMT
Author: bayard
Date: Tue Sep 15 05:57:07 2009
New Revision: 815115

URL: http://svn.apache.org/viewvc?rev=815115&view=rev
Log:
Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified;
mostly in r738956.

Also see the following revisions:

    ------------------------------------------------------------------------
    r641231 | skestle | 2008-03-26 02:58:51 -0700 (Wed, 26 Mar 2008) | 1 line
    
    Started incorporating Edwin's patch for COLLECTIONS-253, in preparation for COLLECTIONS-290.
    ------------------------------------------------------------------------

Modified:
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java?rev=815115&r1=815114&r2=815115&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java
Tue Sep 15 05:57:07 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.collections.iterators;
 
+import static org.apache.commons.collections.functors.TruePredicate.truePredicate;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -28,7 +30,6 @@
 
 import org.apache.commons.collections.Predicate;
 import org.apache.commons.collections.functors.NotNullPredicate;
-import org.apache.commons.collections.functors.TruePredicate;
 
 /**
  * Test the filter iterator.
@@ -39,7 +40,7 @@
  * @author Ralph Wagner
  * @author Huw Roberts
  */
-public class TestFilterIterator extends AbstractTestIterator {
+public class TestFilterIterator<E> extends AbstractTestIterator<E> {
 
     /** Creates new TestFilterIterator */
     public TestFilterIterator(String name) {
@@ -47,8 +48,9 @@
     }
 
     private String[] array;
-    private List list;
-    private FilterIterator iterator;
+    private List<E> list;
+    private FilterIterator<E> iterator;
+
     /**
      * Set up instance variables required by this test case.
      */
@@ -74,11 +76,11 @@
     /**
      * Returns an full iterator wrapped in a
      * FilterIterator that blocks all the elements
-     * 
+     *
      * @return "empty" FilterIterator
      */
-    public Iterator makeEmptyIterator() {
-        return makeBlockAllFilter(new ArrayIterator(array));
+    public FilterIterator<E> makeEmptyIterator() {
+        return makeBlockAllFilter(new ArrayIterator<E>(array));
     }
 
     /**
@@ -87,9 +89,9 @@
      * 
      * @return a filtered iterator
      */
-    public Iterator makeFullIterator() {
-        array = new String[] { "a", "b", "c" };
-        list = new ArrayList(Arrays.asList(array));
+    @SuppressWarnings("unchecked")
+    public FilterIterator<E> makeObject() {
+        list = new ArrayList<E>(Arrays.asList((E[]) array));
         return makePassThroughFilter(list.iterator());
     }
 
@@ -100,8 +102,9 @@
     }
 
     public void testRepeatedNext() {
-        for (int i = 0; i < array.length; i++)
+        for (int i = 0; i < array.length; i++) {
             iterator.next();
+        }
         verifyNoMoreElements();
     }
 
@@ -120,15 +123,16 @@
      * Test that when the iterator is changed, the hasNext method returns the
      * correct response for the new iterator.
      */
+    @SuppressWarnings("unchecked")
     public void testSetIterator() {
-        Iterator iter1 = Collections.singleton(new Object()).iterator();
-        Iterator iter2 = Collections.EMPTY_LIST.iterator();
-        
-        FilterIterator filterIterator = new FilterIterator(iter1);
-        filterIterator.setPredicate(TruePredicate.getInstance());
+        Iterator<E> iter1 = Collections.singleton((E) new Object()).iterator();
+        Iterator<E> iter2 = Collections.<E>emptyList().iterator();
+
+        FilterIterator<E> filterIterator = new FilterIterator<E>(iter1);
+        filterIterator.setPredicate(truePredicate());
         // this iterator has elements
         assertEquals(true, filterIterator.hasNext());
-        
+
         // this iterator has no elements
         filterIterator.setIterator(iter2);
         assertEquals(false, filterIterator.hasNext());
@@ -139,13 +143,13 @@
      * correct response for the new predicate.
      */
     public void testSetPredicate() {
-        Iterator iter = Collections.singleton(null).iterator();
+        Iterator<E> iter = Collections.singleton((E) null).iterator();
 
-        FilterIterator filterIterator = new FilterIterator(iter);
-        filterIterator.setPredicate(TruePredicate.getInstance());
+        FilterIterator<E> filterIterator = new FilterIterator<E>(iter);
+        filterIterator.setPredicate(truePredicate());
         // this predicate matches
         assertEquals(true, filterIterator.hasNext());
-        
+
         // this predicate doesn't match
         filterIterator.setPredicate(NotNullPredicate.getInstance());
         assertEquals(false, filterIterator.hasNext());
@@ -163,11 +167,13 @@
     }
 
     private void verifyElementsInPredicate(final String[] elements) {
-        Predicate pred = new Predicate() {
-            public boolean evaluate(Object x) {
-                for (int i = 0; i < elements.length; i++)
-                    if (elements[i].equals(x))
+        Predicate<E> pred = new Predicate<E>() {
+            public boolean evaluate(E x) {
+                for (int i = 0; i < elements.length; i++) {
+                    if (elements[i].equals(x)) {
                         return true;
+                    }
+                }
                 return false;
             }
         };
@@ -191,35 +197,35 @@
     }
 
     private void initIterator() {
-        iterator = (FilterIterator) makeFullIterator();
+        iterator = makeObject();
     }
 
     /**
      * Returns a FilterIterator that does not filter
      * any of its elements
-     * 
+     *
      * @param i      the Iterator to "filter"
      * @return "filtered" iterator
      */
-    protected FilterIterator makePassThroughFilter(Iterator i) {
-        Predicate pred = new Predicate() {
-                public boolean evaluate(Object x) { return true; }
+    protected FilterIterator<E> makePassThroughFilter(Iterator<E> i) {
+        Predicate<E> pred = new Predicate<E>() {
+                public boolean evaluate(E x) { return true; }
         };
-        return new FilterIterator(i,pred);
+        return new FilterIterator<E>(i, pred);
     }
 
     /**
      * Returns a FilterIterator that blocks
      * all of its elements
-     * 
+     *
      * @param i      the Iterator to "filter"
      * @return "filtered" iterator
      */
-    protected FilterIterator makeBlockAllFilter(Iterator i) {
-        Predicate pred = new Predicate() {
-                public boolean evaluate(Object x) { return false; }
+    protected FilterIterator<E> makeBlockAllFilter(Iterator<E> i) {
+        Predicate<E> pred = new Predicate<E>() {
+                public boolean evaluate(E x) { return false; }
         };
-        return new FilterIterator(i,pred);
+        return new FilterIterator<E>(i, pred);
     }
 }
 



Mime
View raw message