Top Description Inners Fields Constructors Methods
com.google.common.collect

public Class HashBasedTable<R, C, V>

extends StandardTable<R, C, V>
Class Inheritance
Annotations
@GwtCompatible
serializable:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.collect.CollectPreconditions.checkNonnegative

Implementation of Table using linked hash tables. This guarantees predictable iteration order of the various views.

The views returned by column, columnKeySet(), and 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.

Author
Jared Levy
Since
7.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.google.common.collect.StandardTable:
backingMapfactory

Constructor Summary

AccessConstructor and Description
pack-priv
HashBasedTable(Map<R, Map<C, V>> backingMap, HashBasedTable.Factory<C, V> factory)

Method Summary

Modifier and TypeMethod and Description
public static <R, C, V> HashBasedTable<R, C, V>
create()

Creates an empty HashBasedTable.

public static <R, C, V> HashBasedTable<R, C, V>
create(int
the expected number of distinct row keys
expectedRows
,
int
the expected number of column key / value mappings in each row
expectedCellsPerRow
)

Creates an empty HashBasedTable with the specified map sizes.

public static <R, C, V> HashBasedTable<R, C, V>
create(Table<? extends R, ? extends C, ? extends V>
the table to copy
table
)

Creates a HashBasedTable with the same mappings as the specified table.

Inherited from com.google.common.collect.StandardTable:
cellIteratorcellSetcellSpliteratorclearcolumncolumnKeySetcolumnMapcontainscontainsColumncontainsRowcontainsValuecreateColumnKeyIteratorcreateRowMapgetisEmptyputremoverowrowKeySetrowMapsizevalues

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.google.common.collect.StandardTable.serialVersionUID.

Constructor Detail

HashBasedTableback to summary
pack-priv HashBasedTable(Map<R, Map<C, V>> backingMap, HashBasedTable.Factory<C, V> factory)

Method Detail

createback to summary
public static <R, C, V> HashBasedTable<R, C, V> create()

Creates an empty HashBasedTable.

createback to summary
public static <R, C, V> HashBasedTable<R, C, V> create(int expectedRows, int expectedCellsPerRow)

Creates an empty HashBasedTable with the specified map sizes.

Parameters
expectedRows:int

the expected number of distinct row keys

expectedCellsPerRow:int

the expected number of column key / value mappings in each row

Exceptions
IllegalArgumentException:
if expectedRows or expectedCellsPerRow is negative
createback to summary
public 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.

Parameters
table:Table<? extends R, ? extends C, ? extends V>

the table to copy

Exceptions
NullPointerException:
if any of the row keys, column keys, or values in table is null
com.google.common.collect back to summary

private Class HashBasedTable.Factory<C, V>

extends Object
implements Supplier<Map<C, V>>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.google.common.base.Supplier, java.util.function.Supplier

Field Summary

Modifier and TypeField and Description
pack-priv final int
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
Factory(int expectedSize)

Method Summary

Modifier and TypeMethod and Description
public Map<C, V>
get()

Implements com.google.common.base.Supplier.get.

Retrieves an instance of the appropriate type.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

expectedSizeback to summary
pack-priv final int expectedSize
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

Factoryback to summary
pack-priv Factory(int expectedSize)

Method Detail

getback to summary
public Map<C, V> get()

Implements com.google.common.base.Supplier.get.

Doc from com.google.common.base.Supplier.get.

Retrieves an instance of the appropriate type. The returned object may or may not be a new instance, depending on the implementation.

Returns:Map<C, V>

an instance of the appropriate type

Annotations
@Override