Returns an immutable copy of the provided table. The Table#cellSet() iteration order of the provided table determines the iteration ordering of all views in the returned table. Note that some views of the original table and the copied table may have different iteration orders. For more c
(Table<? extends R, ? extends C, ? extends V> table)
| 72 | |
| 73 | |
| 74 | public static <R, C, V> ImmutableTable<R, C, V> copyOf(Table<? extends R, ? extends C, ? extends V> table) { |
| 75 | if (table instanceof ImmutableTable) { |
| 76 | @SuppressWarnings("unchecked") |
| 77 | ImmutableTable<R, C, V> parameterizedTable = (ImmutableTable<R, C, V>) table; |
| 78 | return parameterizedTable; |
| 79 | } else { |
| 80 | int size = table.size(); |
| 81 | switch (size) { |
| 82 | case 0: |
| 83 | return of(); |
| 84 | case 1: |
| 85 | Cell<? extends R, ? extends C, ? extends V> onlyCell = Iterables.getOnlyElement(table.cellSet()); |
| 86 | return ImmutableTable.<R, C, V>of(onlyCell.getRowKey(), onlyCell.getColumnKey(), onlyCell.getValue()); |
| 87 | default: |
| 88 | ImmutableSet.Builder<Cell<R, C, V>> cellSetBuilder = new ImmutableSet.Builder<Cell<R, C, V>>(size); |
| 89 | for (Cell<? extends R, ? extends C, ? extends V> cell : table.cellSet()) { |
| 90 | /* |
| 91 | * Must cast to be able to create a Cell<R, C, V> rather than a |
| 92 | * Cell<? extends R, ? extends C, ? extends V> |
| 93 | */ |
| 94 | cellSetBuilder.add(cellOf((R) cell.getRowKey(), (C) cell.getColumnKey(), (V) cell.getValue())); |
| 95 | } |
| 96 | return RegularImmutableTable.forCells(cellSetBuilder.build()); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns a new builder. The generated builder is equivalent to the builder |