public static final class ImmutableTable.Builder<R,C extends Object,V>
public static final tables ("constant tables"). Example:
static final ImmutableTable<Integer, Character, String> SPREADSHEET = new ImmutableTable.Builder<Integer, Character, String>() .put(1, 'A', "foo") .put(1, 'B', "bar") .put(2, 'A', "baz") .build();
By default, the order in which cells are added to the builder determines the iteration ordering of all views in the returned table, with putAll(com.google.common.collect.Table<? extends R, ? extends C, ? extends V>) following the Table iteration order. However, if orderRowsBy(java.util.Comparator<? super R>) or orderColumnsBy(java.util.Comparator<? super C>) is called, the views are sorted by the supplied comparators. For empty or single-cell immutable tables, ImmutableTable and ImmutableTable are even more convenient.
Builder instances can be reused - it is safe to call build() multiple times to build multiple tables in series. Each table is a superset of the tables created before it.
| Constructor and Description |
|---|
Builder()
Creates a new builder.
|
| Modifier and Type | Method and Description |
|---|---|
ImmutableTable |
build()
Returns a newly-created immutable table.
|
ImmutableTable |
orderColumnsBy(Comparator
Specifies the ordering of the generated table's columns.
|
ImmutableTable |
orderRowsBy(Comparator
Specifies the ordering of the generated table's rows.
|
ImmutableTable |
put(R rowKey, C columnKey, V value)
Associates the (
rowKey,
columnKey) pair with
value in the built table.
|
ImmutableTable |
put(Table
Adds the given
cell to the table, making it immutable if necessary.
|
ImmutableTable |
putAll(Table
Associates all of the given table's keys and values in the built table.
|
public Builder()
ImmutableTable.builder() .
public ImmutableTable.Builder <R ,C ,V> orderRowsBy(Comparator <? super R> rowComparator)
public ImmutableTable.Builder <R ,C ,V> orderColumnsBy(Comparator <? super C> columnComparator)
public ImmutableTable.Builder <R ,C ,V> put(R rowKey, C columnKey, V value)
rowKey,
columnKey) pair with
value in the built table. Duplicate key pairs are not allowed and will cause
build() to fail.
public ImmutableTable.Builder <R ,C ,V> put(Table .Cell <? extends R ,? extends C ,? extends V> cell)
cell to the table, making it immutable if necessary. Duplicate key pairs are not allowed and will cause
build() to fail.
public ImmutableTable.Builder <R ,C ,V> putAll(Table <? extends R ,? extends C ,? extends V> table)
build() to fail.
NullPointerException - if any key or value in
table is null
public ImmutableTable<R ,C ,V> build()
IllegalArgumentException - if duplicate key pairs were added