使用索引值从 HashBasedTable(Guava 集合)中提取数据

Extracting data from a HashBasedTable (a Guava collection) using index values

我有一个方法 returns HashBasedTable(来自 Google 的 Guava 项目:https://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#Table

我希望在 table 创建后从中提取值。

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
/**
 *
 * @author yschellekens
 */
public class Whosebug {  

    /**
     *
     * @return
     */
    public static Table<Long, Long, String> getGeoTargeting()  {
         Table<Long, Long, String> weightedGraph = HashBasedTable.create();

         weightedGraph.put(999_99_9999L, 999_99_9999L, "blabla");
         return weightedGraph;
 }


   public static void main(String[] args) throws Exception {
     Table<Long, Long, String> weightedGraph = HashBasedTable.create();
       weightedGraph=getGeoTargeting();
      System.out.println(weightedGraph.isEmpty());
   }
}

输出:

run:
false
BUILD SUCCESSFUL (total time: 2 seconds) 

我的问题是:如何从 table 中提取单个元素,例如(允许我按索引提取元素):

get(int index) //as in array list

而不是喜欢(这是 Hashbasetable 的 Javadoc 中唯一的 get 方法)

get(Object rowKey, Object columnKey)
Returns the value corresponding to the given row and column keys, or null if no such mapping exists.

因为我想通过索引而不是值提取元素

提前致谢!

要检索 table 中的所有值作为集合,请执行以下操作:

Collection values = weightedGraph.values()

要按索引访问返回集合中的任何值,请执行以下操作:

new ArrayList(values).get(index);