可重新启动的链接哈希图迭代,可以通过番石榴实现
Guava 的 AbstractLinkedIterator
类的
存在似乎允许在像 LinkedHashMap
这样的东西中间重新启动迭代。但我在番石榴中找不到任何返回这个的类。事实上,是否有一种方法可以通过其中一个的子类来迭代 LinkedHashMap
或 LinkedHashMultimap
?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AbstractLinkedIterator
,如其 Javadoc 所述:这就是它的全部目的。例如,它不了解
LinkedHashMap
中当前链接的条目。如果您有权访问链接结构的节点并将其设为Iterator
,您当然可以根据前一个节点计算下一个节点,但LinkedHashMap
不会不要公开其链接的条目。AbstractLinkedIterator
, as its Javadoc states: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 anIterator<Node>
you could of course compute the next node from the previous one, butLinkedHashMap
doesn't expose its linked entries.此链接说目前还没有任何用途(02/05/2011),我当然也找不到任何用途。查看源代码,这是一个非常的骨架实现,它只是调用它的继承者来询问他们下一个可能基于当前元素是什么,但你必须自己实现它的核心(这确实可能为您提供可以从某些有序集/列表中的任何点开始的迭代器)。你想做什么?
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
对于创建表示重复的Iterator
和Iterable
非常有用 - 例如带有素数的潜在无限Iterable
等等。如果需要重新开始迭代,只需使用
Iterable
创建新的Iterator
即可。AbstractLinkedIterator
is very useful for creatingIterator
s andIterable
s that represent reccurances - e.g. potentially infiniteIterable
with prime numbers etc.If you need to restart the iteration, just use the
Iterable
to create newIterator
.