Table whose row keys and column keys are ordered by their natural
ordering or by supplied comparators. When constructing a TreeBasedTable, you may provide
comparators for the row keys and the column keys, or you may use natural ordering for both.
The rowKeySet method returns a SortedSet and the rowMap method
returns a SortedMap, instead of the Set and Map specified by the Table interface.
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.
Because a TreeBasedTable has unique sorted values for a given row, both row(rowKey) and rowMap().get(rowKey) are SortedMap instances, instead of the
Map specified in the Table interface.
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.
See the Guava User Guide article on Table.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final Comparator | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Comparator | columnComparator()
Deprecated
Store the
Returns the comparator that orders the columns.
Comparator alongside the Table.
|
| public static <R extends Comparable | create()
Creates an empty |
| public static <R, C, V> TreeBasedTable | create(Comparator<? super R>
the comparator that orders the row keys rowComparator, Comparator<? super C> the comparator that orders the column keys columnComparator)Creates an empty |
| public static <R, C, V> TreeBasedTable | create(TreeBasedTable<R, C, ? extends V> table)
Creates a |
| pack-priv Iterator | createColumnKeyIterator()
Overrides com. |
| public SortedMap | row(R
key of row to search for in the table rowKey)Overrides com. Implements com. |
| public Comparator | rowComparator()
Deprecated
Use
Returns the comparator that orders the rows.
table.rowKeySet().comparator() instead.
|
| public SortedSet | rowKeySet()
Overrides com. Implements com. |
| public SortedMap | rowMap()
Overrides com. Implements com. |
| columnComparator | back to summary |
|---|---|
| private final Comparator<? super C> columnComparator | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides com. | |
| TreeBasedTable | back to summary |
|---|---|
| pack-priv TreeBasedTable(Comparator<? super R> rowComparator, Comparator<? super C> columnComparator) | |
| columnComparator | back to summary |
|---|---|
| public Comparator Deprecated Store the Returns the comparator that orders the columns. With natural ordering,
| |
| create | back to summary |
|---|---|
| public static <R extends Comparable Creates an empty The method signature specifies | |
| create | back to summary |
|---|---|
| public static <R, C, V> TreeBasedTable Creates an empty
| |
| create | back to summary |
|---|---|
| public static <R, C, V> TreeBasedTable Creates a | |
| createColumnKeyIterator | back to summary |
|---|---|
| pack-priv Iterator Overrides com. Overridden column iterator to return columns values in globally sorted order.
| |
| row | back to summary |
|---|---|
| public SortedMap Overrides com. Implements com. Doc from com. 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. Because a
| |
| rowComparator | back to summary |
|---|---|
| public Comparator Deprecated Use Returns the comparator that orders the rows. With natural ordering,
| |
| rowKeySet | back to summary |
|---|---|
| public SortedSet Overrides com. Implements com. Doc from com. 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. This method returns a This method returns a
| |
| rowMap | back to summary |
|---|---|
| public SortedMap Overrides com. Implements com. Doc from com. 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
In contrast, the maps returned by This method returns a This method returns a
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Comparator | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public TreeMap |
| comparator | back to summary |
|---|---|
| pack-priv final Comparator<? super C> comparator | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| Factory | back to summary |
|---|---|
| pack-priv Factory(Comparator<? super C> comparator) | |
| get | back to summary |
|---|---|
| public TreeMap Implements com. Doc from com. Retrieves an instance of the appropriate type. The returned object may or may not be a new instance, depending on the implementation. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final C | |
| pack-priv final C | |
| pack-priv transient SortedMap |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Comparator | comparator()
Implements java. null if this map uses the natural ordering of its keys.
|
| pack-priv int | |
| pack-priv SortedMap | |
| public boolean | containsKey(Object
key whose presence in this map is to be tested key)Overrides com. Implements java. true if this map contains a mapping for the specified
key.
|
| public C | firstKey()
Implements java. |
| public SortedMap | headMap(C
high endpoint (exclusive) of the keys in the returned map toKey)Implements java. toKey.
|
| public SortedSet | keySet()
Overrides java. Implements java. Set view of the keys contained in this map.
|
| public C | lastKey()
Implements java. |
| pack-priv void | |
| public V | put(C
key with which the specified value is to be associated key, V value to be associated with the specified key value)Overrides com. Implements java. |
| pack-priv boolean | |
| public SortedMap | subMap(C
low endpoint (inclusive) of the keys in the returned map fromKey, C high endpoint (exclusive) of the keys in the returned map toKey)Implements java. fromKey, inclusive, to toKey, exclusive.
|
| public SortedMap | tailMap(C
low endpoint (inclusive) of the keys in the returned map fromKey)Implements java. fromKey.
|
| pack-priv void |
| lowerBound | back to summary |
|---|---|
| pack-priv final C lowerBound
| |
| upperBound | back to summary |
|---|---|
| pack-priv final C upperBound
| |
| wholeRow | back to summary |
|---|---|
| pack-priv transient SortedMap<C, V> wholeRow
| |
| TreeRow | back to summary |
|---|---|
| pack-priv TreeRow(R rowKey) | |
| TreeRow | back to summary |
|---|---|
| pack-priv TreeRow(R rowKey, C lowerBound, C upperBound) | |
| comparator | back to summary |
|---|---|
| public Comparator Implements java. Doc from java. Returns the comparator used to order the keys in this map, or
| |
| compare | back to summary |
|---|---|
| pack-priv int compare(Object a, Object b) | |
| computeBackingRowMap | back to summary |
|---|---|
| pack-priv SortedMap Overrides com.
| |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(Object key) Overrides com. Implements java. Doc from java. Returns | |
| firstKey | back to summary |
|---|---|
| public C firstKey() Implements java. Doc from java. Returns the first (lowest) key currently in this map.
| |
| headMap | back to summary |
|---|---|
| public SortedMap Implements java. Doc from java. Returns a view of the portion of this map whose keys are
strictly less than The returned map will throw an | |
| keySet | back to summary |
|---|---|
| public SortedSet Overrides java. Implements java. Doc from java. Returns a | |
| lastKey | back to summary |
|---|---|
| public C lastKey() Implements java. Doc from java. Returns the last (highest) key currently in this map.
| |
| maintainEmptyInvariant | back to summary |
|---|---|
| pack-priv void maintainEmptyInvariant() Overrides com.
| |
| put | back to summary |
|---|---|
| public V put(C key, V value) Overrides com. Implements java. Doc from java. Associates the specified value with the specified key in this map
(optional operation). If the map previously contained a mapping for
the key, the old value is replaced by the specified value. (A map
| |
| rangeContains | back to summary |
|---|---|
| pack-priv boolean rangeContains(Object o) | |
| subMap | back to summary |
|---|---|
| public SortedMap Implements java. Doc from java. Returns a view of the portion of this map whose keys range from
The returned map will throw an | |
| tailMap | back to summary |
|---|---|
| public SortedMap Implements java. Doc from java. Returns a view of the portion of this map whose keys are
greater than or equal to The returned map will throw an | |
| updateWholeRowField | back to summary |
|---|---|
| pack-priv void updateWholeRowField() | |