@GwtCompatible(serializable=true) public class TreeBasedTable<R,C,V> extends StandardRowSortedTable<R,C,V>
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 StandardTable.column(C), StandardTable.columnKeySet(), and StandardTable.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 |
TreeBasedTable.Factory<C,V> |
private class |
TreeBasedTable.TreeRow |
StandardTable.Row, StandardTable.RowMapAbstractTable.CellSet, AbstractTable.ValuesTable.Cell<R,C,V>| Modifier and Type | Field and Description |
|---|---|
private java.util.Comparator<? super C> |
columnComparator |
private static long |
serialVersionUID |
backingMap, factory| Constructor and Description |
|---|
TreeBasedTable(java.util.Comparator<? super R> rowComparator,
java.util.Comparator<? super C> columnComparator) |
| Modifier and Type | Method and Description |
|---|---|
java.util.Comparator<? super C> |
columnComparator()
Returns the comparator that orders the columns.
|
static <R extends java.lang.Comparable,C extends java.lang.Comparable,V> |
create()
Creates an empty
TreeBasedTable that uses the natural orderings
of both row and column keys. |
static <R,C,V> TreeBasedTable<R,C,V> |
create(java.util.Comparator<? super R> rowComparator,
java.util.Comparator<? super C> columnComparator)
Creates an empty
TreeBasedTable that is ordered by the specified
comparators. |
static <R,C,V> TreeBasedTable<R,C,V> |
create(TreeBasedTable<R,C,? extends V> table)
Creates a
TreeBasedTable with the same mappings and sort order
as the specified TreeBasedTable. |
(package private) java.util.Iterator<C> |
createColumnKeyIterator()
Overridden column iterator to return columns values in globally sorted
order.
|
java.util.SortedMap<C,V> |
row(R rowKey)
Returns a view of all mappings that have the given row key.
|
java.util.Comparator<? super R> |
rowComparator()
Returns the comparator that orders the rows.
|
java.util.SortedSet<R> |
rowKeySet()
Returns a set of row keys that have one or more values in the table.
|
java.util.SortedMap<R,java.util.Map<C,V>> |
rowMap()
Returns a view that associates each row key with the corresponding map from
column keys to values.
|
createRowMapcellIterator, cellSet, clear, column, columnKeySet, columnMap, contains, containsColumn, containsRow, containsValue, get, isEmpty, put, remove, size, valuescreateCellSet, createValues, equals, hashCode, putAll, toString, valuesIteratorclone, finalize, getClass, notify, notifyAll, wait, wait, waitcellSet, clear, column, columnKeySet, columnMap, contains, containsColumn, containsRow, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size, valuesprivate final java.util.Comparator<? super C> columnComparator
private static final long serialVersionUID
public static <R extends java.lang.Comparable,C extends java.lang.Comparable,V> TreeBasedTable<R,C,V> create()
TreeBasedTable that uses the natural orderings
of both row and column keys.
The method signature specifies R extends Comparable with a raw
Comparable, instead of R extends Comparable<? super R>,
and the same for C. That's necessary to support classes defined
without generics.
public static <R,C,V> TreeBasedTable<R,C,V> create(java.util.Comparator<? super R> rowComparator, java.util.Comparator<? super C> columnComparator)
TreeBasedTable that is ordered by the specified
comparators.rowComparator - the comparator that orders the row keyscolumnComparator - the comparator that orders the column keyspublic static <R,C,V> TreeBasedTable<R,C,V> create(TreeBasedTable<R,C,? extends V> table)
TreeBasedTable with the same mappings and sort order
as the specified TreeBasedTable.public java.util.Comparator<? super R> rowComparator()
Ordering.natural() is returned.public java.util.Comparator<? super C> columnComparator()
Ordering.natural() is returned.public java.util.SortedMap<C,V> row(R rowKey)
Changes to the returned map will update the underlying table, and vice versa.
Because a TreeBasedTable has unique sorted values for a given
row, this method returns a SortedMap, instead of the Map
specified in the Table interface.
public java.util.SortedSet<R> rowKeySet()
StandardRowSortedTableThis method returns a SortedSet, instead of the Set
specified in the Table interface.
public java.util.SortedMap<R,java.util.Map<C,V>> rowMap()
StandardRowSortedTableput() 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().
This method returns a SortedMap, instead of the Map
specified in the Table interface.
java.util.Iterator<C> createColumnKeyIterator()
createColumnKeyIterator in class StandardTable<R,C,V>