@SuppressWarnings("unchecked") @Override Iterator<Cell<C, R, V>> cellIterator() { return Iterators.transform(original.cellSet().iterator(), (Function) TRANSPOSE_CELL); }
@Override public Set<Cell<R, C, V>> cellSet() { return delegate().cellSet(); }
@Override Iterator<Cell<R, C, V2>> cellIterator() { return Iterators.transform(fromTable.cellSet().iterator(), cellFunction()); }
/** * Returns an immutable copy of the provided table. * * <p>The {@link 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 control over the ordering, create a * {@link Builder} and call {@link Builder#orderRowsBy}, {@link Builder#orderColumnsBy}, and * {@link Builder#putAll} * * <p>Despite the method name, this method attempts to avoid actually copying the data when it is * safe to do so. The exact circumstances under which a copy will or will not be performed are * undocumented and subject to change. */ public static <R, C, V> ImmutableTable<R, C, V> copyOf( Table<? extends R, ? extends C, ? extends V> table) { if (table instanceof ImmutableTable) { @SuppressWarnings("unchecked") ImmutableTable<R, C, V> parameterizedTable = (ImmutableTable<R, C, V>) table; return parameterizedTable; } else { return copyOf(table.cellSet()); } }
@Override public Set<Cell<R, C, V>> cellSet() { assertTrue(Thread.holdsLock(mutex)); return delegate.cellSet(); }
@Override public Set<Cell<R, C, V>> cellSet() { synchronized (mutex) { return set(delegate().cellSet(), mutex); } }
@SuppressWarnings("unchecked") @Override Spliterator<Cell<C, R, V>> cellSpliterator() { return CollectSpliterators.map(original.cellSet().spliterator(), (Function) TRANSPOSE_CELL); } }
/** * Associates all of the given table's keys and values in the built table. Duplicate row key * column key pairs are not allowed, and will cause {@link #build} to fail. * * @throws NullPointerException if any key or value in {@code table} is null */ @CanIgnoreReturnValue public Builder<R, C, V> putAll(Table<? extends R, ? extends C, ? extends V> table) { for (Cell<? extends R, ? extends C, ? extends V> cell : table.cellSet()) { put(cell); } return this; }
@Override Spliterator<Cell<R, C, V2>> cellSpliterator() { return CollectSpliterators.map(fromTable.cellSet().spliterator(), cellFunction()); }
@Override public void putAll(Table<? extends R, ? extends C, ? extends V> table) { for (Table.Cell<? extends R, ? extends C, ? extends V> cell : table.cellSet()) { put(cell.getRowKey(), cell.getColumnKey(), cell.getValue()); } }
public void testCellSetToString_ordered() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); assertEquals( "[(foo,1)=a, (foo,2)=null, (foo,3)=c, " + "(bar,1)=b, (bar,2)=null, (bar,3)=null, " + "(cat,1)=null, (cat,2)=null, (cat,3)=null]", table.cellSet().toString()); }
public void testCellSetToString_ordered() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); assertEquals("[(bar,1)=b, (foo,1)=a, (foo,3)=c]", table.cellSet().toString()); }
public void testCellReflectsChanges() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Cell<String, Integer, Character> cell = table.cellSet().iterator().next(); assertEquals(Tables.immutableCell("foo", 1, 'a'), cell); assertEquals((Character) 'a', table.put("foo", 1, 'd')); assertEquals(Tables.immutableCell("foo", 1, 'd'), cell); }
@Override public Set<Cell<String, Integer, Character>> create(Object... elements) { Table<String, Integer, Character> table = createTable(); for (Object element : elements) { @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element; table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue()); } return table.cellSet(); }
@Override public Set<Cell<String, Integer, Character>> create(Object... elements) { List<Integer> columnKeys = Lists.newArrayList(); for (Object element : elements) { @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element; columnKeys.add(cell.getColumnKey()); } Table<String, Integer, Character> table = ArrayTable.create(ImmutableList.of("bar"), columnKeys); for (Object element : elements) { @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element; table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue()); } return table.cellSet(); }
private static <R, C, V> void validateViewOrdering(Table<R, C, V> original, Table<R, C, V> copy) { assertThat(copy.cellSet()).containsExactlyElementsIn(original.cellSet()).inOrder(); assertThat(copy.rowKeySet()).containsExactlyElementsIn(original.rowKeySet()).inOrder(); assertThat(copy.values()).containsExactlyElementsIn(original.values()).inOrder(); }
private static <R, C, V> void validateReserialization(Table<R, C, V> original) { Table<R, C, V> copy = SerializableTester.reserializeAndAssert(original); assertThat(copy.cellSet()).containsExactlyElementsIn(original.cellSet()).inOrder(); assertThat(copy.rowKeySet()).containsExactlyElementsIn(original.rowKeySet()).inOrder(); assertThat(copy.columnKeySet()).containsExactlyElementsIn(original.columnKeySet()).inOrder(); }
@Override public Set<Cell<String, Integer, Character>> create(Object... elements) { Table<String, Integer, Character> table = HashBasedTable.create(); for (Object element : elements) { @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element; table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue()); } return Tables.unmodifiableTable(table).cellSet(); } })
@Override public Set<Cell<String, Integer, Character>> create(Object... elements) { Table<String, Integer, Character> table = createTable(); for (Object element : elements) { @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element; table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue()); } return Tables.transformValues(table, Functions.<Character>identity()).cellSet(); } })