Enable remove() in FilterIterator
from Ralph Wagner git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130970 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
389ea88c76
commit
ae4e066007
|
@ -1,13 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java,v 1.4 2002/12/13 12:03:06 scolebourne Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java,v 1.5 2003/01/30 23:11:58 scolebourne Exp $
|
||||||
* $Revision: 1.4 $
|
|
||||||
* $Date: 2002/12/13 12:03:06 $
|
|
||||||
*
|
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
*
|
*
|
||||||
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
|
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
|
||||||
* reserved.
|
* reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -23,11 +20,11 @@
|
||||||
* distribution.
|
* distribution.
|
||||||
*
|
*
|
||||||
* 3. The end-user documentation included with the redistribution, if
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
* any, must include the following acknowlegement:
|
* any, must include the following acknowledgment:
|
||||||
* "This product includes software developed by the
|
* "This product includes software developed by the
|
||||||
* Apache Software Foundation (http://www.apache.org/)."
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
* Alternately, this acknowlegement may appear in the software itself,
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
* if and wherever such third-party acknowlegements normally appear.
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
*
|
*
|
||||||
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
* Foundation" must not be used to endorse or promote products derived
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
@ -36,7 +33,7 @@
|
||||||
*
|
*
|
||||||
* 5. Products derived from this software may not be called "Apache"
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
* nor may "Apache" appear in their names without prior written
|
* nor may "Apache" appear in their names without prior written
|
||||||
* permission of the Apache Group.
|
* permission of the Apache Software Foundation.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
@ -58,20 +55,25 @@
|
||||||
* <http://www.apache.org/>.
|
* <http://www.apache.org/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// TestFilterIterator.java
|
|
||||||
package org.apache.commons.collections.iterators;
|
package org.apache.commons.collections.iterators;
|
||||||
|
|
||||||
import junit.framework.TestSuite;
|
import java.util.ArrayList;
|
||||||
import junit.framework.Test;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.apache.commons.collections.Predicate;
|
import org.apache.commons.collections.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Test the filter iterator.
|
||||||
*
|
*
|
||||||
* @author Jan Sorensen
|
* @author Jan Sorensen
|
||||||
|
* @author Ralph Wagner
|
||||||
|
* @version $Revision: 1.5 $ $Date: 2003/01/30 23:11:58 $
|
||||||
*/
|
*/
|
||||||
public class TestFilterIterator extends TestIterator {
|
public class TestFilterIterator extends TestIterator {
|
||||||
|
|
||||||
|
@ -81,6 +83,7 @@ public class TestFilterIterator extends TestIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] array;
|
private String[] array;
|
||||||
|
private List list;
|
||||||
private FilterIterator iterator;
|
private FilterIterator iterator;
|
||||||
/**
|
/**
|
||||||
* Set up instance variables required by this test case.
|
* Set up instance variables required by this test case.
|
||||||
|
@ -121,18 +124,15 @@ public class TestFilterIterator extends TestIterator {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Iterator makeFullIterator() {
|
public Iterator makeFullIterator() {
|
||||||
return makePassThroughFilter(new ArrayIterator(array));
|
array = new String[] { "a", "b", "c" };
|
||||||
|
list = new ArrayList(Arrays.asList(array));
|
||||||
|
return makePassThroughFilter(list.iterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object makeObject() {
|
public Object makeObject() {
|
||||||
return makeFullIterator();
|
return makeFullIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsRemove() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testRepeatedHasNext() {
|
public void testRepeatedHasNext() {
|
||||||
for (int i = 0; i <= array.length; i++) {
|
for (int i = 0; i <= array.length; i++) {
|
||||||
assertTrue(iterator.hasNext());
|
assertTrue(iterator.hasNext());
|
||||||
|
@ -184,10 +184,19 @@ public class TestFilterIterator extends TestIterator {
|
||||||
assertTrue(i == elements.length - 1 ? !iterator.hasNext() : iterator.hasNext());
|
assertTrue(i == elements.length - 1 ? !iterator.hasNext() : iterator.hasNext());
|
||||||
}
|
}
|
||||||
verifyNoMoreElements();
|
verifyNoMoreElements();
|
||||||
|
|
||||||
|
// test removal
|
||||||
|
initIterator();
|
||||||
|
iterator.setPredicate(pred);
|
||||||
|
if (iterator.hasNext()) {
|
||||||
|
Object last = iterator.next();
|
||||||
|
iterator.remove();
|
||||||
|
assertTrue("Base of FilterIterator still contains removed element.", !list.contains(last));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initIterator() {
|
private void initIterator() {
|
||||||
iterator = makePassThroughFilter(new ArrayIterator(array));
|
iterator = (FilterIterator) makeFullIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/TestUniqueFilterIterator.java,v 1.2 2002/10/12 22:36:23 scolebourne Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/TestUniqueFilterIterator.java,v 1.3 2003/01/30 23:11:58 scolebourne Exp $
|
||||||
* $Revision: 1.2 $
|
|
||||||
* $Date: 2002/10/12 22:36:23 $
|
|
||||||
*
|
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
*
|
*
|
||||||
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
|
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
|
||||||
* reserved.
|
* reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -23,11 +20,11 @@
|
||||||
* distribution.
|
* distribution.
|
||||||
*
|
*
|
||||||
* 3. The end-user documentation included with the redistribution, if
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
* any, must include the following acknowlegement:
|
* any, must include the following acknowledgment:
|
||||||
* "This product includes software developed by the
|
* "This product includes software developed by the
|
||||||
* Apache Software Foundation (http://www.apache.org/)."
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
* Alternately, this acknowlegement may appear in the software itself,
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
* if and wherever such third-party acknowlegements normally appear.
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
*
|
*
|
||||||
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
* Foundation" must not be used to endorse or promote products derived
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
@ -36,7 +33,7 @@
|
||||||
*
|
*
|
||||||
* 5. Products derived from this software may not be called "Apache"
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
* nor may "Apache" appear in their names without prior written
|
* nor may "Apache" appear in their names without prior written
|
||||||
* permission of the Apache Group.
|
* permission of the Apache Software Foundation.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
@ -58,7 +55,6 @@
|
||||||
* <http://www.apache.org/>.
|
* <http://www.apache.org/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.commons.collections.iterators;
|
package org.apache.commons.collections.iterators;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -77,7 +73,8 @@ import junit.framework.TestSuite;
|
||||||
* @author James Strachan
|
* @author James Strachan
|
||||||
* @author Mauricio S. Moura
|
* @author Mauricio S. Moura
|
||||||
* @author Morgan Delagrange
|
* @author Morgan Delagrange
|
||||||
* @version $Id: TestUniqueFilterIterator.java,v 1.2 2002/10/12 22:36:23 scolebourne Exp $
|
* @author Stephen Colebourne
|
||||||
|
* @version $Revision: 1.3 $ $Date: 2003/01/30 23:11:58 $
|
||||||
*/
|
*/
|
||||||
public class TestUniqueFilterIterator extends TestIterator {
|
public class TestUniqueFilterIterator extends TestIterator {
|
||||||
|
|
||||||
|
@ -146,17 +143,5 @@ public class TestUniqueFilterIterator extends TestIterator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemove() {
|
|
||||||
Iterator iter = (Iterator) makeFullIterator();
|
|
||||||
|
|
||||||
try {
|
|
||||||
iter.remove();
|
|
||||||
fail("FilterIterator does not support the remove() method");
|
|
||||||
} catch (UnsupportedOperationException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue