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.
I'd welcome an patch for this with tests.


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;
This sounds no different to ListIteratorWrapper, or IteratorUtils.toList(). IMHO, [collections] is probably over abstracted now.

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.
Why not just call iterator() on the List object? Perhaps you mean a ResettableIteratorWrapper, which could be useful.

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;
This is probably best achieved as a patch to ListIteratorWrapper.

4.) Retrofitting ListIteratorWrapper, to use 1.) and 2.)
Changing a superclass is a binary incompatible change, so we couldn't do that.

5.) Writing a Decorator, that converts a ResettableIterator into a
LoopingIterator
Could be done but probably of limited value.

Stephen

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to