Interface Table<R,C,V>

Type Parameters:
R - row key type | 行键类型
C - column key type | 列键类型
V - value type | 值类型
All Known Implementing Classes:
ArrayTable, HashBasedTable, TreeBasedTable

public interface Table<R,C,V>
Table - Two-dimensional Map with Row and Column Keys Table - 带行和列键的二维映射

A collection that associates an ordered pair of keys (row key, column key) with a single value. Similar to a 2D array or spreadsheet.

将有序键对(行键、列键)与单个值关联的集合。类似于二维数组或电子表格。

Features | 主要功能:

  • Two-dimensional mapping - 二维映射
  • Row view (row key to column-value map) - 行视图(行键到列值映射)
  • Column view (column key to row-value map) - 列视图(列键到行值映射)
  • Cell view (all row-column-value triples) - 单元格视图(所有行列值三元组)

Usage Examples | 使用示例:

// Create Table - 创建 Table
Table<String, String, Integer> table = HashBasedTable.create();

// Put values - 放入值
table.put("row1", "col1", 100);
table.put("row1", "col2", 200);
table.put("row2", "col1", 300);

// Get value - 获取值
Integer value = table.get("row1", "col1");  // 100

// Get row view - 获取行视图
Map<String, Integer> row = table.row("row1");  // {col1=100, col2=200}

// Get column view - 获取列视图
Map<String, Integer> col = table.column("col1");  // {row1=100, row2=300}

// Iterate cells - 迭代单元格
for (Table.Cell<String, String, Integer> cell : table.cellSet()) {
    System.out.println(cell.getRowKey() + "," + cell.getColumnKey() + "=" + cell.getValue());
}

Performance | 性能特性:

  • get: O(1) for hash-based - get: O(1) 基于哈希
  • put: O(1) for hash-based - put: O(1) 基于哈希
  • row/column: O(1) - row/column: O(1)

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
  • Null-safe: Implementation dependent - 空值安全: 取决于实现
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Cell - A row-column-value triple Cell - 行列值三元组
  • Method Summary

    Modifier and Type
    Method
    Description
    Return a view of all cells.
    void
    Clear all mappings.
    column(C columnKey)
    Return a map view for a specific column.
    Return a view of all column keys.
    Map<C,Map<R,V>>
    Return a map view of all columns.
    boolean
    contains(Object rowKey, Object columnKey)
    Check if the table contains a mapping with the row and column keys.
    boolean
    Check if the table contains a mapping with the column key.
    boolean
    Check if the table contains a mapping with the row key.
    boolean
    Check if the table contains a mapping with the value.
    get(Object rowKey, Object columnKey)
    Get the value at the specified row and column.
    boolean
    Check if the table contains any mappings.
    put(R rowKey, C columnKey, V value)
    Put a value at the specified row and column.
    void
    putAll(Table<? extends R, ? extends C, ? extends V> table)
    Put all values from another table.
    remove(Object rowKey, Object columnKey)
    Remove the value at the specified row and column.
    row(R rowKey)
    Return a map view for a specific row.
    Return a view of all row keys.
    Map<R,Map<C,V>>
    Return a map view of all rows.
    int
    Return the number of row-column-value mappings.
    Return a view of all values.
  • Method Details

    • isEmpty

      boolean isEmpty()
      Check if the table contains any mappings. 检查表是否为空。
      Returns:
      true if empty | 如果为空则返回 true
    • size

      int size()
      Return the number of row-column-value mappings. 返回行列值映射的数量。
      Returns:
      size | 大小
    • clear

      void clear()
      Clear all mappings. 清除所有映射。
    • contains

      boolean contains(Object rowKey, Object columnKey)
      Check if the table contains a mapping with the row and column keys. 检查表是否包含指定行列键的映射。
      Parameters:
      rowKey - the row key | 行键
      columnKey - the column key | 列键
      Returns:
      true if contains | 如果包含则返回 true
    • containsRow

      boolean containsRow(Object rowKey)
      Check if the table contains a mapping with the row key. 检查表是否包含指定行键的映射。
      Parameters:
      rowKey - the row key | 行键
      Returns:
      true if contains | 如果包含则返回 true
    • containsColumn

      boolean containsColumn(Object columnKey)
      Check if the table contains a mapping with the column key. 检查表是否包含指定列键的映射。
      Parameters:
      columnKey - the column key | 列键
      Returns:
      true if contains | 如果包含则返回 true
    • containsValue

      boolean containsValue(Object value)
      Check if the table contains a mapping with the value. 检查表是否包含指定值的映射。
      Parameters:
      value - the value | 值
      Returns:
      true if contains | 如果包含则返回 true
    • get

      V get(Object rowKey, Object columnKey)
      Get the value at the specified row and column. 获取指定行列的值。
      Parameters:
      rowKey - the row key | 行键
      columnKey - the column key | 列键
      Returns:
      the value, or null | 值,或 null
    • put

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

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

      V remove(Object rowKey, Object columnKey)
      Remove the value at the specified row and column. 移除指定行列的值。
      Parameters:
      rowKey - the row key | 行键
      columnKey - the column key | 列键
      Returns:
      removed value, or null | 移除的值,或 null
    • rowKeySet

      Set<R> rowKeySet()
      Return a view of all row keys. 返回所有行键的视图。
      Returns:
      row key set | 行键集合
    • columnKeySet

      Set<C> columnKeySet()
      Return a view of all column keys. 返回所有列键的视图。
      Returns:
      column key set | 列键集合
    • values

      Collection<V> values()
      Return a view of all values. 返回所有值的视图。
      Returns:
      values collection | 值集合
    • cellSet

      Set<Table.Cell<R,C,V>> cellSet()
      Return a view of all cells. 返回所有单元格的视图。
      Returns:
      cell set | 单元格集合
    • row

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

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

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

      Map<C,Map<R,V>> columnMap()
      Return a map view of all columns. 返回所有列的映射视图。
      Returns:
      column key to row-value map | 列键到行值映射