Table
表格集合类,能够通过行和列定位到一个cell,也能通过行取得整行的数据或通过列取得整列的数据
supports a number of views to let you use the data from any angle, including
- rowMap(), which views a Table<R, C, V> as a Map<R, Map<C, V>>. Similarly, rowKeySet()returns a Set<R>.
- row(r) returns a non-null Map<C, V>. Writes to the Map will write through to the underlying Table.
- Analogous column methods are provided: columnMap(), columnKeySet(), and column(c). (Column-based access is somewhat less efficient than row-based access.)
- cellSet() returns a view of the Table as a set of Table.Cell<R, C, V>. Cell is much like Map.Entry, but distinguishes the row and column keys.
Several Table implementations are provided, including:
- HashBasedTable, which is essentially backed by a HashMap<R, HashMap<C, V>> (as of Guava 20.0, it is backed by a LinkedHashMap<R, LinkedHashMap<C, V>>).
- TreeBasedTable, which is essentially backed by a TreeMap<R, TreeMap<C, V>>.
- ImmutableTable, which is essentially backed by an ImmutableMap<R, ImmutableMap<C, V>>. (Note: ImmutableTable has optimized implementations for sparser and denser data sets.)
- ArrayTable, which requires that the complete universe of rows and columns be specified at construction time, but is backed by a two-dimensional array to improve speed and memory efficiency when the table is dense. ArrayTable works somewhat differently from other implementations; consult the Javadoc for details.