Class HashBasedTable<R,C,V>
- java.lang.Object
-
- com.google.common.collect.AbstractTable<R,C,V>
-
- com.google.common.collect.StandardTable<R,C,V>
-
- com.google.common.collect.HashBasedTable<R,C,V>
-
- All Implemented Interfaces:
Table<R,C,V>
,java.io.Serializable
public class HashBasedTable<R,C,V> extends StandardTable<R,C,V>
Implementation ofTable
using linked hash tables. This guarantees predictable iteration order of the various views.The views returned by
StandardTable.column(C)
,StandardTable.columnKeySet()
, andStandardTable.columnMap()
have iterators that don't supportremove()
. 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 likecolumn(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
.- Since:
- 7.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
HashBasedTable.Factory<C,V>
-
Nested classes/interfaces inherited from class com.google.common.collect.StandardTable
StandardTable.Row, StandardTable.RowMap
-
Nested classes/interfaces inherited from class com.google.common.collect.AbstractTable
AbstractTable.CellSet, AbstractTable.Values
-
Nested classes/interfaces inherited from interface com.google.common.collect.Table
Table.Cell<R,C,V>
-
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
-
Fields inherited from class com.google.common.collect.StandardTable
backingMap, factory
-
-
Constructor Summary
Constructors Constructor Description HashBasedTable(java.util.Map<R,java.util.Map<C,V>> backingMap, HashBasedTable.Factory<C,V> factory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(java.lang.Object rowKey, java.lang.Object columnKey)
Returnstrue
if the table contains a mapping with the specified row and column keys.boolean
containsColumn(java.lang.Object columnKey)
Returnstrue
if the table contains a mapping with the specified column.boolean
containsRow(java.lang.Object rowKey)
Returnstrue
if the table contains a mapping with the specified row key.boolean
containsValue(java.lang.Object value)
Returnstrue
if the table contains a mapping with the specified value.static <R,C,V>
HashBasedTable<R,C,V>create()
Creates an emptyHashBasedTable
.static <R,C,V>
HashBasedTable<R,C,V>create(int expectedRows, int expectedCellsPerRow)
Creates an emptyHashBasedTable
with the specified map sizes.static <R,C,V>
HashBasedTable<R,C,V>create(Table<? extends R,? extends C,? extends V> table)
Creates aHashBasedTable
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, ornull
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.-
Methods inherited from class com.google.common.collect.StandardTable
cellIterator, cellSet, cellSpliterator, clear, column, columnKeySet, columnMap, createColumnKeyIterator, createRowMap, isEmpty, put, row, rowKeySet, rowMap, size, values
-
Methods inherited from class com.google.common.collect.AbstractTable
createCellSet, createValues, hashCode, putAll, toString, valuesIterator, valuesSpliterator
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static <R,C,V> HashBasedTable<R,C,V> create()
Creates an emptyHashBasedTable
.
-
create
public static <R,C,V> HashBasedTable<R,C,V> create(int expectedRows, int expectedCellsPerRow)
Creates an emptyHashBasedTable
with the specified map sizes.- Parameters:
expectedRows
- the expected number of distinct row keysexpectedCellsPerRow
- the expected number of column key / value mappings in each row- Throws:
java.lang.IllegalArgumentException
- ifexpectedRows
orexpectedCellsPerRow
is negative
-
create
public static <R,C,V> HashBasedTable<R,C,V> create(Table<? extends R,? extends C,? extends V> table)
Creates aHashBasedTable
with the same mappings as the specified table.- Parameters:
table
- the table to copy- Throws:
java.lang.NullPointerException
- if any of the row keys, column keys, or values intable
is null
-
contains
public boolean contains(java.lang.Object rowKey, java.lang.Object columnKey)
Description copied from interface:Table
Returnstrue
if the table contains a mapping with the specified row and column keys.
-
containsColumn
public boolean containsColumn(java.lang.Object columnKey)
Description copied from interface:Table
Returnstrue
if the table contains a mapping with the specified column.- Specified by:
containsColumn
in interfaceTable<R,C,V>
- Overrides:
containsColumn
in classStandardTable<R,C,V>
- Parameters:
columnKey
- key of column to search for
-
containsRow
public boolean containsRow(java.lang.Object rowKey)
Description copied from interface:Table
Returnstrue
if the table contains a mapping with the specified row key.- Specified by:
containsRow
in interfaceTable<R,C,V>
- Overrides:
containsRow
in classStandardTable<R,C,V>
- Parameters:
rowKey
- key of row to search for
-
containsValue
public boolean containsValue(java.lang.Object value)
Description copied from interface:Table
Returnstrue
if the table contains a mapping with the specified value.- Specified by:
containsValue
in interfaceTable<R,C,V>
- Overrides:
containsValue
in classStandardTable<R,C,V>
- Parameters:
value
- value to search for
-
get
public V get(java.lang.Object rowKey, java.lang.Object columnKey)
Description copied from interface:Table
Returns the value corresponding to the given row and column keys, ornull
if no such mapping exists.
-
equals
public boolean equals(java.lang.Object obj)
Description copied from interface:Table
Compares the specified object with this table for equality. Two tables are equal when their cell views, as returned byTable.cellSet()
, are equal.
-
-