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. 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 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, set, toArray, 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.
| Modifier and Type | Class and Description |
|---|---|
| private abstract static class | |
| private class | |
| private class | |
| private class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final @Nullable V[][] | |
| private final ImmutableMap | |
| private final ImmutableList | |
| private transient ArrayTable | |
| private final ImmutableMap | |
| private final ImmutableList | |
| private transient ArrayTable | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| private | |
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public V | Returns: the value with the specified row and columnposition of the row key in rowIndex, int rowKeyList()position of the row key in columnIndex)columnKeyList()Returns the value corresponding to the specified row and column indices. |
| pack-priv Iterator | |
| public Set | Returns: set of table cells consisting of row key / column key / value tripletsOverrides com. Implements com. |
| pack-priv Spliterator | |
| public void | clear()
Overrides com. Implements com.
Deprecated
Use
Not supported.
eraseAll
|
| public Map | Returns: the corresponding map from row keys to valueskey of column to search for in the table columnKey)Implements com. |
| public ImmutableList | columnKeyList()
Returns, as an immutable list, the column keys provided when the table was constructed, including those that are mapped to null values only. |
| public ImmutableSet | Returns: immutable set of column keysOverrides com. Implements com. |
| public Map | columnMap()
Implements com. |
| public boolean | contains(Object
key of row to search for rowKey, Object key of column to search for columnKey)Overrides com. Implements com. true if the provided keys are among the keys provided when the table was
constructed.
|
| public boolean | containsColumn(Object
key of column to search for columnKey)Overrides com. Implements com. true if the provided column key is among the column keys provided when the
table was constructed.
|
| public boolean | containsRow(Object
key of row to search for rowKey)Overrides com. Implements com. true if the provided row key is among the row keys provided when the table was
constructed.
|
| public boolean | containsValue(Object
value to search for value)Overrides com. Implements com. true if the table contains a mapping with the specified value.
|
| public static <R, C, V> ArrayTable | |
| public static <R, C, V> ArrayTable | |
| public V | |
| public void | |
| public V | get(Object
key of row to search for rowKey, Object key of column to search for columnKey)Overrides com. Implements com. null if no such
mapping exists.
|
| private Table. | |
| private V | |
| public boolean | isEmpty()
Overrides com. Implements com. true if rowKeyList().size == 0 or columnKeyList().size() == 0.
|
| 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. Implements com. |
| public void | putAll(Table<? extends R, ? extends C, ? extends @Nullable V>
the table to add to this table table)Overrides com. Implements com. |
| public V | remove(Object
row key of mapping to be removed rowKey, Object column key of mapping to be removed columnKey)Overrides com. Implements com.
Deprecated
Use
Not supported.
erase
|
| public Map | Returns: the corresponding map from column keys to valueskey of row to search for in the table rowKey)Implements com. |
| public ImmutableList | rowKeyList()
Returns, as an immutable list, the row keys provided when the table was constructed, including those that are mapped to null values only. |
| public ImmutableSet | Returns: immutable set of row keysOverrides com. Implements com. |
| public Map | rowMap()
Implements com. |
| public V | Returns: the previous value with the specified row and columnposition of the row key in rowIndex, int rowKeyList()position of the row key in columnIndex, V columnKeyList()value to store in the table value)Associates |
| public int | size()
Implements com. |
| public @Nullable V[][] | |
| public Collection | Returns: collection of valuesOverrides com. Implements com. |
| pack-priv Iterator | |
| pack-priv Spliterator |