Dear all, Looking for a way, to turn any existing iterator into one, that can be exercised repeatedly, I stumbled upon the classes/if's ResettableIterator, AbstractIteratorDecorator, and ListIteratorWrapper, but didn't actually found an elegant solution for this. Obviously, the simplest option to include something like this into collections, was to turn ListIteratorWrapper into a ResettableIterator by implementing the reset() method.
But milling the ideas around, I'd like to offer a different approach, that I'm willing to contribute instead, if nobody objects. This would involve introducing the following classes: 1.) A derivation of AbstractIteratorDecorator, with the only function to record the returned elements, as they are traversed - candidate name: CachedIterator or CachedIteratorDecorator. This Decorator would use a List as cache, which could either be injected, or created automatically; 2.) An Iterator, that wraps a list similar the manor, ArrayIterator wraps access to an array, with the possible extension, that reset() and add() would be supported too. (Possible problem here: Its difficult to think of a name, with ListIterator and ListIteratorWrapper already taken) 3.) Combining the two into ResettableCachedIterator (involves using ChainedIterator to do the trick) I'm suggesting to use the infix 'Cached' here, because there is the possibility of a completely different implementation of a decorator allowing resettability: by passing a factory, that is reproducing the underlying iterator on reset, if necessary; The difference is obvious: the cached approach is guaranteed to reproduce the sequence of elements exactly, the factory appraoch is not; As further steps, the following could be done: 4.) Retrofitting ListIteratorWrapper, to use 1.) and 2.) 5.) Writing a Decorator, that converts a ResettableIterator into a LoopingIterator Again, I'm willing to volonteer for that work. Any comments? Thomas --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
