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 2003/11/12 12:37:52 UTC

[collections] how to *NEST* (not CHAIN) iterators

Consider the following:

Class 'A' contains many 'B's
It provides an Iterator() over these 'B's

Class 'B' contains many 'C's
It provides an Iterator() over these 'C's

I would like to add a method to class 'A'
that returns an iterator over the 'C's it
(indirectly) contains.

The obvious way is to use the 'A' level iterator
to get all the 'B's, and to add the iterator from
each 'B' to a ChainedIterator, whic gives the correct result.

However, if A is large, the resulting ChainedIterator
has is also large, and potentially time consuming to generate.

Essentially we've been forced to build (something like)
the list of 'B's which is what the various Iterators in
Collections are designed to avoid.

I would like (somehow) to iterate over the 'C's directly,
by somehow "nesting" (as opposed to chaining) the 2 levels
of iteration, but cannot see how.

      BugBear (AKA P Womack)


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [collections] how to *NEST* (not CHAIN) iterators

Posted by Stephen Colebourne <sc...@btopenworld.com>.
If you have a particular solution in mind, perhaps a patch or code sample
would clarify it in my mind.

You might also want to look at the new CompositeCollection class on the CVS,
although I don't _think_ its what you need.

Stephen

From: "pwomack" <pw...@papermule.co.uk>
> Stephen Colebourne wrote:
> > We have nothing that I can think of that would help. What you need it
would
> > seem is a variation on the IteratorChain that takes in a collection of
> > things that have iterators.
>
> I think I need something that takes an iterator...
> that returns things that have iterators.
>
> Essentially, the IteratorChain takes a collection (along
> with some very useful parameter overloads).
>
> But one of the claimed benefits of the design
> is *avoiding* having to construct collections,
> allowing the user to iterate over a "virtual" collection.
>
> What I want to do is add this benefit to IteratorChain
> itself.
>
>      BugBear
>
> >
> > Stephen
> >
> > ----- Original Message -----
> > From: "pwomack" <pw...@papermule.co.uk>
> > To: <co...@jakarta.apache.org>
> > Sent: Wednesday, November 12, 2003 11:37 AM
> > Subject: [collections] how to *NEST* (not CHAIN) iterators
> >
> >
> >
> >>Consider the following:
> >>
> >>Class 'A' contains many 'B's
> >>It provides an Iterator() over these 'B's
> >>
> >>Class 'B' contains many 'C's
> >>It provides an Iterator() over these 'C's
> >>
> >>I would like to add a method to class 'A'
> >>that returns an iterator over the 'C's it
> >>(indirectly) contains.
> >>
> >>The obvious way is to use the 'A' level iterator
> >>to get all the 'B's, and to add the iterator from
> >>each 'B' to a ChainedIterator, whic gives the correct result.
> >>
> >>However, if A is large, the resulting ChainedIterator
> >>has is also large, and potentially time consuming to generate.
> >>
> >>Essentially we've been forced to build (something like)
> >>the list of 'B's which is what the various Iterators in
> >>Collections are designed to avoid.
> >>
> >>I would like (somehow) to iterate over the 'C's directly,
> >>by somehow "nesting" (as opposed to chaining) the 2 levels
> >>of iteration, but cannot see how.
> >>
> >>      BugBear (AKA P Womack)
> >>
> >>
> >>---------------------------------------------------------------------
> >>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
> >
>
>
>
> ---------------------------------------------------------------------
> 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] how to *NEST* (not CHAIN) iterators

Posted by pwomack <pw...@papermule.co.uk>.
Stephen Colebourne wrote:
> We have nothing that I can think of that would help. What you need it would
> seem is a variation on the IteratorChain that takes in a collection of
> things that have iterators.

I think I need something that takes an iterator...
that returns things that have iterators.

Essentially, the IteratorChain takes a collection (along
with some very useful parameter overloads).

But one of the claimed benefits of the design
is *avoiding* having to construct collections,
allowing the user to iterate over a "virtual" collection.

What I want to do is add this benefit to IteratorChain
itself.

     BugBear

> 
> Stephen
> 
> ----- Original Message -----
> From: "pwomack" <pw...@papermule.co.uk>
> To: <co...@jakarta.apache.org>
> Sent: Wednesday, November 12, 2003 11:37 AM
> Subject: [collections] how to *NEST* (not CHAIN) iterators
> 
> 
> 
>>Consider the following:
>>
>>Class 'A' contains many 'B's
>>It provides an Iterator() over these 'B's
>>
>>Class 'B' contains many 'C's
>>It provides an Iterator() over these 'C's
>>
>>I would like to add a method to class 'A'
>>that returns an iterator over the 'C's it
>>(indirectly) contains.
>>
>>The obvious way is to use the 'A' level iterator
>>to get all the 'B's, and to add the iterator from
>>each 'B' to a ChainedIterator, whic gives the correct result.
>>
>>However, if A is large, the resulting ChainedIterator
>>has is also large, and potentially time consuming to generate.
>>
>>Essentially we've been forced to build (something like)
>>the list of 'B's which is what the various Iterators in
>>Collections are designed to avoid.
>>
>>I would like (somehow) to iterate over the 'C's directly,
>>by somehow "nesting" (as opposed to chaining) the 2 levels
>>of iteration, but cannot see how.
>>
>>      BugBear (AKA P Womack)
>>
>>
>>---------------------------------------------------------------------
>>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
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [collections] how to *NEST* (not CHAIN) iterators

Posted by Stephen Colebourne <sc...@btopenworld.com>.
We have nothing that I can think of that would help. What you need it would
seem is a variation on the IteratorChain that takes in a collection of
things that have iterators.

Stephen

----- Original Message -----
From: "pwomack" <pw...@papermule.co.uk>
To: <co...@jakarta.apache.org>
Sent: Wednesday, November 12, 2003 11:37 AM
Subject: [collections] how to *NEST* (not CHAIN) iterators


> Consider the following:
>
> Class 'A' contains many 'B's
> It provides an Iterator() over these 'B's
>
> Class 'B' contains many 'C's
> It provides an Iterator() over these 'C's
>
> I would like to add a method to class 'A'
> that returns an iterator over the 'C's it
> (indirectly) contains.
>
> The obvious way is to use the 'A' level iterator
> to get all the 'B's, and to add the iterator from
> each 'B' to a ChainedIterator, whic gives the correct result.
>
> However, if A is large, the resulting ChainedIterator
> has is also large, and potentially time consuming to generate.
>
> Essentially we've been forced to build (something like)
> the list of 'B's which is what the various Iterators in
> Collections are designed to avoid.
>
> I would like (somehow) to iterate over the 'C's directly,
> by somehow "nesting" (as opposed to chaining) the 2 levels
> of iteration, but cannot see how.
>
>       BugBear (AKA P Womack)
>
>
> ---------------------------------------------------------------------
> 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