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开发者_JAVA百科 ever return this. Is there, in fact, a way to iterate a LinkedHashMap
or a LinkedHashMultimap
via a subclass of one of these?
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.
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?
AbstractLinkedIterator
is very useful for creating Iterator
s and Iterable
s 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
.
精彩评论