fix a bug in FilterListIterator and add a test for it

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130701 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Rodney Waldhoff 2002-05-13 16:10:37 +00:00
parent 6b320e8afe
commit e2af015a2f
2 changed files with 24 additions and 8 deletions

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/FilterListIterator.java,v 1.2 2002/02/26 17:28:55 rwaldhoff Exp $
* $Revision: 1.2 $
* $Date: 2002/02/26 17:28:55 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/FilterListIterator.java,v 1.3 2002/05/13 16:10:37 rwaldhoff Exp $
* $Revision: 1.3 $
* $Date: 2002/05/13 16:10:37 $
*
* ====================================================================
*
@ -71,7 +71,7 @@ import java.util.NoSuchElementException;
* <code>Predicate</code> evaluates to <code>true</code> are
* returned by the iterator.
*
* @version $Revision: 1.2 $ $Date: 2002/02/26 17:28:55 $
* @version $Revision: 1.3 $ $Date: 2002/05/13 16:10:37 $
* @author Rodney Waldhoff
*/
public class FilterListIterator extends ProxyListIterator {
@ -199,6 +199,8 @@ public class FilterListIterator extends ProxyListIterator {
clearPreviousObject();
if(!setNextObject()) {
return false;
} else {
clearNextObject();
}
}
@ -230,6 +232,8 @@ public class FilterListIterator extends ProxyListIterator {
clearNextObject();
if(!setPreviousObject()) {
return false;
} else {
clearPreviousObject();
}
}

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestFilterListIterator.java,v 1.2 2002/02/26 17:28:55 rwaldhoff Exp $
* $Revision: 1.2 $
* $Date: 2002/02/26 17:28:55 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestFilterListIterator.java,v 1.3 2002/05/13 16:10:37 rwaldhoff Exp $
* $Revision: 1.3 $
* $Date: 2002/05/13 16:10:37 $
*
* ====================================================================
*
@ -70,7 +70,7 @@ import java.util.ListIterator;
import java.util.Random;
/**
* @version $Revision: 1.2 $ $Date: 2002/02/26 17:28:55 $
* @version $Revision: 1.3 $ $Date: 2002/05/13 16:10:37 $
* @author Rodney Waldhoff
*/
public class TestFilterListIterator extends TestCase {
@ -316,6 +316,18 @@ public class TestFilterListIterator extends TestCase {
}
}
public void testFailingHasNextBug() {
FilterListIterator filtered = new FilterListIterator(list.listIterator(),fourPred);
ListIterator expected = fours.listIterator();
while(expected.hasNext()) {
expected.next();
filtered.next();
}
assertTrue(filtered.hasPrevious());
assertTrue(!filtered.hasNext());
assertEquals(expected.previous(),filtered.previous());
}
// Utilities
private void walkForward(ListIterator expected, ListIterator testing) {