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 ClassesModifier and TypeInterfaceDescriptionstatic interfaceTable.Cell<R,C, V> Cell - A row-column-value triple Cell - 行列值三元组 -
Method Summary
Modifier and TypeMethodDescriptionSet<Table.Cell<R, C, V>> cellSet()Return a view of all cells.voidclear()Clear all mappings.Return a map view for a specific column.Return a view of all column keys.Return a map view of all columns.booleanCheck if the table contains a mapping with the row and column keys.booleancontainsColumn(Object columnKey) Check if the table contains a mapping with the column key.booleancontainsRow(Object rowKey) Check if the table contains a mapping with the row key.booleancontainsValue(Object value) Check if the table contains a mapping with the value.Get the value at the specified row and column.booleanisEmpty()Check if the table contains any mappings.Put a value at the specified row and column.voidPut all values from another table.Remove the value at the specified row and column.Return a map view for a specific row.Return a view of all row keys.rowMap()Return a map view of all rows.intsize()Return the number of row-column-value mappings.values()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
-
containsRow
Check if the table contains a mapping with the row key. 检查表是否包含指定行键的映射。- Parameters:
rowKey- the row key | 行键- Returns:
- true if contains | 如果包含则返回 true
-
containsColumn
Check if the table contains a mapping with the column key. 检查表是否包含指定列键的映射。- Parameters:
columnKey- the column key | 列键- Returns:
- true if contains | 如果包含则返回 true
-
containsValue
Check if the table contains a mapping with the value. 检查表是否包含指定值的映射。- Parameters:
value- the value | 值- Returns:
- true if contains | 如果包含则返回 true
-
get
-
put
-
putAll
-
remove
-
rowKeySet
-
columnKeySet
-
values
-
cellSet
-
row
-
column
-
rowMap
-
columnMap
-