commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pwomack <pwom...@papermule.co.uk>
Subject [collections] how to *NEST* (not CHAIN) iterators
Date Wed, 12 Nov 2003 11:37:52 GMT
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


Mime
View raw message