Class ImmutableTable<R,C,V>
java.lang.Object
cloud.opencode.base.collections.immutable.ImmutableTable<R,C,V>
- Type Parameters:
R- row key type | 行键类型C- column key type | 列键类型V- value type | 值类型
- All Implemented Interfaces:
Serializable
ImmutableTable - Immutable Table (Row-Column-Value) Implementation
ImmutableTable - 不可变表格(行-列-值)实现
A two-dimensional map-like data structure that uses row and column keys to store values. Cannot be modified after creation.
使用行和列键存储值的二维类映射数据结构。创建后不能修改。
Features | 主要功能:
- Immutable - 不可变
- Thread-safe - 线程安全
- Null-safe (nulls not allowed) - 空值安全(不允许空值)
- Two-dimensional structure - 二维结构
- O(1) cell access - O(1) 单元格访问
- Row and column views - 行和列视图
Usage Examples | 使用示例:
// Create table - 创建表格
ImmutableTable<String, String, Integer> table = ImmutableTable.<String, String, Integer>builder()
.put("row1", "col1", 1)
.put("row1", "col2", 2)
.put("row2", "col1", 3)
.put("row2", "col2", 4)
.build();
// Access cell - 访问单元格
Integer value = table.get("row1", "col1"); // Returns 1 - 返回 1
// Check existence - 检查存在性
boolean exists = table.contains("row1", "col1"); // Returns true - 返回 true
// Get row - 获取行
Map<String, Integer> row = table.row("row1"); // Returns {col1=1, col2=2}
// Get column - 获取列
Map<String, Integer> column = table.column("col1"); // Returns {row1=1, row2=3}
// Get all rows/columns - 获取所有行/列
Set<String> rowKeys = table.rowKeySet();
Set<String> columnKeys = table.columnKeySet();
Performance | 性能特性:
- get(row, column): O(1) - get(行, 列): O(1)
- contains: O(1) - contains: O(1)
- row/column: O(1) map lookup - row/column: O(1) 映射查找
- rowKeySet/columnKeySet: O(1) - rowKeySet/columnKeySet: O(1)
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Yes (nulls not allowed) - 空值安全: 是(不允许空值)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for ImmutableTable ImmutableTable 构建器static interfaceCell interface representing a table cell 表示表格单元格的单元格接口 -
Method Summary
Modifier and TypeMethodDescriptionstatic <R,C, V> ImmutableTable.Builder <R, C, V> builder()Return a new builder.cellSet()Return the set of all cells.Return the column map for the given column key.Return the set of all column keys.Return the map of all columns.booleanCheck if the table contains the given row and column.booleancontainsColumn(Object colKey) Check if the table contains the given column key.booleancontainsRow(Object rowKey) Check if the table contains the given row key.booleancontainsValue(Object value) Check if the table contains the given value.booleanReturn the value at the given row and column.inthashCode()booleanisEmpty()Check if the table is empty.static <R,C, V> ImmutableTable <R, C, V> of()Return an empty immutable table.static <R,C, V> ImmutableTable <R, C, V> of(R rowKey, C colKey, V value) Return an immutable table containing the given cell.Return the row map for the given row key.Return the set of all row keys.rowMap()Return the map of all rows.intsize()Return the number of cells in the table.toString()values()Return the collection of all values.
-
Method Details
-
of
Return an empty immutable table. 返回空不可变表格。- Type Parameters:
R- row key type | 行键类型C- column key type | 列键类型V- value type | 值类型- Returns:
- empty immutable table | 空不可变表格
-
of
Return an immutable table containing the given cell. 返回包含给定单元格的不可变表格。- Type Parameters:
R- row key type | 行键类型C- column key type | 列键类型V- value type | 值类型- Parameters:
rowKey- the row key | 行键colKey- the column key | 列键value- the value | 值- Returns:
- immutable table | 不可变表格
-
builder
Return a new builder. 返回新构建器。- Type Parameters:
R- row key type | 行键类型C- column key type | 列键类型V- value type | 值类型- Returns:
- builder | 构建器
-
get
-
contains
-
containsRow
Check if the table contains the given row key. 检查表格是否包含给定的行键。- Parameters:
rowKey- the row key | 行键- Returns:
- true if present | 如果存在则返回 true
-
containsColumn
Check if the table contains the given column key. 检查表格是否包含给定的列键。- Parameters:
colKey- the column key | 列键- Returns:
- true if present | 如果存在则返回 true
-
containsValue
Check if the table contains the given value. 检查表格是否包含给定的值。- Parameters:
value- the value | 值- Returns:
- true if present | 如果存在则返回 true
-
row
-
column
-
rowMap
-
columnMap
-
rowKeySet
-
columnKeySet
-
values
Return the collection of all values. 返回所有值的集合。- Returns:
- unmodifiable collection of values | 值的不可修改集合
-
cellSet
Return the set of all cells. 返回所有单元格的集合。- Returns:
- unmodifiable set of cells | 单元格的不可修改集合
-
size
public int size()Return the number of cells in the table. 返回表格中的单元格数。- Returns:
- the size | 大小
-
isEmpty
public boolean isEmpty()Check if the table is empty. 检查表格是否为空。- Returns:
- true if empty | 如果为空则返回 true
-
equals
-
hashCode
-
toString
-