You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2006/01/06 23:07:15 UTC

svn commit: r366576 - in /jakarta/commons/proper/collections/trunk: RELEASE-NOTES.html project.xml src/java/org/apache/commons/collections/iterators/FilterIterator.java src/test/org/apache/commons/collections/iterators/TestFilterIterator.java

Author: scolebourne
Date: Fri Jan  6 14:07:07 2006
New Revision: 366576

URL: http://svn.apache.org/viewcvs?rev=366576&view=rev
Log:
Fix set iterator and predicate methods
bug 38074, from Huw Roberts

Modified:
    jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
    jakarta/commons/proper/collections/trunk/project.xml
    jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterIterator.java
    jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java

Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html?rev=366576&r1=366575&r2=366576&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html (original)
+++ jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html Fri Jan  6 14:07:07 2006
@@ -104,6 +104,7 @@
 <li>UnboundedFifoBuffer - Fix deserialization to work with subsequant object manipulation [35763]</li>
 <li>BlockingBuffer - Fix internal locking code (internal fix, no effect on users of BlockingBuffer) [37028]</li>
 <li>IteratorChain.remove() - Fix to avoid IllegalStateException when one of the underlying iterators is a FilterIterator [34267]</li>
+<li>FilterIterator - Correctly handle setting of iterator and predicate after object creation [38074]</li>
 <li>ExtendedProperties.convertProperties() - Fix to handle default properties maps correctly [32204]</li>
 <li>Add casts to avoid some JDK1.5 compilation warnings [35474]</li>
 <li>Make serialization version ids private [37106]</li>

Modified: jakarta/commons/proper/collections/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/project.xml?rev=366576&r1=366575&r2=366576&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/project.xml (original)
+++ jakarta/commons/proper/collections/trunk/project.xml Fri Jan  6 14:07:07 2006
@@ -341,6 +341,9 @@
       <name>Daniel Rall</name>
     </contributor>
     <contributor>
+      <name>Huw Roberts</name>
+    </contributor>
+    <contributor>
       <name>Henning P. Schmiedehausen</name>
     </contributor>
     <contributor>

Modified: jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterIterator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterIterator.java?rev=366576&r1=366575&r2=366576&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterIterator.java (original)
+++ jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterIterator.java Fri Jan  6 14:07:07 2006
@@ -148,6 +148,8 @@
      */
     public void setIterator(Iterator iterator) {
         this.iterator = iterator;
+        nextObject = null;
+        nextObjectSet = false;
     }
 
     //-----------------------------------------------------------------------
@@ -167,6 +169,8 @@
      */
     public void setPredicate(Predicate predicate) {
         this.predicate = predicate;
+        nextObject = null;
+        nextObjectSet = false;
     }
 
     //-----------------------------------------------------------------------

Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java?rev=366576&r1=366575&r2=366576&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java (original)
+++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java Fri Jan  6 14:07:07 2006
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2004 The Apache Software Foundation
+ *  Copyright 2001-2004,2006 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
@@ -25,14 +26,17 @@
 import junit.framework.TestSuite;
 
 import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.functors.NotNullPredicate;
+import org.apache.commons.collections.functors.TruePredicate;
 
 /**
  * Test the filter iterator.
  *
  * @version $Revision$ $Date$
  * 
- * @author  Jan Sorensen
+ * @author Jan Sorensen
  * @author Ralph Wagner
+ * @author Huw Roberts
  */
 public class TestFilterIterator extends AbstractTestIterator {
 
@@ -109,6 +113,41 @@
         verifyElementsInPredicate(new String[] { "a", "c" });
         verifyElementsInPredicate(new String[] { "b", "c" });
         verifyElementsInPredicate(new String[] { "a", "b", "c" });
+    }
+
+    /**
+     * Test that when the iterator is changed, the hasNext method returns the
+     * correct response for the new iterator.
+     */
+    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());
+        // this iterator has elements
+        assertEquals(true, filterIterator.hasNext());
+        
+        // this iterator has no elements
+        filterIterator.setIterator(iter2);
+        assertEquals(false, filterIterator.hasNext());
+    }
+
+    /**
+     * Test that when the predicate is changed, the hasNext method returns the
+     * correct response for the new predicate.
+     */
+    public void testSetPredicate() {
+        Iterator iter = Collections.singleton(null).iterator();
+
+        FilterIterator filterIterator = new FilterIterator(iter);
+        filterIterator.setPredicate(TruePredicate.getInstance());
+        // this predicate matches
+        assertEquals(true, filterIterator.hasNext());
+        
+        // this predicate doesn't match
+        filterIterator.setPredicate(NotNullPredicate.getInstance());
+        assertEquals(false, filterIterator.hasNext());
     }
 
     private void verifyNoMoreElements() {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org