commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pwomack <>
Subject [collections] Iterator Exception behaviour
Date Thu, 08 Jan 2004 15:36:30 GMT
I note from the spec that IteratorChain (amonst others)
throws an exception if it is empty;

         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);
     for(Iterator ic = b.iterator(); ic.hasNext();) {
         ObjC c = (ObjC);
         // do something with a 'C'

into this form:

IteratorChain allC = new IteratorChain();
for(Iterator ib = a.iterator(); ib.hasNext();) {
     ObjB b = (ObjB);

for(;allC.hasNext();) {
    ObjC c = (ObjC);
    // 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.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message