Class TreeBasedTable<R,C,V>

java.lang.Object
cloud.opencode.base.collections.specialized.TreeBasedTable<R,C,V>
Type Parameters:
R - row key type | 行键类型
C - column key type | 列键类型
V - value type | 值类型
All Implemented Interfaces:
Table<R,C,V>, Serializable

public final class TreeBasedTable<R,C,V> extends Object implements Table<R,C,V>, Serializable
TreeBasedTable - Tree-based Table Implementation TreeBasedTable - 基于树的表实现

A table implementation using TreeMaps for sorted row and column keys.

使用 TreeMap 对行和列键进行排序的表实现。

Features | 主要功能:

  • Sorted row and column keys - 排序的行和列键
  • Natural or custom ordering - 自然或自定义排序
  • Efficient range queries - 高效范围查询

Usage Examples | 使用示例:

TreeBasedTable<String, String, Integer> table = TreeBasedTable.create();
table.put("row1", "col1", 1);
table.put("row2", "col2", 2);

Integer value = table.get("row1", "col1");  // 1

// Rows and columns are sorted
for (String row : table.rowKeySet()) {
    // Iterates in sorted order
}

Performance | 性能特性:

  • get: O(log r + log c) where r=rows, c=columns - get: O(log r + log c)
  • put: O(log r + log c) - put: O(log r + log c)
  • containsRow/Column: O(log r/c) - containsRow/Column: O(log r/c)

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
  • Null-safe: No (nulls not allowed) - 空值安全: 否(不允许空值)
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • create

      public static <R extends Comparable<? super R>, C extends Comparable<? super C>, V> TreeBasedTable<R,C,V> create()
      Create an empty TreeBasedTable with natural ordering. 创建自然排序的空 TreeBasedTable。
      Type Parameters:
      R - row key type | 行键类型
      C - column key type | 列键类型
      V - value type | 值类型
      Returns:
      new empty TreeBasedTable | 新空 TreeBasedTable
    • create

      public static <R,C,V> TreeBasedTable<R,C,V> create(Comparator<? super R> rowComparator, Comparator<? super C> columnComparator)
      Create an empty TreeBasedTable with custom comparators. 创建自定义比较器的空 TreeBasedTable。
      Type Parameters:
      R - row key type | 行键类型
      C - column key type | 列键类型
      V - value type | 值类型
      Parameters:
      rowComparator - row comparator | 行比较器
      columnComparator - column comparator | 列比较器
      Returns:
      new empty TreeBasedTable | 新空 TreeBasedTable
    • get

      public V get(Object rowKey, Object columnKey)
      Description copied from interface: Table
      Get the value at the specified row and column. 获取指定行列的值。
      Specified by:
      get in interface Table<R,C,V>
      Parameters:
      rowKey - the row key | 行键
      columnKey - the column key | 列键
      Returns:
      the value, or null | 值,或 null
    • contains

      public boolean contains(Object rowKey, Object columnKey)
      Description copied from interface: Table
      Check if the table contains a mapping with the row and column keys. 检查表是否包含指定行列键的映射。
      Specified by:
      contains in interface Table<R,C,V>
      Parameters:
      rowKey - the row key | 行键
      columnKey - the column key | 列键
      Returns:
      true if contains | 如果包含则返回 true
    • containsRow

      public boolean containsRow(Object rowKey)
      Description copied from interface: Table
      Check if the table contains a mapping with the row key. 检查表是否包含指定行键的映射。
      Specified by:
      containsRow in interface Table<R,C,V>
      Parameters:
      rowKey - the row key | 行键
      Returns:
      true if contains | 如果包含则返回 true
    • containsColumn

      public boolean containsColumn(Object columnKey)
      Description copied from interface: Table
      Check if the table contains a mapping with the column key. 检查表是否包含指定列键的映射。
      Specified by:
      containsColumn in interface Table<R,C,V>
      Parameters:
      columnKey - the column key | 列键
      Returns:
      true if contains | 如果包含则返回 true
    • containsValue

      public boolean containsValue(Object value)
      Description copied from interface: Table
      Check if the table contains a mapping with the value. 检查表是否包含指定值的映射。
      Specified by:
      containsValue in interface Table<R,C,V>
      Parameters:
      value - the value | 值
      Returns:
      true if contains | 如果包含则返回 true
    • put

      public V put(R rowKey, C columnKey, V value)
      Description copied from interface: Table
      Put a value at the specified row and column. 在指定行列放入值。
      Specified by:
      put in interface Table<R,C,V>
      Parameters:
      rowKey - the row key | 行键
      columnKey - the column key | 列键
      value - the value | 值
      Returns:
      previous value, or null | 之前的值,或 null
    • putAll

      public void putAll(Table<? extends R, ? extends C, ? extends V> table)
      Description copied from interface: Table
      Put all values from another table. 从另一个表放入所有值。
      Specified by:
      putAll in interface Table<R,C,V>
      Parameters:
      table - the source table | 源表
    • remove

      public V remove(Object rowKey, Object columnKey)
      Description copied from interface: Table
      Remove the value at the specified row and column. 移除指定行列的值。
      Specified by:
      remove in interface Table<R,C,V>
      Parameters:
      rowKey - the row key | 行键
      columnKey - the column key | 列键
      Returns:
      removed value, or null | 移除的值,或 null
    • row

      public Map<C,V> row(R rowKey)
      Description copied from interface: Table
      Return a map view for a specific row. 返回特定行的映射视图。
      Specified by:
      row in interface Table<R,C,V>
      Parameters:
      rowKey - the row key | 行键
      Returns:
      column to value map | 列到值的映射
    • column

      public Map<R,V> column(C columnKey)
      Description copied from interface: Table
      Return a map view for a specific column. 返回特定列的映射视图。
      Specified by:
      column in interface Table<R,C,V>
      Parameters:
      columnKey - the column key | 列键
      Returns:
      row to value map | 行到值的映射
    • cellSet

      public Set<Table.Cell<R,C,V>> cellSet()
      Description copied from interface: Table
      Return a view of all cells. 返回所有单元格的视图。
      Specified by:
      cellSet in interface Table<R,C,V>
      Returns:
      cell set | 单元格集合
    • rowKeySet

      public Set<R> rowKeySet()
      Description copied from interface: Table
      Return a view of all row keys. 返回所有行键的视图。
      Specified by:
      rowKeySet in interface Table<R,C,V>
      Returns:
      row key set | 行键集合
    • columnKeySet

      public Set<C> columnKeySet()
      Description copied from interface: Table
      Return a view of all column keys. 返回所有列键的视图。
      Specified by:
      columnKeySet in interface Table<R,C,V>
      Returns:
      column key set | 列键集合
    • values

      public Collection<V> values()
      Description copied from interface: Table
      Return a view of all values. 返回所有值的视图。
      Specified by:
      values in interface Table<R,C,V>
      Returns:
      values collection | 值集合
    • rowMap

      public Map<R,Map<C,V>> rowMap()
      Description copied from interface: Table
      Return a map view of all rows. 返回所有行的映射视图。
      Specified by:
      rowMap in interface Table<R,C,V>
      Returns:
      row key to column-value map | 行键到列值映射
    • columnMap

      public Map<C,Map<R,V>> columnMap()
      Description copied from interface: Table
      Return a map view of all columns. 返回所有列的映射视图。
      Specified by:
      columnMap in interface Table<R,C,V>
      Returns:
      column key to row-value map | 列键到行值映射
    • size

      public int size()
      Description copied from interface: Table
      Return the number of row-column-value mappings. 返回行列值映射的数量。
      Specified by:
      size in interface Table<R,C,V>
      Returns:
      size | 大小
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Table
      Check if the table contains any mappings. 检查表是否为空。
      Specified by:
      isEmpty in interface Table<R,C,V>
      Returns:
      true if empty | 如果为空则返回 true
    • clear

      public void clear()
      Description copied from interface: Table
      Clear all mappings. 清除所有映射。
      Specified by:
      clear in interface Table<R,C,V>
    • rowComparator

      public Comparator<? super R> rowComparator()
      Return the row comparator. 返回行比较器。
      Returns:
      the row comparator | 行比较器
    • columnComparator

      public Comparator<? super C> columnComparator()
      Return the column comparator. 返回列比较器。
      Returns:
      the column comparator | 列比较器
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object