@GwtCompatible(serializable=true) public class HashBasedTable<R,C,V> extends StandardTable<R,C,V>
Table using linked hash tables. This guarantees predictable iteration
order of the various views.
The views returned by StandardTable.column(C), StandardTable.columnKeySet(), and StandardTable.columnMap() have iterators that don't support remove(). Otherwise,
all optional operations are supported. Null row keys, columns keys, and
values are not supported.
Lookups by row key are often faster than lookups by column key, because
the data is stored in a Map<R, Map<C, V>>. A method call like column(columnKey).get(rowKey) still runs quickly, since the row key is
provided. However, column(columnKey).size() takes longer, since an
iteration across all row keys occurs.
Note that this implementation is not synchronized. If multiple threads access this table concurrently and one of the threads modifies the table, it must be synchronized externally.
See the Guava User Guide article on
Table.
| Modifier and Type | Class and Description |
|---|---|
private static class |
HashBasedTable.Factory<C,V> |
StandardTable.Row, StandardTable.RowMapAbstractTable.CellSet, AbstractTable.ValuesTable.Cell<R,C,V>| Modifier and Type | Field and Description |
|---|---|
private static long |
serialVersionUID |
backingMap, factory| Constructor and Description |
|---|
HashBasedTable(java.util.Map<R,java.util.Map<C,V>> backingMap,
HashBasedTable.Factory<C,V> factory) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(java.lang.Object rowKey,
java.lang.Object columnKey)
Returns
true if the table contains a mapping with the specified
row and column keys. |
boolean |
containsColumn(java.lang.Object columnKey)
Returns
true if the table contains a mapping with the specified
column. |
boolean |
containsRow(java.lang.Object rowKey)
Returns
true if the table contains a mapping with the specified
row key. |
boolean |
containsValue(java.lang.Object value)
Returns
true if the table contains a mapping with the specified
value. |
static <R,C,V> HashBasedTable<R,C,V> |
create()
Creates an empty
HashBasedTable. |
static <R,C,V> HashBasedTable<R,C,V> |
create(int expectedRows,
int expectedCellsPerRow)
Creates an empty
HashBasedTable with the specified map sizes. |
static <R,C,V> HashBasedTable<R,C,V> |
create(Table<? extends R,? extends C,? extends V> table)
Creates a
HashBasedTable with the same mappings as the specified
table. |
boolean |
equals(java.lang.Object obj)
Compares the specified object with this table for equality.
|
V |
get(java.lang.Object rowKey,
java.lang.Object columnKey)
Returns the value corresponding to the given row and column keys, or
null if no such mapping exists. |
V |
remove(java.lang.Object rowKey,
java.lang.Object columnKey)
Removes the mapping, if any, associated with the given keys.
|
cellIterator, cellSet, clear, column, columnKeySet, columnMap, createColumnKeyIterator, createRowMap, isEmpty, put, row, rowKeySet, rowMap, size, valuescreateCellSet, createValues, hashCode, putAll, toString, valuesIteratorprivate static final long serialVersionUID
public static <R,C,V> HashBasedTable<R,C,V> create()
HashBasedTable.public static <R,C,V> HashBasedTable<R,C,V> create(int expectedRows, int expectedCellsPerRow)
HashBasedTable with the specified map sizes.expectedRows - the expected number of distinct row keysexpectedCellsPerRow - the expected number of column key / value
mappings in each rowjava.lang.IllegalArgumentException - if expectedRows or expectedCellsPerRow is negativepublic static <R,C,V> HashBasedTable<R,C,V> create(Table<? extends R,? extends C,? extends V> table)
HashBasedTable with the same mappings as the specified
table.table - the table to copyjava.lang.NullPointerException - if any of the row keys, column keys, or values
in table is nullpublic boolean contains(@Nullable
java.lang.Object rowKey,
@Nullable
java.lang.Object columnKey)
Tabletrue if the table contains a mapping with the specified
row and column keys.public boolean containsColumn(@Nullable
java.lang.Object columnKey)
Tabletrue if the table contains a mapping with the specified
column.containsColumn in interface Table<R,C,V>containsColumn in class StandardTable<R,C,V>columnKey - key of column to search forpublic boolean containsRow(@Nullable
java.lang.Object rowKey)
Tabletrue if the table contains a mapping with the specified
row key.containsRow in interface Table<R,C,V>containsRow in class StandardTable<R,C,V>rowKey - key of row to search forpublic boolean containsValue(@Nullable
java.lang.Object value)
Tabletrue if the table contains a mapping with the specified
value.containsValue in interface Table<R,C,V>containsValue in class StandardTable<R,C,V>value - value to search forpublic V get(@Nullable java.lang.Object rowKey, @Nullable java.lang.Object columnKey)
Tablenull if no such mapping exists.public boolean equals(@Nullable
java.lang.Object obj)
TableTable.cellSet(), are equal.