Class ArrayTable<R,C,V>

java.lang.Object
cloud.opencode.base.collections.specialized.ArrayTable<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 ArrayTable<R,C,V> extends Object implements Table<R,C,V>, Serializable
ArrayTable - Fixed-size Array-based Table Implementation ArrayTable - 固定大小基于数组的表实现

A table implementation using a 2D array with fixed row and column keys.

使用具有固定行和列键的二维数组的表实现。

Features | 主要功能:

  • Fixed dimensions - 固定维度
  • O(1) access - O(1) 访问
  • Dense storage - 密集存储
  • Allows null values - 允许空值

Usage Examples | 使用示例:

ArrayTable<String, String, Integer> table = ArrayTable.create(
    Arrays.asList("row1", "row2"),
    Arrays.asList("col1", "col2"));

table.put("row1", "col1", 1);
table.put("row1", "col2", 2);

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

// Direct array access
Integer[][] array = table.toArray();

Performance | 性能特性:

  • get: O(1) - get: O(1)
  • put: O(1) - put: O(1)
  • containsRow/Column: O(1) - containsRow/Column: O(1)

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
  • Null-safe: Values can be null - 空值安全: 值可以为 null
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface Table

    Table.Cell<R,C,V>
  • Method Summary

    Modifier and Type
    Method
    Description
    at(int rowIndex, int columnIndex)
    Return the value at the given indices.
    Return a view of all cells.
    void
    Clear all mappings.
    column(C columnKey)
    Return a map view for a specific column.
    Return all column keys in order.
    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.
    static <R,C,V> ArrayTable<R,C,V>
    create(Table<R,C,V> table)
    Create an ArrayTable copying from another table.
    static <R,C,V> ArrayTable<R,C,V>
    create(Iterable<? extends R> rowKeys, Iterable<? extends C> columnKeys)
    Create an ArrayTable with the specified row and column keys.
    boolean
     
    erase(int rowIndex, int columnIndex)
    Erase the value at the given indices.
    get(Object rowKey, Object columnKey)
    Get the value at the specified row and column.
    int
     
    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 all row keys in order.
    Return a view of all row keys.
    Map<R,Map<C,V>>
    Return a map view of all rows.
    set(int rowIndex, int columnIndex, V value)
    Set the value at the given indices.
    int
    Return the number of row-column-value mappings.
    V[][]
    toArray(V[][] array)
    Return the values as a 2D array.
     
    Return a view of all values.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • create

      public static <R,C,V> ArrayTable<R,C,V> create(Iterable<? extends R> rowKeys, Iterable<? extends C> columnKeys)
      Create an ArrayTable with the specified row and column keys. 使用指定的行和列键创建 ArrayTable。
      Type Parameters:
      R - row key type | 行键类型
      C - column key type | 列键类型
      V - value type | 值类型
      Parameters:
      rowKeys - the row keys | 行键
      columnKeys - the column keys | 列键
      Returns:
      new ArrayTable | 新 ArrayTable
    • create

      public static <R,C,V> ArrayTable<R,C,V> create(Table<R,C,V> table)
      Create an ArrayTable copying from another table. 从另一个表复制创建 ArrayTable。
      Type Parameters:
      R - row key type | 行键类型
      C - column key type | 列键类型
      V - value type | 值类型
      Parameters:
      table - the table to copy | 要复制的表
      Returns:
      new ArrayTable | 新 ArrayTable
    • 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>
    • rowKeyList

      public List<R> rowKeyList()
      Return all row keys in order. 按顺序返回所有行键。
      Returns:
      the row keys | 行键
    • columnKeyList

      public List<C> columnKeyList()
      Return all column keys in order. 按顺序返回所有列键。
      Returns:
      the column keys | 列键
    • at

      public V at(int rowIndex, int columnIndex)
      Return the value at the given indices. 返回给定索引处的值。
      Parameters:
      rowIndex - the row index | 行索引
      columnIndex - the column index | 列索引
      Returns:
      the value | 值
    • set

      public V set(int rowIndex, int columnIndex, V value)
      Set the value at the given indices. 设置给定索引处的值。
      Parameters:
      rowIndex - the row index | 行索引
      columnIndex - the column index | 列索引
      value - the value | 值
      Returns:
      the old value | 旧值
    • erase

      public V erase(int rowIndex, int columnIndex)
      Erase the value at the given indices. 擦除给定索引处的值。
      Parameters:
      rowIndex - the row index | 行索引
      columnIndex - the column index | 列索引
      Returns:
      the old value | 旧值
    • toArray

      public V[][] toArray(V[][] array)
      Return the values as a 2D array. 以二维数组形式返回值。
      Parameters:
      array - the array to fill | 要填充的数组
      Returns:
      the filled array | 填充后的数组
    • 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