You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Peter Billen <pe...@clueless.be> on 2005/04/01 12:41:32 UTC
[collections] IteratorChain.remove() in combination with FilterIterator
Hello all,
I'm having some troubles with the IteratorChain.remove() function, when one of
the underlying iterators is a FilterIterator. It throws an
IllegalStateException ("remove() cannot be called"). As I believe this is a
bug, I'm posting it to the dev-mailinglist.
Here is a simplified code snippet:
public class Main {
private static class MyPredicate implements Predicate {
public boolean evaluate(Object o) {
Integer i = (Integer) o;
if (i.compareTo(new Integer(4)) < 0)
return true;
return false;
}
}
public static void main(String[] args) {
List list1 = new ArrayList();
List list2 = new ArrayList();
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(), new
MyPredicate());
Iterator it2 = IteratorUtils.filteredIterator(list2.iterator(), new
MyPredicate());
Iterator it = IteratorUtils.chainedIterator(it1, it2);
while (it.hasNext()) {
System.out.println(it.next());
it.remove();
}
}
}
Thanks all.
Kinds regards,
--
Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org