bmargulies
bmargulies

Reputation: 100133

restartable linked hash map iteration, possible via guava

Guava's AbstractLinkedIterator class

seems to exist to allow for restarting an iteration in the middle of something like a LinkedHashMap. But I'm failing to find any classes in guava that ever return this. Is there, in fact, a way to iterate a LinkedHashMap or a LinkedHashMultimap via a subclass of one of these?

Upvotes: 1

Views: 357

Answers (3)

Gabriel Ščerbák
Gabriel Ščerbák

Reputation: 18570

AbstractLinkedIterator is very useful for creating Iterators and Iterables that represent reccurances - e.g. potentially infinite Iterable with prime numbers etc.

If you need to restart the iteration, just use the Iterable to create new Iterator.

Upvotes: 0

ColinD
ColinD

Reputation: 110084

AbstractLinkedIterator, as its Javadoc states:

provides a skeletal implementation of the Iterator interface for sequences whose next element can always be derived from the previous element.

That's all it's for. It doesn't have any knowledge of, say, a current linked entry in in a LinkedHashMap. If you had access to the nodes of a linked structure and you made this an Iterator<Node> you could of course compute the next node from the previous one, but LinkedHashMap doesn't expose its linked entries.

Upvotes: 3

alpian
alpian

Reputation: 4748

This link says there are no uses as yet (02/05/2011) and i certainly couldn't find any either. Looking at the source code this is a very skeletal implementation which just calls down to it's inheritors to ask them what the next might be based on the current element but you'd have to implement the meat of it yourself (which might indeed give you your Iterators that can start from any point in some ordered set/list). What is it you're trying to do?

Upvotes: 2

Related Questions