可重新启动的链接哈希图迭代,可以通过番石榴实现

发布于 2024-11-04 06:22:47 字数 392 浏览 1 评论 0原文

Guava 的 AbstractLinkedIterator类的

存在似乎允许在像 LinkedHashMap 这样的东西中间重新启动迭代。但我在番石榴中找不到任何返回这个的类。事实上,是否有一种方法可以通过其中一个的子类来迭代 LinkedHashMapLinkedHashMultimap

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱殇璃 2024-11-11 06:22:47

AbstractLinkedIterator,如其 Javadoc 所述:

为序列提供Iterator接口的骨架实现,其下一个元素始终可以从前一个元素派生。

这就是它的全部目的。例如,它不了解 LinkedHashMap 中当前链接的条目。如果您有权访问链接结构的节点并将其设为 Iterator,您当然可以根据前一个节点计算下一个节点,但 LinkedHashMap 不会不要公开其链接的条目。

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.

街道布景 2024-11-11 06:22:47

此链接说目前还没有任何用途(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?

晚风撩人 2024-11-11 06:22:47

AbstractLinkedIterator 对于创建表示重复的 IteratorIterable 非常有用 - 例如带有素数的潜在无限 Iterable等等。

如果需要重新开始迭代,只需使用Iterable创建新的Iterator即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文