Class ArrayTable<R,C,V>  
- All Implemented Interfaces:
- Table<R, C, @Nullable V>,- Serializable
Table implementation backed by a two-dimensional array.
 Warning: ArrayTable is rarely the Table implementation you want. First,
 it requires that the complete universe of rows and columns be specified at construction time.
 Second, it is always backed by an array large enough to hold a value for every possible
 combination of row and column keys. (This is rarely optimal unless the table is extremely dense.)
 Finally, every possible combination of row and column keys is always considered to have a value
 associated with it: It is not possible to "remove" a value, only to replace it with null,
 which will still appear when iterating over the table's contents in a foreach loop or a call to a
 null-hostile method like ImmutableTable.copyOf(com.google.common.collect.Table<? extends R, ? extends C, ? extends V>). For alternatives, please see the wiki.
 
The allowed row and column keys must be supplied when the table is created. The table always contains a mapping for every row key / column pair. The value corresponding to a given row and column is null unless another value is provided.
The table's size is constant: the product of the number of supplied row keys and the number of
 supplied column keys. The remove and clear methods are not supported by the table
 or its views. The erase(java.lang.Object, java.lang.Object) and eraseAll() methods may be used instead.
 
The ordering of the row and column keys provided when the table is constructed determines the
 iteration ordering across rows and columns in the table's views. None of the view iterators
 support Iterator.remove(). If the table is modified after an iterator is created, the
 iterator remains valid.
 
This class requires less memory than the HashBasedTable and TreeBasedTable
 implementations, except when the table is sparse.
 
Null row keys or column keys are not permitted.
This class provides methods involving the underlying array structure, where the array indices
 correspond to the position of a row or column in the lists of allowed keys and values. See the
 at(int, int), set(int, int, V), toArray(java.lang.Class<V>), rowKeyList(), and columnKeyList()
 methods for more details.
 
Note that this implementation is not synchronized. If multiple threads access the same cell of
 an ArrayTable concurrently and one of the threads modifies its value, there is no
 guarantee that the new value will be fully visible to the other threads. To guarantee that
 modifications are visible, synchronize access to the table. Unlike other Table
 implementations, synchronization is unnecessary between a thread that writes to one cell and a
 thread that reads from another.
 
See the Guava User Guide article on Table.
- Since:
- 10.0
- Author:
- Jared Levy
- See Also:
- 
Nested Class Summary
- 
Method SummaryModifier and TypeMethodDescriptionat(int rowIndex, int columnIndex) Returns the value corresponding to the specified row and column indices.cellSet()Returns an unmodifiable set of all row key / column key / value triplets.voidclear()Deprecated.Returns a view of all mappings that have the given column key.Returns, as an immutable list, the column keys provided when the table was constructed, including those that are mapped to null values only.Returns an immutable set of the valid column keys, including those that are associated with null values only.Returns a view that associates each column key with the corresponding map from row keys to values.booleanReturnstrueif the provided keys are among the keys provided when the table was constructed.booleancontainsColumn(@Nullable Object columnKey) Returnstrueif the provided column key is among the column keys provided when the table was constructed.booleancontainsRow(@Nullable Object rowKey) Returnstrueif the provided row key is among the row keys provided when the table was constructed.booleancontainsValue(@Nullable Object value) Returnstrueif the table contains a mapping with the specified value.static <R,C, V> ArrayTable <R, C, V> Creates anArrayTablewith the mappings in the provided table.static <R,C, V> ArrayTable <R, C, V> Creates anArrayTablefilled withnull.booleanCompares the specified object with this table for equality.Associates the valuenullwith the specified keys, assuming both keys are valid.voideraseAll()Associates the valuenullwith every pair of allowed row and column keys.Returns the value corresponding to the given row and column keys, ornullif no such mapping exists.inthashCode()Returns the hash code for this table.booleanisEmpty()ReturnstrueifrowKeyList().size == 0orcolumnKeyList().size() == 0.Associates the specified value with the specified keys.voidCopies all mappings from the specified table to this table.Deprecated.Returns a view of all mappings that have the given row key.Returns, as an immutable list, the row keys provided when the table was constructed, including those that are mapped to null values only.Returns an immutable set of the valid row keys, including those that are associated with null values only.rowMap()Returns a view that associates each row key with the corresponding map from column keys to values.Associatesvaluewith the specified row and column indices.intsize()Returns the number of row key / column key / value mappings in the table.Returns a two-dimensional array with the table contents.toString()Returns the string representationrowMap().toString().values()Returns an unmodifiable collection of all values, which may contain duplicates.
- 
Method Details- 
createpublic static <R,C, ArrayTable<R,V> C, createV> (Iterable<? extends R> rowKeys, Iterable<? extends C> columnKeys) Creates anArrayTablefilled withnull.- Parameters:
- rowKeys- row keys that may be stored in the generated table
- columnKeys- column keys that may be stored in the generated table
- Throws:
- NullPointerException- if any of the provided keys is null
- IllegalArgumentException- if- rowKeysor- columnKeyscontains duplicates or if exactly one of- rowKeysor- columnKeysis empty.
 
- 
createCreates anArrayTablewith the mappings in the provided table.If tableincludes a mapping with row keyrand a separate mapping with column keyc, the returned table contains a mapping with row keyrand column keyc. If that row key / column key pair in not intable, the pair maps tonullin the generated table.The returned table allows subsequent putcalls with the row keys intable.rowKeySet()and the column keys intable.columnKeySet(). Callingput(R, C, V)with other keys leads to anIllegalArgumentException.The ordering of table.rowKeySet()andtable.columnKeySet()determines the row and column iteration ordering of the returned table.- Throws:
- NullPointerException- if- tablehas a null key
 
- 
rowKeyListReturns, as an immutable list, the row keys provided when the table was constructed, including those that are mapped to null values only.
- 
columnKeyListReturns, as an immutable list, the column keys provided when the table was constructed, including those that are mapped to null values only.
- 
atReturns the value corresponding to the specified row and column indices. The same value is returned byget(rowKeyList().get(rowIndex), columnKeyList().get(columnIndex)), but this method runs more quickly.- Parameters:
- rowIndex- position of the row key in- rowKeyList()
- columnIndex- position of the row key in- columnKeyList()
- Returns:
- the value with the specified row and column
- Throws:
- IndexOutOfBoundsException- if either index is negative,- rowIndexis greater than or equal to the number of allowed row keys, or- columnIndexis greater than or equal to the number of allowed column keys
 
- 
setAssociatesvaluewith the specified row and column indices. The logicput(rowKeyList().get(rowIndex), columnKeyList().get(columnIndex), value)has the same behavior, but this method runs more quickly.- Parameters:
- rowIndex- position of the row key in- rowKeyList()
- columnIndex- position of the row key in- columnKeyList()
- value- value to store in the table
- Returns:
- the previous value with the specified row and column
- Throws:
- IndexOutOfBoundsException- if either index is negative,- rowIndexis greater than or equal to the number of allowed row keys, or- columnIndexis greater than or equal to the number of allowed column keys
 
- 
toArrayReturns a two-dimensional array with the table contents. The row and column indices correspond to the positions of the row and column in the iterables provided during table construction. If the table lacks a mapping for a given row and column, the corresponding array element is null.Subsequent table changes will not modify the array, and vice versa. - Parameters:
- valueClass- class of values stored in the returned array
 
- 
clearDeprecated.UseeraseAll()Not supported. UseeraseAll()instead.
- 
eraseAllpublic void eraseAll()Associates the valuenullwith every pair of allowed row and column keys.
- 
containsReturnstrueif the provided keys are among the keys provided when the table was constructed.
- 
containsColumn
- 
containsRow
- 
containsValue
- 
getDescription copied from interface:TableReturns the value corresponding to the given row and column keys, ornullif no such mapping exists.
- 
isEmpty
- 
putAssociates the specified value with the specified keys. If the table already contained a mapping for those keys, the old value is replaced with the specified value.- Specified by:
- putin interface- Table<R,- C, - V> 
- Parameters:
- rowKey- row key that the value should be associated with
- columnKey- column key that the value should be associated with
- value- value to be associated with the specified keys
- Returns:
- the value previously associated with the keys, or nullif no mapping existed for the keys
- Throws:
- IllegalArgumentException- if- rowKeyis not in- rowKeySet()or- columnKeyis not in- columnKeySet().
 
- 
putAllCopies all mappings from the specified table to this table. The effect is equivalent to callingTable.put(R, C, V)with each row key / column key / value mapping intable.If tableis anArrayTable, its null values will be stored in this table, possibly replacing values that were previously non-null.- Specified by:
- putAllin interface- Table<R,- C, - V> 
- Parameters:
- table- the table to add to this table
- Throws:
- NullPointerException- if- tablehas a null key
- IllegalArgumentException- if any of the provided table's row keys or column keys is not in- rowKeySet()or- columnKeySet()
 
- 
remove@CanIgnoreReturnValue @Deprecated public @Nullable V remove(@Nullable Object rowKey, @Nullable Object columnKey) Deprecated.Not supported. Useerase(java.lang.Object, java.lang.Object)instead.
- 
eraseAssociates the valuenullwith the specified keys, assuming both keys are valid. If either key is null or isn't among the keys provided during construction, this method has no effect.This method is equivalent to put(rowKey, columnKey, null)when both provided keys are valid.- Parameters:
- rowKey- row key of mapping to be erased
- columnKey- column key of mapping to be erased
- Returns:
- the value previously associated with the keys, or nullif no mapping existed for the keys
 
- 
size
- 
cellSetReturns an unmodifiable set of all row key / column key / value triplets. Changes to the table will update the returned set.The returned set's iterator traverses the mappings with the first row key, the mappings with the second row key, and so on. The value in the returned cells may change if the table subsequently changes. 
- 
columnReturns a view of all mappings that have the given column key. If the column key isn't incolumnKeySet(), an empty immutable map is returned.Otherwise, for each row key in rowKeySet(), the returned map associates the row key with the corresponding value in the table. Changes to the returned map will update the underlying table, and vice versa.
- 
columnKeySetReturns an immutable set of the valid column keys, including those that are associated with null values only.- Specified by:
- columnKeySetin interface- Table<R,- C, - V> 
- Returns:
- immutable set of column keys
 
- 
columnMapDescription copied from interface:TableReturns a view that associates each column key with the corresponding map from row keys to values. Changes to the returned map will update this table. The returned map does not supportput()orputAll(), orsetValue()on its entries.In contrast, the maps returned by columnMap().get()have the same behavior as those returned byTable.column(C). Those maps may supportsetValue(),put(), andputAll().
- 
rowReturns a view of all mappings that have the given row key. If the row key isn't inrowKeySet(), an empty immutable map is returned.Otherwise, for each column key in columnKeySet(), the returned map associates the column key with the corresponding value in the table. Changes to the returned map will update the underlying table, and vice versa.
- 
rowKeySet
- 
rowMapDescription copied from interface:TableReturns a view that associates each row key with the corresponding map from column keys to values. Changes to the returned map will update this table. The returned map does not supportput()orputAll(), orsetValue()on its entries.In contrast, the maps returned by rowMap().get()have the same behavior as those returned byTable.row(R). Those maps may supportsetValue(),put(), andputAll().
- 
valuesReturns an unmodifiable collection of all values, which may contain duplicates. Changes to the table will update the returned collection.The returned collection's iterator traverses the values of the first row key, the values of the second row key, and so on. 
- 
equalsDescription copied from interface:TableCompares the specified object with this table for equality. Two tables are equal when their cell views, as returned byTable.cellSet(), are equal.
- 
hashCodepublic int hashCode()Description copied from interface:TableReturns the hash code for this table. The hash code of a table is defined as the hash code of its cell view, as returned byTable.cellSet().
- 
toString
 
- 
eraseAll()