001/* 002 * Copyright (C) 2009 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.google.common.collect; 018 019import static com.google.common.base.Preconditions.checkArgument; 020import static com.google.common.base.Preconditions.checkElementIndex; 021import static com.google.common.base.Preconditions.checkNotNull; 022 023import com.google.common.annotations.Beta; 024import com.google.common.annotations.GwtCompatible; 025import com.google.common.annotations.GwtIncompatible; 026import com.google.common.base.Objects; 027import com.google.common.collect.Maps.IteratorBasedAbstractMap; 028import com.google.errorprone.annotations.CanIgnoreReturnValue; 029import com.google.j2objc.annotations.WeakOuter; 030import java.io.Serializable; 031import java.lang.reflect.Array; 032import java.util.Arrays; 033import java.util.Collection; 034import java.util.Iterator; 035import java.util.Map; 036import java.util.Set; 037import org.checkerframework.checker.nullness.compatqual.MonotonicNonNullDecl; 038import org.checkerframework.checker.nullness.compatqual.NullableDecl; 039 040/** 041 * Fixed-size {@link Table} implementation backed by a two-dimensional array. 042 * 043 * <p>The allowed row and column keys must be supplied when the table is created. The table always 044 * contains a mapping for every row key / column pair. The value corresponding to a given row and 045 * column is null unless another value is provided. 046 * 047 * <p>The table's size is constant: the product of the number of supplied row keys and the number of 048 * supplied column keys. The {@code remove} and {@code clear} methods are not supported by the table 049 * or its views. The {@link #erase} and {@link #eraseAll} methods may be used instead. 050 * 051 * <p>The ordering of the row and column keys provided when the table is constructed determines the 052 * iteration ordering across rows and columns in the table's views. None of the view iterators 053 * support {@link Iterator#remove}. If the table is modified after an iterator is created, the 054 * iterator remains valid. 055 * 056 * <p>This class requires less memory than the {@link HashBasedTable} and {@link TreeBasedTable} 057 * implementations, except when the table is sparse. 058 * 059 * <p>Null row keys or column keys are not permitted. 060 * 061 * <p>This class provides methods involving the underlying array structure, where the array indices 062 * correspond to the position of a row or column in the lists of allowed keys and values. See the 063 * {@link #at}, {@link #set}, {@link #toArray}, {@link #rowKeyList}, and {@link #columnKeyList} 064 * methods for more details. 065 * 066 * <p>Note that this implementation is not synchronized. If multiple threads access the same cell of 067 * an {@code ArrayTable} concurrently and one of the threads modifies its value, there is no 068 * guarantee that the new value will be fully visible to the other threads. To guarantee that 069 * modifications are visible, synchronize access to the table. Unlike other {@code Table} 070 * implementations, synchronization is unnecessary between a thread that writes to one cell and a 071 * thread that reads from another. 072 * 073 * <p>See the Guava User Guide article on <a href= 074 * "https://github.com/google/guava/wiki/NewCollectionTypesExplained#table"> {@code Table}</a>. 075 * 076 * @author Jared Levy 077 * @since 10.0 078 */ 079@Beta 080@GwtCompatible(emulated = true) 081public final class ArrayTable<R, C, V> extends AbstractTable<R, C, V> implements Serializable { 082 083 /** 084 * Creates an {@code ArrayTable} filled with {@code null}. 085 * 086 * @param rowKeys row keys that may be stored in the generated table 087 * @param columnKeys column keys that may be stored in the generated table 088 * @throws NullPointerException if any of the provided keys is null 089 * @throws IllegalArgumentException if {@code rowKeys} or {@code columnKeys} contains duplicates 090 * or if exactly one of {@code rowKeys} or {@code columnKeys} is empty. 091 */ 092 public static <R, C, V> ArrayTable<R, C, V> create( 093 Iterable<? extends R> rowKeys, Iterable<? extends C> columnKeys) { 094 return new ArrayTable<>(rowKeys, columnKeys); 095 } 096 097 /* 098 * TODO(jlevy): Add factory methods taking an Enum class, instead of an 099 * iterable, to specify the allowed row keys and/or column keys. Note that 100 * custom serialization logic is needed to support different enum sizes during 101 * serialization and deserialization. 102 */ 103 104 /** 105 * Creates an {@code ArrayTable} with the mappings in the provided table. 106 * 107 * <p>If {@code table} includes a mapping with row key {@code r} and a separate mapping with 108 * column key {@code c}, the returned table contains a mapping with row key {@code r} and column 109 * key {@code c}. If that row key / column key pair in not in {@code table}, the pair maps to 110 * {@code null} in the generated table. 111 * 112 * <p>The returned table allows subsequent {@code put} calls with the row keys in {@code 113 * table.rowKeySet()} and the column keys in {@code table.columnKeySet()}. Calling {@link #put} 114 * with other keys leads to an {@code IllegalArgumentException}. 115 * 116 * <p>The ordering of {@code table.rowKeySet()} and {@code table.columnKeySet()} determines the 117 * row and column iteration ordering of the returned table. 118 * 119 * @throws NullPointerException if {@code table} has a null key 120 */ 121 public static <R, C, V> ArrayTable<R, C, V> create(Table<R, C, V> table) { 122 return (table instanceof ArrayTable<?, ?, ?>) 123 ? new ArrayTable<R, C, V>((ArrayTable<R, C, V>) table) 124 : new ArrayTable<R, C, V>(table); 125 } 126 127 private final ImmutableList<R> rowList; 128 private final ImmutableList<C> columnList; 129 130 // TODO(jlevy): Add getters returning rowKeyToIndex and columnKeyToIndex? 131 private final ImmutableMap<R, Integer> rowKeyToIndex; 132 private final ImmutableMap<C, Integer> columnKeyToIndex; 133 private final V[][] array; 134 135 private ArrayTable(Iterable<? extends R> rowKeys, Iterable<? extends C> columnKeys) { 136 this.rowList = ImmutableList.copyOf(rowKeys); 137 this.columnList = ImmutableList.copyOf(columnKeys); 138 checkArgument(rowList.isEmpty() == columnList.isEmpty()); 139 140 /* 141 * TODO(jlevy): Support only one of rowKey / columnKey being empty? If we 142 * do, when columnKeys is empty but rowKeys isn't, rowKeyList() can contain 143 * elements but rowKeySet() will be empty and containsRow() won't 144 * acknolwedge them. 145 */ 146 rowKeyToIndex = Maps.indexMap(rowList); 147 columnKeyToIndex = Maps.indexMap(columnList); 148 149 @SuppressWarnings("unchecked") 150 V[][] tmpArray = (V[][]) new Object[rowList.size()][columnList.size()]; 151 array = tmpArray; 152 // Necessary because in GWT the arrays are initialized with "undefined" instead of null. 153 eraseAll(); 154 } 155 156 private ArrayTable(Table<R, C, V> table) { 157 this(table.rowKeySet(), table.columnKeySet()); 158 putAll(table); 159 } 160 161 private ArrayTable(ArrayTable<R, C, V> table) { 162 rowList = table.rowList; 163 columnList = table.columnList; 164 rowKeyToIndex = table.rowKeyToIndex; 165 columnKeyToIndex = table.columnKeyToIndex; 166 @SuppressWarnings("unchecked") 167 V[][] copy = (V[][]) new Object[rowList.size()][columnList.size()]; 168 array = copy; 169 for (int i = 0; i < rowList.size(); i++) { 170 System.arraycopy(table.array[i], 0, copy[i], 0, table.array[i].length); 171 } 172 } 173 174 private abstract static class ArrayMap<K, V> extends IteratorBasedAbstractMap<K, V> { 175 private final ImmutableMap<K, Integer> keyIndex; 176 177 private ArrayMap(ImmutableMap<K, Integer> keyIndex) { 178 this.keyIndex = keyIndex; 179 } 180 181 @Override 182 public Set<K> keySet() { 183 return keyIndex.keySet(); 184 } 185 186 K getKey(int index) { 187 return keyIndex.keySet().asList().get(index); 188 } 189 190 abstract String getKeyRole(); 191 192 @NullableDecl 193 abstract V getValue(int index); 194 195 @NullableDecl 196 abstract V setValue(int index, V newValue); 197 198 @Override 199 public int size() { 200 return keyIndex.size(); 201 } 202 203 @Override 204 public boolean isEmpty() { 205 return keyIndex.isEmpty(); 206 } 207 208 Entry<K, V> getEntry(final int index) { 209 checkElementIndex(index, size()); 210 return new AbstractMapEntry<K, V>() { 211 @Override 212 public K getKey() { 213 return ArrayMap.this.getKey(index); 214 } 215 216 @Override 217 public V getValue() { 218 return ArrayMap.this.getValue(index); 219 } 220 221 @Override 222 public V setValue(V value) { 223 return ArrayMap.this.setValue(index, value); 224 } 225 }; 226 } 227 228 @Override 229 Iterator<Entry<K, V>> entryIterator() { 230 return new AbstractIndexedListIterator<Entry<K, V>>(size()) { 231 @Override 232 protected Entry<K, V> get(final int index) { 233 return getEntry(index); 234 } 235 }; 236 } 237 238 // TODO(lowasser): consider an optimized values() implementation 239 240 @Override 241 public boolean containsKey(@NullableDecl Object key) { 242 return keyIndex.containsKey(key); 243 } 244 245 @Override 246 public V get(@NullableDecl Object key) { 247 Integer index = keyIndex.get(key); 248 if (index == null) { 249 return null; 250 } else { 251 return getValue(index); 252 } 253 } 254 255 @Override 256 public V put(K key, V value) { 257 Integer index = keyIndex.get(key); 258 if (index == null) { 259 throw new IllegalArgumentException( 260 getKeyRole() + " " + key + " not in " + keyIndex.keySet()); 261 } 262 return setValue(index, value); 263 } 264 265 @Override 266 public V remove(Object key) { 267 throw new UnsupportedOperationException(); 268 } 269 270 @Override 271 public void clear() { 272 throw new UnsupportedOperationException(); 273 } 274 } 275 276 /** 277 * Returns, as an immutable list, the row keys provided when the table was constructed, including 278 * those that are mapped to null values only. 279 */ 280 public ImmutableList<R> rowKeyList() { 281 return rowList; 282 } 283 284 /** 285 * Returns, as an immutable list, the column keys provided when the table was constructed, 286 * including those that are mapped to null values only. 287 */ 288 public ImmutableList<C> columnKeyList() { 289 return columnList; 290 } 291 292 /** 293 * Returns the value corresponding to the specified row and column indices. The same value is 294 * returned by {@code get(rowKeyList().get(rowIndex), columnKeyList().get(columnIndex))}, but this 295 * method runs more quickly. 296 * 297 * @param rowIndex position of the row key in {@link #rowKeyList()} 298 * @param columnIndex position of the row key in {@link #columnKeyList()} 299 * @return the value with the specified row and column 300 * @throws IndexOutOfBoundsException if either index is negative, {@code rowIndex} is greater than 301 * or equal to the number of allowed row keys, or {@code columnIndex} is greater than or equal 302 * to the number of allowed column keys 303 */ 304 public V at(int rowIndex, int columnIndex) { 305 // In GWT array access never throws IndexOutOfBoundsException. 306 checkElementIndex(rowIndex, rowList.size()); 307 checkElementIndex(columnIndex, columnList.size()); 308 return array[rowIndex][columnIndex]; 309 } 310 311 /** 312 * Associates {@code value} with the specified row and column indices. The logic {@code 313 * put(rowKeyList().get(rowIndex), columnKeyList().get(columnIndex), value)} has the same 314 * behavior, but this method runs more quickly. 315 * 316 * @param rowIndex position of the row key in {@link #rowKeyList()} 317 * @param columnIndex position of the row key in {@link #columnKeyList()} 318 * @param value value to store in the table 319 * @return the previous value with the specified row and column 320 * @throws IndexOutOfBoundsException if either index is negative, {@code rowIndex} is greater than 321 * or equal to the number of allowed row keys, or {@code columnIndex} is greater than or equal 322 * to the number of allowed column keys 323 */ 324 @CanIgnoreReturnValue 325 public V set(int rowIndex, int columnIndex, @NullableDecl V value) { 326 // In GWT array access never throws IndexOutOfBoundsException. 327 checkElementIndex(rowIndex, rowList.size()); 328 checkElementIndex(columnIndex, columnList.size()); 329 V oldValue = array[rowIndex][columnIndex]; 330 array[rowIndex][columnIndex] = value; 331 return oldValue; 332 } 333 334 /** 335 * Returns a two-dimensional array with the table contents. The row and column indices correspond 336 * to the positions of the row and column in the iterables provided during table construction. If 337 * the table lacks a mapping for a given row and column, the corresponding array element is null. 338 * 339 * <p>Subsequent table changes will not modify the array, and vice versa. 340 * 341 * @param valueClass class of values stored in the returned array 342 */ 343 @GwtIncompatible // reflection 344 public V[][] toArray(Class<V> valueClass) { 345 @SuppressWarnings("unchecked") // TODO: safe? 346 V[][] copy = (V[][]) Array.newInstance(valueClass, rowList.size(), columnList.size()); 347 for (int i = 0; i < rowList.size(); i++) { 348 System.arraycopy(array[i], 0, copy[i], 0, array[i].length); 349 } 350 return copy; 351 } 352 353 /** 354 * Not supported. Use {@link #eraseAll} instead. 355 * 356 * @throws UnsupportedOperationException always 357 * @deprecated Use {@link #eraseAll} 358 */ 359 @Override 360 @Deprecated 361 public void clear() { 362 throw new UnsupportedOperationException(); 363 } 364 365 /** Associates the value {@code null} with every pair of allowed row and column keys. */ 366 public void eraseAll() { 367 for (V[] row : array) { 368 Arrays.fill(row, null); 369 } 370 } 371 372 /** 373 * Returns {@code true} if the provided keys are among the keys provided when the table was 374 * constructed. 375 */ 376 @Override 377 public boolean contains(@NullableDecl Object rowKey, @NullableDecl Object columnKey) { 378 return containsRow(rowKey) && containsColumn(columnKey); 379 } 380 381 /** 382 * Returns {@code true} if the provided column key is among the column keys provided when the 383 * table was constructed. 384 */ 385 @Override 386 public boolean containsColumn(@NullableDecl Object columnKey) { 387 return columnKeyToIndex.containsKey(columnKey); 388 } 389 390 /** 391 * Returns {@code true} if the provided row key is among the row keys provided when the table was 392 * constructed. 393 */ 394 @Override 395 public boolean containsRow(@NullableDecl Object rowKey) { 396 return rowKeyToIndex.containsKey(rowKey); 397 } 398 399 @Override 400 public boolean containsValue(@NullableDecl Object value) { 401 for (V[] row : array) { 402 for (V element : row) { 403 if (Objects.equal(value, element)) { 404 return true; 405 } 406 } 407 } 408 return false; 409 } 410 411 @Override 412 public V get(@NullableDecl Object rowKey, @NullableDecl Object columnKey) { 413 Integer rowIndex = rowKeyToIndex.get(rowKey); 414 Integer columnIndex = columnKeyToIndex.get(columnKey); 415 return (rowIndex == null || columnIndex == null) ? null : at(rowIndex, columnIndex); 416 } 417 418 /** 419 * Returns {@code true} if {@code rowKeyList().size == 0} or {@code columnKeyList().size() == 0}. 420 */ 421 @Override 422 public boolean isEmpty() { 423 return rowList.isEmpty() || columnList.isEmpty(); 424 } 425 426 /** 427 * {@inheritDoc} 428 * 429 * @throws IllegalArgumentException if {@code rowKey} is not in {@link #rowKeySet()} or {@code 430 * columnKey} is not in {@link #columnKeySet()}. 431 */ 432 @CanIgnoreReturnValue 433 @Override 434 public V put(R rowKey, C columnKey, @NullableDecl V value) { 435 checkNotNull(rowKey); 436 checkNotNull(columnKey); 437 Integer rowIndex = rowKeyToIndex.get(rowKey); 438 checkArgument(rowIndex != null, "Row %s not in %s", rowKey, rowList); 439 Integer columnIndex = columnKeyToIndex.get(columnKey); 440 checkArgument(columnIndex != null, "Column %s not in %s", columnKey, columnList); 441 return set(rowIndex, columnIndex, value); 442 } 443 444 /* 445 * TODO(jlevy): Consider creating a merge() method, similar to putAll() but 446 * copying non-null values only. 447 */ 448 449 /** 450 * {@inheritDoc} 451 * 452 * <p>If {@code table} is an {@code ArrayTable}, its null values will be stored in this table, 453 * possibly replacing values that were previously non-null. 454 * 455 * @throws NullPointerException if {@code table} has a null key 456 * @throws IllegalArgumentException if any of the provided table's row keys or column keys is not 457 * in {@link #rowKeySet()} or {@link #columnKeySet()} 458 */ 459 @Override 460 public void putAll(Table<? extends R, ? extends C, ? extends V> table) { 461 super.putAll(table); 462 } 463 464 /** 465 * Not supported. Use {@link #erase} instead. 466 * 467 * @throws UnsupportedOperationException always 468 * @deprecated Use {@link #erase} 469 */ 470 @CanIgnoreReturnValue 471 @Override 472 @Deprecated 473 public V remove(Object rowKey, Object columnKey) { 474 throw new UnsupportedOperationException(); 475 } 476 477 /** 478 * Associates the value {@code null} with the specified keys, assuming both keys are valid. If 479 * either key is null or isn't among the keys provided during construction, this method has no 480 * effect. 481 * 482 * <p>This method is equivalent to {@code put(rowKey, columnKey, null)} when both provided keys 483 * are valid. 484 * 485 * @param rowKey row key of mapping to be erased 486 * @param columnKey column key of mapping to be erased 487 * @return the value previously associated with the keys, or {@code null} if no mapping existed 488 * for the keys 489 */ 490 @CanIgnoreReturnValue 491 public V erase(@NullableDecl Object rowKey, @NullableDecl Object columnKey) { 492 Integer rowIndex = rowKeyToIndex.get(rowKey); 493 Integer columnIndex = columnKeyToIndex.get(columnKey); 494 if (rowIndex == null || columnIndex == null) { 495 return null; 496 } 497 return set(rowIndex, columnIndex, null); 498 } 499 500 // TODO(jlevy): Add eraseRow and eraseColumn methods? 501 502 @Override 503 public int size() { 504 return rowList.size() * columnList.size(); 505 } 506 507 /** 508 * Returns an unmodifiable set of all row key / column key / value triplets. Changes to the table 509 * will update the returned set. 510 * 511 * <p>The returned set's iterator traverses the mappings with the first row key, the mappings with 512 * the second row key, and so on. 513 * 514 * <p>The value in the returned cells may change if the table subsequently changes. 515 * 516 * @return set of table cells consisting of row key / column key / value triplets 517 */ 518 @Override 519 public Set<Cell<R, C, V>> cellSet() { 520 return super.cellSet(); 521 } 522 523 @Override 524 Iterator<Cell<R, C, V>> cellIterator() { 525 return new AbstractIndexedListIterator<Cell<R, C, V>>(size()) { 526 @Override 527 protected Cell<R, C, V> get(final int index) { 528 return getCell(index); 529 } 530 }; 531 } 532 533 private Cell<R, C, V> getCell(final int index) { 534 return new Tables.AbstractCell<R, C, V>() { 535 final int rowIndex = index / columnList.size(); 536 final int columnIndex = index % columnList.size(); 537 538 @Override 539 public R getRowKey() { 540 return rowList.get(rowIndex); 541 } 542 543 @Override 544 public C getColumnKey() { 545 return columnList.get(columnIndex); 546 } 547 548 @Override 549 public V getValue() { 550 return at(rowIndex, columnIndex); 551 } 552 }; 553 } 554 555 private V getValue(int index) { 556 int rowIndex = index / columnList.size(); 557 int columnIndex = index % columnList.size(); 558 return at(rowIndex, columnIndex); 559 } 560 561 /** 562 * Returns a view of all mappings that have the given column key. If the column key isn't in 563 * {@link #columnKeySet()}, an empty immutable map is returned. 564 * 565 * <p>Otherwise, for each row key in {@link #rowKeySet()}, the returned map associates the row key 566 * with the corresponding value in the table. Changes to the returned map will update the 567 * underlying table, and vice versa. 568 * 569 * @param columnKey key of column to search for in the table 570 * @return the corresponding map from row keys to values 571 */ 572 @Override 573 public Map<R, V> column(C columnKey) { 574 checkNotNull(columnKey); 575 Integer columnIndex = columnKeyToIndex.get(columnKey); 576 return (columnIndex == null) ? ImmutableMap.<R, V>of() : new Column(columnIndex); 577 } 578 579 private class Column extends ArrayMap<R, V> { 580 final int columnIndex; 581 582 Column(int columnIndex) { 583 super(rowKeyToIndex); 584 this.columnIndex = columnIndex; 585 } 586 587 @Override 588 String getKeyRole() { 589 return "Row"; 590 } 591 592 @Override 593 V getValue(int index) { 594 return at(index, columnIndex); 595 } 596 597 @Override 598 V setValue(int index, V newValue) { 599 return set(index, columnIndex, newValue); 600 } 601 } 602 603 /** 604 * Returns an immutable set of the valid column keys, including those that are associated with 605 * null values only. 606 * 607 * @return immutable set of column keys 608 */ 609 @Override 610 public ImmutableSet<C> columnKeySet() { 611 return columnKeyToIndex.keySet(); 612 } 613 614 @MonotonicNonNullDecl private transient ColumnMap columnMap; 615 616 @Override 617 public Map<C, Map<R, V>> columnMap() { 618 ColumnMap map = columnMap; 619 return (map == null) ? columnMap = new ColumnMap() : map; 620 } 621 622 @WeakOuter 623 private class ColumnMap extends ArrayMap<C, Map<R, V>> { 624 private ColumnMap() { 625 super(columnKeyToIndex); 626 } 627 628 @Override 629 String getKeyRole() { 630 return "Column"; 631 } 632 633 @Override 634 Map<R, V> getValue(int index) { 635 return new Column(index); 636 } 637 638 @Override 639 Map<R, V> setValue(int index, Map<R, V> newValue) { 640 throw new UnsupportedOperationException(); 641 } 642 643 @Override 644 public Map<R, V> put(C key, Map<R, V> value) { 645 throw new UnsupportedOperationException(); 646 } 647 } 648 649 /** 650 * Returns a view of all mappings that have the given row key. If the row key isn't in {@link 651 * #rowKeySet()}, an empty immutable map is returned. 652 * 653 * <p>Otherwise, for each column key in {@link #columnKeySet()}, the returned map associates the 654 * column key with the corresponding value in the table. Changes to the returned map will update 655 * the underlying table, and vice versa. 656 * 657 * @param rowKey key of row to search for in the table 658 * @return the corresponding map from column keys to values 659 */ 660 @Override 661 public Map<C, V> row(R rowKey) { 662 checkNotNull(rowKey); 663 Integer rowIndex = rowKeyToIndex.get(rowKey); 664 return (rowIndex == null) ? ImmutableMap.<C, V>of() : new Row(rowIndex); 665 } 666 667 private class Row extends ArrayMap<C, V> { 668 final int rowIndex; 669 670 Row(int rowIndex) { 671 super(columnKeyToIndex); 672 this.rowIndex = rowIndex; 673 } 674 675 @Override 676 String getKeyRole() { 677 return "Column"; 678 } 679 680 @Override 681 V getValue(int index) { 682 return at(rowIndex, index); 683 } 684 685 @Override 686 V setValue(int index, V newValue) { 687 return set(rowIndex, index, newValue); 688 } 689 } 690 691 /** 692 * Returns an immutable set of the valid row keys, including those that are associated with null 693 * values only. 694 * 695 * @return immutable set of row keys 696 */ 697 @Override 698 public ImmutableSet<R> rowKeySet() { 699 return rowKeyToIndex.keySet(); 700 } 701 702 @MonotonicNonNullDecl private transient RowMap rowMap; 703 704 @Override 705 public Map<R, Map<C, V>> rowMap() { 706 RowMap map = rowMap; 707 return (map == null) ? rowMap = new RowMap() : map; 708 } 709 710 @WeakOuter 711 private class RowMap extends ArrayMap<R, Map<C, V>> { 712 private RowMap() { 713 super(rowKeyToIndex); 714 } 715 716 @Override 717 String getKeyRole() { 718 return "Row"; 719 } 720 721 @Override 722 Map<C, V> getValue(int index) { 723 return new Row(index); 724 } 725 726 @Override 727 Map<C, V> setValue(int index, Map<C, V> newValue) { 728 throw new UnsupportedOperationException(); 729 } 730 731 @Override 732 public Map<C, V> put(R key, Map<C, V> value) { 733 throw new UnsupportedOperationException(); 734 } 735 } 736 737 /** 738 * Returns an unmodifiable collection of all values, which may contain duplicates. Changes to the 739 * table will update the returned collection. 740 * 741 * <p>The returned collection's iterator traverses the values of the first row key, the values of 742 * the second row key, and so on. 743 * 744 * @return collection of values 745 */ 746 @Override 747 public Collection<V> values() { 748 return super.values(); 749 } 750 751 @Override 752 Iterator<V> valuesIterator() { 753 return new AbstractIndexedListIterator<V>(size()) { 754 @Override 755 protected V get(int index) { 756 return getValue(index); 757 } 758 }; 759 } 760 761 private static final long serialVersionUID = 0; 762}