private static void populateForValues( Table<Integer, Character, String> table, String[] elements) { for (int i = 0; i < elements.length; i++) { table.put(i, 'a', elements[i]); } }
void put(R row, C column, V value, BinaryOperator<V> merger) { MutableCell<R, C, V> oldCell = table.get(row, column); if (oldCell == null) { MutableCell<R, C, V> cell = new MutableCell<>(row, column, value); insertionOrder.add(cell); table.put(row, column, cell); } else { oldCell.merge(value, merger); } }
@CanIgnoreReturnValue @Override public V put(R rowKey, C columnKey, V value) { return delegate().put(rowKey, columnKey, value); }
@Override protected Map<String, Map<Integer, Character>> makePopulatedMap() { Table<Integer, String, String> table = HashBasedTable.create(); table.put(1, "foo", "apple"); table.put(1, "bar", "banana"); table.put(3, "foo", "cat"); return Tables.transformValues(table, FIRST_CHARACTER).columnMap(); } }
@Override public V put(@Nullable R rowKey, @Nullable C columnKey, @Nullable V value) { synchronized (mutex) { return delegate().put(rowKey, columnKey, value); } }
public void testCreateExplicitComparators() { table = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); table.put("foo", 3, 'a'); table.put("foo", 12, 'b'); table.put("bar", 5, 'c'); table.put("cat", 8, 'd'); assertThat(table.rowKeySet()).containsExactly("foo", "cat", "bar").inOrder(); assertThat(table.row("foo").keySet()).containsExactly(12, 3).inOrder(); }
public void testPutOriginalModifiesTranspose() { Table<Integer, String, Character> original = HashBasedTable.create(); Table<String, Integer, Character> transpose = Tables.transpose(original); original.put(1, "foo", 'a'); assertEquals((Character) 'a', transpose.get("foo", 1)); }
@Override protected Collection<String> create(String[] elements) { Table<Integer, Character, String> table = HashBasedTable.create(); table.put(1, 'a', "foo"); table.clear(); populateForValues(table, elements); return Tables.unmodifiableTable(table).values(); } })
public void testIterationOrder() { Table<String, String, String> table = HashBasedTable.create(); for (int i = 0; i < 5; i++) { table.put("r" + i, "c" + i, "v" + i); } assertThat(table.rowKeySet()).containsExactly("r0", "r1", "r2", "r3", "r4").inOrder(); assertThat(table.columnKeySet()).containsExactly("c0", "c1", "c2", "c3", "c4").inOrder(); assertThat(table.values()).containsExactly("v0", "v1", "v2", "v3", "v4").inOrder(); }
@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) { 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(); } })
public void testCreateCopyArrayTable() { Table<String, Integer, Character> original = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Table<String, Integer, Character> copy = ArrayTable.create(original); assertEquals(original, copy); original.put("foo", 1, 'd'); assertEquals((Character) 'd', original.get("foo", 1)); assertEquals((Character) 'a', copy.get("foo", 1)); assertEquals(copy.rowKeySet(), original.rowKeySet()); assertEquals(copy.columnKeySet(), original.columnKeySet()); }
public void testEqualsObject() { Table<Character, Integer, String> nonEmptyTable = HashBasedTable.create(); nonEmptyTable.put('A', 1, "blah"); new EqualsTester() .addEqualityGroup(INSTANCE, HashBasedTable.create(), TreeBasedTable.create()) .addEqualityGroup(nonEmptyTable) .testEquals(); }
@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(); } })