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