有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

基于google guava树表索引的java子集

我有一个TreeBasedTable<String,String,CustomType>结构,从中我需要能够获得基于startend范围索引的子集,比如fromindextoindexcellSet方法不返回SortedSet。最好的方法是什么

我想做Lists.newArrayList(structure.cellSet()).subList(start,end),但看起来不是一件有效的事情


共 (2) 个答案

  1. # 1 楼答案

    当使用^{}时,^{}的实现实际上返回一个^{}

    所以你应该使用:

    @SuppressWarnings("unchecked") // safe cast because TreeBasedTable returns SortedMap
    final SortedMap<String, Map<String, CustomType>> rowMap = (SortedMap<String, Map<String, CustomType>>) myTable.rowMap();
    final SortedMap<String, Map<String, CustomType>> subRowMap = rowMap.subMap(start, end);
    

    所以startend将对rowMap起作用,就像subList(start,end)List起作用一样

  2. # 2 楼答案

    如果startindexendindex是整数位置,那么ArrayList实现实际上离可行的最佳状态并没有太远,尽管它的编写效率会稍微高一些

    FluentIterable.from(table.cellSet()).skip(fromIndex).limit(toIndex).toList()
    

    它不会将更多元素复制到任何实现的结果中

    一般来说,对于任意的SortedSetSortedMap,或者Java附带的几乎任何排序数据结构,都没有一种有效的方法来实现这一点