You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by pwomack <pw...@papermule.co.uk> on 2004/01/08 16:36:30 UTC
[collections] Iterator Exception behaviour
I note from the spec that IteratorChain (amonst others)
throws an exception if it is empty;
Throws:
UnsupportedOperationException - if the IteratorChain does not
contain at least one Iterator
This results in the following unfortunate behaviour; if I
transform this code:
for(Iterator ib = a.iterator(); ib.hasNext();) {
ObjB b = (ObjB)ib.next();
for(Iterator ic = b.iterator(); ic.hasNext();) {
ObjC c = (ObjC)ic.next();
// do something with a 'C'
}
}
into this form:
IteratorChain allC = new IteratorChain();
for(Iterator ib = a.iterator(); ib.hasNext();) {
ObjB b = (ObjB)ib.next();
allC.addIterator(b.iterator());
}
for(;allC.hasNext();) {
ObjC c = (ObjC)allC.next();
// do something with a 'C'
}
If the original 'a' is empty, the second version throws an Exception,
(since allC has no Iterators) whereas the first version correctly
does nothing.
I assert that the second version should be as equivalent
as possible to this first; in short I believe that
the Exception should not be thrown.
BugBear
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [collections] Iterator Exception behaviour
Posted by Stephen Colebourne <sc...@btopenworld.com>.
Fixed in CVS, and the upcoming 3.0
Stephen
----- Original Message -----
From: "Janek Bogucki" <ya...@studylink.com>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Thursday, January 08, 2004 8:58 PM
Subject: Re: [collections] Iterator Exception behaviour
> On Thu, 2004-01-08 at 10:36, pwomack wrote:
> > I assert that the second version should be as equivalent
> > as possible to this first; in short I believe that
> > the Exception should not be thrown.
> >
> > BugBear
>
> I agree.
>
> -Janek
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [collections] Iterator Exception behaviour
Posted by Janek Bogucki <ya...@studylink.com>.
On Thu, 2004-01-08 at 10:36, pwomack wrote:
> I assert that the second version should be as equivalent
> as possible to this first; in short I believe that
> the Exception should not be thrown.
>
> BugBear
I agree.
-Janek
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org