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

pack-priv Class StandardTable<R, C, V>

extends AbstractTable<R, C, V>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
com.google.common.collect.HashBasedTable, com.google.common.collect.StandardRowSortedTable
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, .Predicates.alwaysTrue, .Predicates.equalTo, .Predicates.in, .Predicates.not, com.google.common.collect.Maps.safeContainsKey, .Maps.safeGet, .NullnessCasts.uncheckedCastNullableTToT, java.util.Objects.requireNonNull

Table implementation backed by a map that associates row keys with column key / value secondary maps. This class provides rapid access to records by the row key alone or by both keys, but not by just the column key.

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.

Author
Jared Levy

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private class
private class
private class
pack-priv class
pack-priv class
private abstract class
StandardTable.TableSet<T>

Abstract set whose isEmpty() returns whether the table is empty and whose clear() clears all table mappings.

Field Summary

Modifier and TypeField and Description
pack-priv final Map<R, Map<C, V>>
private transient Set<C>
private transient StandardTable<R, C, V>.ColumnMap
pack-priv final Supplier<? extends Map<C, V>>
private transient Map<R, Map<C, V>>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
StandardTable(Map<R, Map<C, V>> backingMap, Supplier<? extends Map<C, V>> factory)

Method Summary

Modifier and TypeMethod and Description
pack-priv Iterator<Table.Cell<R, C, V>>
public Set<Table.Cell<R, C, V>>
cellSet()

Overrides com.google.common.collect.AbstractTable.cellSet.

Implements com.google.common.collect.Table.cellSet.

Returns a set of all row key / column key / value triplets.
pack-priv Spliterator<Table.Cell<R, C, V>>
public void
clear()

Overrides com.google.common.collect.AbstractTable.clear.

Implements com.google.common.collect.Table.clear.

Removes all mappings from the table.
public Map<R, V>
column(C
key of column to search for in the table
columnKey
)

Implements com.google.common.collect.Table.column.

Returns a view of all mappings that have the given column key.
public Set<C>
columnKeySet()

Overrides com.google.common.collect.AbstractTable.columnKeySet.

Implements com.google.common.collect.Table.columnKeySet.

Returns a set of column keys that have one or more values in the table.
public Map<C, Map<R, V>>
columnMap()

Implements com.google.common.collect.Table.columnMap.

Returns a view that associates each column key with the corresponding map from row keys to values.
public boolean
contains(Object
key of row to search for
rowKey
,
Object
key of column to search for
columnKey
)

Overrides com.google.common.collect.AbstractTable.contains.

Implements com.google.common.collect.Table.contains.

Returns true if the table contains a mapping with the specified row and column keys.
public boolean
containsColumn(Object
key of column to search for
columnKey
)

Overrides com.google.common.collect.AbstractTable.containsColumn.

Implements com.google.common.collect.Table.containsColumn.

Returns true if the table contains a mapping with the specified column.
private boolean
containsMapping(Object rowKey, Object columnKey, Object value)

public boolean
containsRow(Object
key of row to search for
rowKey
)

Overrides com.google.common.collect.AbstractTable.containsRow.

Implements com.google.common.collect.Table.containsRow.

Returns true if the table contains a mapping with the specified row key.
public boolean
containsValue(Object
value to search for
value
)

Overrides com.google.common.collect.AbstractTable.containsValue.

Implements com.google.common.collect.Table.containsValue.

Returns true if the table contains a mapping with the specified value.
pack-priv Iterator<C>
createColumnKeyIterator()

Creates an iterator that returns each column value with duplicates omitted.

pack-priv Map<R, Map<C, V>>
public V
get(Object
key of row to search for
rowKey
,
Object
key of column to search for
columnKey
)

Overrides com.google.common.collect.AbstractTable.get.

Implements com.google.common.collect.Table.get.

Returns the value corresponding to the given row and column keys, or null if no such mapping exists.
private Map<C, V>
getOrCreate(R rowKey)

public boolean
isEmpty()

Overrides com.google.common.collect.AbstractTable.isEmpty.

Implements com.google.common.collect.Table.isEmpty.

Returns true if the table contains no mappings.
public V
put(R
row key that the value should be associated with
rowKey
,
C
column key that the value should be associated with
columnKey
,
V
value to be associated with the specified keys
value
)

Overrides com.google.common.collect.AbstractTable.put.

Implements com.google.common.collect.Table.put.

Associates the specified value with the specified keys.
public V
remove(Object
row key of mapping to be removed
rowKey
,
Object
column key of mapping to be removed
columnKey
)

Overrides com.google.common.collect.AbstractTable.remove.

Implements com.google.common.collect.Table.remove.

Removes the mapping, if any, associated with the given keys.
private Map<R, V>
private boolean
removeMapping(Object rowKey, Object columnKey, Object value)

Remove a row key / column key / value mapping, if present.

public Map<C, V>
row(R
key of row to search for in the table
rowKey
)

Implements com.google.common.collect.Table.row.

Returns a view of all mappings that have the given row key.
public Set<R>
rowKeySet()

Overrides com.google.common.collect.AbstractTable.rowKeySet.

Implements com.google.common.collect.Table.rowKeySet.

Returns a set of row keys that have one or more values in the table.
public Map<R, Map<C, V>>
rowMap()

Implements com.google.common.collect.Table.rowMap.

Returns a view that associates each row key with the corresponding map from column keys to values.
public int
size()

Implements com.google.common.collect.Table.size.

Returns the number of row key / column key / value mappings in the table.
public Collection<V>
values()

Overrides com.google.common.collect.AbstractTable.values.

Implements com.google.common.collect.Table.values.

Returns a collection of all values, which may contain duplicates.
Inherited from com.google.common.collect.AbstractTable:
createCellSetcreateValuesequalshashCodeputAlltoStringvaluesIteratorvaluesSpliterator