commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Billen <pe...@clueless.be>
Subject [collections] IteratorChain.remove() in combination with FilterIterator
Date Fri, 01 Apr 2005 10:41:32 GMT
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


Mime
View raw message