I am interested if there is any framework that implements a collection that would have the following behavior.
Suppose it initially contains: [1, 2, 3]
- I iterate it (using an iterator) and reach element 2, now I add 4 to the end (the collection will now be [1, 2, 3, 4]).
- now I create a new iterator and iterate the collection, resulting in [1, 2, 3, 4]
- I continue iterating with the first iterator and it will give me just 3 and return
- now resetting the first iterator will give me [1, 2, 3, 4] (similar to creating a new one).
Same should apply for removal of elements. If I remove 3 instead of adding, the second iterator should give me [1, 2] while the first one will still give me 3 and the end.
So when I get and iterator I want it to give me the collection I had when I created the iterator (even if I iterate it later, on I iterate a bit and continue later), when I reset the iterator, it gets garbage collected it will update to the latest versions and I should be able to have multiple iterator instances created at different times that will give different versions depending on the contents of the array when the iterator was created.
I would need it to work well with multiple threads and preferable have an efficient implementation.
Does anyone know of any implementation of such a collection, or do I have to implement it myself?