11d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/* 21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2008 The Guava Authors 31d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 41d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License"); 51d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * you may not use this file except in compliance with the License. 61d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * You may obtain a copy of the License at 71d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 81d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * http://www.apache.org/licenses/LICENSE-2.0 91d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 101d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Unless required by applicable law or agreed to in writing, software 111d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS, 121d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * See the License for the specific language governing permissions and 141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * limitations under the License. 151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 171d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpackage com.google.common.collect; 181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 191d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport com.google.common.annotations.GwtCompatible; 201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport com.google.common.base.Objects; 211d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport java.util.Collection; 231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport java.util.Map; 241d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport java.util.Set; 251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 261d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport javax.annotation.Nullable; 271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 281d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/** 291d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * A collection that associates an ordered pair of keys, called a row key and a 301d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * column key, with a single value. A table may be sparse, with only a small 311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * fraction of row key / column key pairs possessing a corresponding value. 321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>The mappings corresponding to a given row key may be viewed as a {@link 341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Map} whose keys are the columns. The reverse is also available, associating a 351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * column with a row key / value map. Note that, in some implementations, data 361d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * access by column key may have fewer supported operations or worse performance 371d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * than data access by row key. 381d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>The methods returning collections or maps always return views of the 401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * underlying table. Updating the table can change the contents of those 411d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * collections, and updating the collections will change the table. 421d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 431d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>All methods that modify the table are optional, and the views returned by 441d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * the table may or may not be modifiable. When modification isn't supported, 451d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * those methods will throw an {@link UnsupportedOperationException}. 467dd252788645e940eada959bdde927426e2531c9Paul Duffin * 477dd252788645e940eada959bdde927426e2531c9Paul Duffin * <p>See the Guava User Guide article on <a href= 487dd252788645e940eada959bdde927426e2531c9Paul Duffin * "http://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#Table"> 497dd252788645e940eada959bdde927426e2531c9Paul Duffin * {@code Table}</a>. 501d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 511d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @author Jared Levy 521d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param <R> the type of the table row keys 531d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param <C> the type of the table column keys 541d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param <V> the type of the mapped values 551d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @since 7.0 561d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 571d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert@GwtCompatible 581d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpublic interface Table<R, C, V> { 591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert // TODO(jlevy): Consider adding methods similar to ConcurrentMap methods. 601d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 611d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert // Accessors 621d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 631d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 641d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns {@code true} if the table contains a mapping with the specified 651d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * row and column keys. 661d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 671d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param rowKey key of row to search for 681d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param columnKey key of column to search for 691d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 701d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert boolean contains(@Nullable Object rowKey, @Nullable Object columnKey); 711d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 721d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 731d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns {@code true} if the table contains a mapping with the specified 741d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * row key. 751d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 761d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param rowKey key of row to search for 771d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 781d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert boolean containsRow(@Nullable Object rowKey); 791d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 801d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 811d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns {@code true} if the table contains a mapping with the specified 821d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * column. 831d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 841d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param columnKey key of column to search for 851d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 861d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert boolean containsColumn(@Nullable Object columnKey); 871d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 881d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 891d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns {@code true} if the table contains a mapping with the specified 901d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * value. 911d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 921d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param value value to search for 931d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 941d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert boolean containsValue(@Nullable Object value); 951d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 961d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 971d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns the value corresponding to the given row and column keys, or 981d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@code null} if no such mapping exists. 991d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1001d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param rowKey key of row to search for 1011d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param columnKey key of column to search for 1021d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1031d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert V get(@Nullable Object rowKey, @Nullable Object columnKey); 1041d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1051d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** Returns {@code true} if the table contains no mappings. */ 1061d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert boolean isEmpty(); 1071d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1081d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 1091d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns the number of row key / column key / value mappings in the table. 1101d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1111d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert int size(); 1121d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1131d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 1141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Compares the specified object with this table for equality. Two tables are 1151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * equal when their cell views, as returned by {@link #cellSet}, are equal. 1161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1170888a09821a98ac0680fad765217302858e70fa4Paul Duffin @Override 1181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert boolean equals(@Nullable Object obj); 1191d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 1211d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns the hash code for this table. The hash code of a table is defined 1221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * as the hash code of its cell view, as returned by {@link #cellSet}. 1231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1240888a09821a98ac0680fad765217302858e70fa4Paul Duffin @Override 1251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert int hashCode(); 1261d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert // Mutators 1281d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1291d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** Removes all mappings from the table. */ 1301d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert void clear(); 1311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 1331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Associates the specified value with the specified keys. If the table 1341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * already contained a mapping for those keys, the old value is replaced with 1351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * the specified value. 1361d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1371d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param rowKey row key that the value should be associated with 1381d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param columnKey column key that the value should be associated with 1391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param value value to be associated with the specified keys 1401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return the value previously associated with the keys, or {@code null} if 1411d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * no mapping existed for the keys 1421d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1431d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert V put(R rowKey, C columnKey, V value); 1441d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1451d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 1461d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copies all mappings from the specified table to this table. The effect is 1471d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * equivalent to calling {@link #put} with each row key / column key / value 1481d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * mapping in {@code table}. 1491d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1501d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param table the table to add to this table 1511d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1521d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert void putAll(Table<? extends R, ? extends C, ? extends V> table); 1531d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1541d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 1551d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Removes the mapping, if any, associated with the given keys. 1561d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1571d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param rowKey row key of mapping to be removed 1581d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param columnKey column key of mapping to be removed 1591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return the value previously associated with the keys, or {@code null} if 1601d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * no such value existed 1611d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1621d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert V remove(@Nullable Object rowKey, @Nullable Object columnKey); 1631d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1641d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert // Views 1651d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1661d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 1671d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns a view of all mappings that have the given row key. For each row 1681d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * key / column key / value mapping in the table with that row key, the 1691d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * returned map associates the column key with the value. If no mappings in 1701d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * the table have the provided row key, an empty map is returned. 1711d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1721d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>Changes to the returned map will update the underlying table, and vice 1731d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * versa. 1741d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1751d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param rowKey key of row to search for in the table 1761d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return the corresponding map from column keys to values 1771d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1781d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert Map<C, V> row(R rowKey); 1791d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1801d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 1811d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns a view of all mappings that have the given column key. For each row 1821d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * key / column key / value mapping in the table with that column key, the 1831d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * returned map associates the row key with the value. If no mappings in the 1841d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * table have the provided column key, an empty map is returned. 1851d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1861d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>Changes to the returned map will update the underlying table, and vice 1871d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * versa. 1881d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1891d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param columnKey key of column to search for in the table 1901d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return the corresponding map from row keys to values 1911d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1921d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert Map<R, V> column(C columnKey); 1931d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1941d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 1951d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns a set of all row key / column key / value triplets. Changes to the 1961d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * returned set will update the underlying table, and vice versa. The cell set 1971d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * does not support the {@code add} or {@code addAll} methods. 1981d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1991d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return set of table cells consisting of row key / column key / value 2001d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * triplets 2011d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2021d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert Set<Cell<R, C, V>> cellSet(); 2031d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2041d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2051d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns a set of row keys that have one or more values in the table. 2061d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Changes to the set will update the underlying table, and vice versa. 2071d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 2081d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return set of row keys 2091d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2101d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert Set<R> rowKeySet(); 2111d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2121d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2131d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns a set of column keys that have one or more values in the table. 2141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Changes to the set will update the underlying table, and vice versa. 2151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 2161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return set of column keys 2171d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert Set<C> columnKeySet(); 2191d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2211d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns a collection of all values, which may contain duplicates. Changes 2221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * to the returned collection will update the underlying table, and vice 2231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * versa. 2241d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 2251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return collection of values 2261d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert Collection<V> values(); 2281d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2291d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2301d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns a view that associates each row key with the corresponding map from 2311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * column keys to values. Changes to the returned map will update this table. 2321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * The returned map does not support {@code put()} or {@code putAll()}, or 2331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@code setValue()} on its entries. 2341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 2351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>In contrast, the maps returned by {@code rowMap().get()} have the same 2361d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * behavior as those returned by {@link #row}. Those maps may support {@code 2371d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * setValue()}, {@code put()}, and {@code putAll()}. 2381d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 2391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return a map view from each row key to a secondary map from column keys to 2401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * values 2411d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2421d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert Map<R, Map<C, V>> rowMap(); 2431d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2441d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2451d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns a view that associates each column key with the corresponding map 2461d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * from row keys to values. Changes to the returned map will update this 2471d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * table. The returned map does not support {@code put()} or {@code putAll()}, 2481d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * or {@code setValue()} on its entries. 2491d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 2501d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>In contrast, the maps returned by {@code columnMap().get()} have the 2511d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * same behavior as those returned by {@link #column}. Those maps may support 2521d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@code setValue()}, {@code put()}, and {@code putAll()}. 2531d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 2541d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return a map view from each column key to a secondary map from row keys to 2551d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * values 2561d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2571d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert Map<C, Map<R, V>> columnMap(); 2581d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2601d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Row key / column key / value triplet corresponding to a mapping in a table. 2611d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 2621d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @since 7.0 2631d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2641d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert interface Cell<R, C, V> { 2651d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2661d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns the row key of this cell. 2671d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2681d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert R getRowKey(); 2691d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2701d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2711d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns the column key of this cell. 2721d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2731d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert C getColumnKey(); 2741d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2751d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2761d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns the value of this cell. 2771d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2781d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert V getValue(); 2791d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2801d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2811d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Compares the specified object with this cell for equality. Two cells are 2821d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * equal when they have equal row keys, column keys, and values. 2831d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2840888a09821a98ac0680fad765217302858e70fa4Paul Duffin @Override 2851d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert boolean equals(@Nullable Object obj); 2861d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 2871d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 2881d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns the hash code of this cell. 2891d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 2901d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>The hash code of a table cell is equal to {@link 2911d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Objects#hashCode}{@code (e.getRowKey(), e.getColumnKey(), e.getValue())}. 2921d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 2930888a09821a98ac0680fad765217302858e70fa4Paul Duffin @Override 2941d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert int hashCode(); 2951d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 2961d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert} 297