gpt4 book ai didi

java - 从 Guava ImmutableTable 派生的 View 的迭代顺序

转载 作者:行者123 更新时间:2023-12-01 11:14:52 26 4
gpt4 key购买 nike

从 Guava 不可变表派生的 View 是否保留原始提供表中的插入顺序?

例如,考虑如下“原始提供的表格”。

ImmutableTable<String, String, String> table = ImmutableTable.<String, String, String>builder()
.put("r1", "c1", "v1")
.put("r2", "c1", "v2")
.put("r3", "c1", "v3")
.put("r4", "c2", "v4")
.build();

现在如果我进行手术

table.column("c1").entrySet().iterator()

迭代是否会按照插入顺序“原始提供的表”提供结果?

注意:按照documentation对从 ArrayTable 派生的 View 进行迭代会保留原始表中的插入顺序。我的用例更倾向于使用不可变表。

最佳答案

是的。请参阅JavaDoc of ImmutableTable .

An immutable Table with reliable user-specified iteration order.

加:

  • ImmutableTable.column() 返回一个 ImmutableMap,它在 JavaDoc具有可靠的用户指定的迭代顺序 .
  • 对于不可变的数据结构,我认为“迭代顺序”应该是其 View 的行为。
  • 对于“用户指定的迭代顺序”,ImmutableTable.Builder#orderColumnsBy可以实现。

关于java - 从 Guava ImmutableTable 派生的 View 的迭代顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31962229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com