Class HashBasedTable<R,C,V>
java.lang.Object
cloud.opencode.base.collections.HashBasedTable<R,C,V>
- Type Parameters:
R- row key type | 行键类型C- column key type | 列键类型V- value type | 值类型
- All Implemented Interfaces:
Table<R,C, V>, Serializable
HashBasedTable - Hash-based Table Implementation
HashBasedTable - 基于哈希的表实现
A Table implementation backed by nested HashMaps. Provides O(1) average time for most operations.
由嵌套 HashMap 支持的 Table 实现。大多数操作提供 O(1) 平均时间。
Features | 主要功能:
- O(1) average time operations - O(1) 平均时间操作
- Allows null values but not null keys - 允许空值但不允许空键
- Serializable - 可序列化
- Live views - 实时视图
Usage Examples | 使用示例:
// Create empty - 创建空
HashBasedTable<String, String, Integer> table = HashBasedTable.create();
// Create with expected size - 创建指定预期大小
HashBasedTable<String, String, Integer> table = HashBasedTable.create(10, 5);
// Create from existing - 从现有创建
HashBasedTable<String, String, Integer> table = HashBasedTable.create(existingTable);
// Operations - 操作
table.put("A", "X", 1);
table.put("A", "Y", 2);
table.put("B", "X", 3);
table.get("A", "X"); // 1
table.row("A"); // {X=1, Y=2}
table.column("X"); // {A=1, B=3}
Performance | 性能特性:
- get/put/remove: O(1) average - get/put/remove: O(1) 平均
- contains: O(1) average - contains: O(1) 平均
- row: O(1) - row: O(1)
- column: O(n) first access, O(1) cached - column: O(n) 首次访问, O(1) 缓存
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: Values yes, keys no - 空值安全: 值是,键否
- 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 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.static <R,C, V> HashBasedTable <R, C, V> create()Create an empty HashBasedTable.static <R,C, V> HashBasedTable <R, C, V> create(int expectedRows, int expectedColumns) Create an empty HashBasedTable with expected sizes.static <R,C, V> HashBasedTable <R, C, V> Create a HashBasedTable from an existing table.booleanGet the value at the specified row and column.inthashCode()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.toString()values()Return a view of all values.
-
Method Details
-
create
Create an empty HashBasedTable. 创建空 HashBasedTable。- Type Parameters:
R- row key type | 行键类型C- column key type | 列键类型V- value type | 值类型- Returns:
- new HashBasedTable | 新的 HashBasedTable
-
create
Create an empty HashBasedTable with expected sizes. 创建指定预期大小的空 HashBasedTable。- Type Parameters:
R- row key type | 行键类型C- column key type | 列键类型V- value type | 值类型- Parameters:
expectedRows- expected row count | 预期行数expectedColumns- expected column count | 预期列数- Returns:
- new HashBasedTable | 新的 HashBasedTable
-
create
public static <R,C, HashBasedTable<R,V> C, createV> (Table<? extends R, ? extends C, ? extends V> table) Create a HashBasedTable from an existing table. 从现有表创建 HashBasedTable。- Type Parameters:
R- row key type | 行键类型C- column key type | 列键类型V- value type | 值类型- Parameters:
table- source table | 源表- Returns:
- new HashBasedTable | 新的 HashBasedTable
-
isEmpty
-
size
-
clear
-
contains
Description copied from interface:TableCheck if the table contains a mapping with the row and column keys. 检查表是否包含指定行列键的映射。 -
containsRow
-
containsColumn
-
containsValue
-
get
-
put
Description copied from interface:TablePut a value at the specified row and column. 在指定行列放入值。 -
putAll
-
remove
Description copied from interface:TableRemove the value at the specified row and column. 移除指定行列的值。 -
rowKeySet
-
columnKeySet
-
values
-
cellSet
-
row
-
column
-
rowMap
-
columnMap
-
equals
-
hashCode
-
toString
-