@GwtCompatible public abstract class ImmutableTable<R,C,V> extends Object
A Table
whose contents will never change, with many other important properties detailed at ImmutableCollection
.
See the Guava User Guide article on immutable collections.
Modifier and Type | Class and Description |
---|---|
static class |
ImmutableTable.Builder<R,C,V>
A builder for creating immutable table instances, especially
public
static final tables (“constant tables”). |
Table.Cell<R,C,V>
Modifier and Type | Method and Description |
---|---|
static <R,C,V> ImmutableTable.Builder<R,C,V> |
builder()
Returns a new builder.
|
static <R,C,V> ImmutableTable.Builder<R,C,V> |
builder(int initialCapacity)
Returns a new builder with the given initial capacity.
|
ImmutableSet<Table.Cell<R,C,V>> |
cellSet()
Returns a set of all row key / column key / value triplets.
|
void |
clear()
Deprecated.
Unsupported operation.
|
ImmutableMap<R,V> |
column(C columnKey)
Returns a view of all mappings that have the given column key.
|
ImmutableSet<C> |
columnKeySet()
Returns a set of column keys that have one or more values in the table.
|
abstract ImmutableMap<C,Map<R,V>> |
columnMap()
Returns a view that associates each column key with the corresponding map from row keys to values.
|
boolean |
contains(Object rowKey,
Object columnKey)
Returns
true if the table contains a mapping with the specified row and column keys. |
boolean |
containsColumn(Object columnKey)
Returns
true if the table contains a mapping with the specified column. |
boolean |
containsRow(Object rowKey)
Returns
true if the table contains a mapping with the specified row key. |
boolean |
containsValue(Object value)
Returns
true if the table contains a mapping with the specified value. |
static <R,C,V> ImmutableTable<R,C,V> |
copyOf(Table<? extends R,? extends C,? extends V> table)
Returns an immutable copy of the provided table.
|
boolean |
equals(Object obj)
Compares the specified object with this table for equality.
|
V |
get(Object rowKey,
Object columnKey)
Returns the value corresponding to the given row and column keys, or
null if no such mapping exists. |
int |
hashCode()
Returns the hash code for this table.
|
boolean |
isEmpty()
Returns
true if the table contains no mappings. |
static <R,C,V> ImmutableTable<R,C,V> |
of()
Returns an empty immutable table.
|
static <R,C,V> ImmutableTable<R,C,V> |
of(R rowKey,
C columnKey,
V value)
Returns an immutable table containing a single cell.
|
V |
put(R rowKey,
C columnKey,
V value)
Deprecated.
Unsupported operation.
|
void |
putAll(Table<? extends R,? extends C,? extends V> table)
Deprecated.
Unsupported operation.
|
V |
remove(Object rowKey,
Object columnKey)
Deprecated.
Unsupported operation.
|
ImmutableMap<C,V> |
row(R rowKey)
Returns a view of all mappings that have the given row key.
|
ImmutableSet<R> |
rowKeySet()
Returns a set of row keys that have one or more values in the table.
|
abstract ImmutableMap<R,Map<C,V>> |
rowMap()
Returns a view that associates each row key with the corresponding map from column keys to values.
|
String |
toString()
Returns the string representation
rowMap().toString() . |
ImmutableCollection<V> |
values()
Returns a collection of all values, which may contain duplicates.
|
public static <R,C,V> ImmutableTable<R,C,V> of()
Returns an empty immutable table.
public static <R,C,V> ImmutableTable<R,C,V> of(R rowKey, C columnKey, V value)
Returns an immutable table containing a single cell.
public static <R,C,V> ImmutableTable<R,C,V> copyOf(Table<? extends R,? extends C,? extends V> table)
Returns an immutable copy of the provided table.
The Table.cellSet()
iteration order of the provided table determines the iteration ordering of all views in the returned table. Note that some views of the original table and the copied table may have different iteration orders. For more control over the ordering, create a ImmutableTable.Builder
and call ImmutableTable.Builder.orderRowsBy(java.util.Comparator<? super R>)
, ImmutableTable.Builder.orderColumnsBy(java.util.Comparator<? super C>)
, and ImmutableTable.Builder.putAll(com.diffplug.common.collect.Table<? extends R, ? extends C, ? extends V>)
Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
public static <R,C,V> ImmutableTable.Builder<R,C,V> builder()
Returns a new builder. The generated builder is equivalent to the builder created by the Builder#Builder()
constructor.
public static <R,C,V> ImmutableTable.Builder<R,C,V> builder(int initialCapacity)
Returns a new builder with the given initial capacity. The generated builder is equivalent to the builder created by the Builder#Builder(int)
constructor.
public ImmutableSet<Table.Cell<R,C,V>> cellSet()
Table
Returns a set of all row key / column key / value triplets. Changes to the returned set will update the underlying table, and vice versa. The cell set does not support the add
or addAll
methods.
public ImmutableCollection<V> values()
Table
Returns a collection of all values, which may contain duplicates. Changes to the returned collection will update the underlying table, and vice versa.
public ImmutableMap<R,V> column(C columnKey)
Returns a view of all mappings that have the given column key. For each row key / column key / value mapping in the table with that column key, the returned map associates the row key with the value. If no mappings in the table have the provided column key, an empty map is returned.
Changes to the returned map will update the underlying table, and vice versa.
columnKey
- key of column to search for in the tableNullPointerException
- if columnKey
is null
public ImmutableSet<C> columnKeySet()
Table
Returns a set of column keys that have one or more values in the table. Changes to the set will update the underlying table, and vice versa.
columnKeySet
in interface Table<R,C,V>
public abstract ImmutableMap<C,Map<R,V>> columnMap()
Returns 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 support put()
or putAll()
, or setValue()
on its entries.
In contrast, the maps returned by columnMap().get()
have the same behavior as those returned by Table.column(C)
. Those maps may support setValue()
, put()
, and putAll()
.
The value Map<R, V>
instances in the returned map are ImmutableMap
instances as well.
public ImmutableMap<C,V> row(R rowKey)
Returns a view of all mappings that have the given row key. For each row key / column key / value mapping in the table with that row key, the returned map associates the column key with the value. If no mappings in the table have the provided row key, an empty map is returned.
Changes to the returned map will update the underlying table, and vice versa.
rowKey
- key of row to search for in the tableNullPointerException
- if rowKey
is null
public ImmutableSet<R> rowKeySet()
Table
Returns a set of row keys that have one or more values in the table. Changes to the set will update the underlying table, and vice versa.
public abstract ImmutableMap<R,Map<C,V>> rowMap()
Returns 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 support put()
or putAll()
, or setValue()
on its entries.
In contrast, the maps returned by rowMap().get()
have the same behavior as those returned by Table.row(R)
. Those maps may support setValue()
, put()
, and putAll()
.
The value Map<C, V>
instances in the returned map are ImmutableMap
instances as well.
public boolean contains(@Nullable Object rowKey, @Nullable Object columnKey)
Table
Returns true
if the table contains a mapping with the specified row and column keys.
public boolean containsValue(@Nullable Object value)
Table
Returns true
if the table contains a mapping with the specified value.
containsValue
in interface Table<R,C,V>
value
- value to search for@Deprecated public final void clear()
Guaranteed to throw an exception and leave the table unmodified.
@Deprecated public final V put(R rowKey, C columnKey, V value)
Guaranteed to throw an exception and leave the table unmodified.
put
in interface Table<R,C,V>
rowKey
- row key that the value should be associated withcolumnKey
- column key that the value should be associated withvalue
- value to be associated with the specified keysnull
if no mapping existed for the keysUnsupportedOperationException
- always@Deprecated public final void putAll(Table<? extends R,? extends C,? extends V> table)
Guaranteed to throw an exception and leave the table unmodified.
@Deprecated public final V remove(Object rowKey, Object columnKey)
Guaranteed to throw an exception and leave the table unmodified.
public boolean containsRow(@Nullable Object rowKey)
Table
Returns true
if the table contains a mapping with the specified row key.
containsRow
in interface Table<R,C,V>
rowKey
- key of row to search forpublic boolean containsColumn(@Nullable Object columnKey)
Table
Returns true
if the table contains a mapping with the specified column.
containsColumn
in interface Table<R,C,V>
columnKey
- key of column to search forpublic V get(@Nullable Object rowKey, @Nullable Object columnKey)
Table
Returns the value corresponding to the given row and column keys, or null
if no such mapping exists.
public boolean isEmpty()
Table
Returns true
if the table contains no mappings.
public boolean equals(@Nullable Object obj)
Table
Compares the specified object with this table for equality. Two tables are equal when their cell views, as returned by Table.cellSet()
, are equal.
public int hashCode()
Table
Returns the hash code for this table. The hash code of a table is defined as the hash code of its cell view, as returned by Table.cellSet()
.