@Override public Map<C, V> column(R columnKey) { return original.row(columnKey); }
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 testTransposedViews() { Table<Integer, String, Character> original = HashBasedTable.create(); Table<String, Integer, Character> transpose = Tables.transpose(original); original.put(1, "foo", 'a'); assertSame(original.columnKeySet(), transpose.rowKeySet()); assertSame(original.rowKeySet(), transpose.columnKeySet()); assertSame(original.columnMap(), transpose.rowMap()); assertSame(original.rowMap(), transpose.columnMap()); assertSame(original.values(), transpose.values()); assertEquals(original.row(1), transpose.column(1)); assertEquals(original.row(2), transpose.column(2)); assertEquals(original.column("foo"), transpose.row("foo")); assertEquals(original.column("bar"), transpose.row("bar")); } }
@Override public Map<C, V2> row(R rowKey) { return Maps.transformValues(fromTable.row(rowKey), function); }
public void testCreateCopy() { TreeBasedTable<String, Integer, Character> original = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); original.put("foo", 3, 'a'); original.put("foo", 12, 'b'); original.put("bar", 5, 'c'); original.put("cat", 8, 'd'); table = TreeBasedTable.create(original); assertThat(table.rowKeySet()).containsExactly("foo", "cat", "bar").inOrder(); assertThat(table.row("foo").keySet()).containsExactly(12, 3).inOrder(); assertEquals(original, table); }
@Override public Map<C, V> row(R rowKey) { return delegate().row(rowKey); }
@Override public Map<C, V> row(R rowKey) { assertTrue(Thread.holdsLock(mutex)); return delegate.row(rowKey); }
@Override public Map<C, V> row(@Nullable R rowKey) { synchronized (mutex) { return map(delegate().row(rowKey), mutex); } }
@Override protected Map<String, Integer> makePopulatedMap() { Table<Character, String, Integer> table = makeTable(); table.put('a', "one", 1); table.put('a', "two", 2); table.put('a', "three", 3); table.put('b', "four", 4); return table.row('a'); } }
@Override protected Map<String, Integer> makeEmptyMap() { return makeTable().row('a'); }
@Override protected Map<String, Integer> makePopulatedMap() { Table<Character, String, Integer> table = HashBasedTable.create(); table.put('a', "one", 1); table.put('a', "two", 2); table.put('a', "three", 3); table.put('b', "four", 4); return Tables.unmodifiableTable(table).row('a'); } }
@Override public void testRow() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Map<Integer, Character> expected = Maps.newHashMap(); expected.put(1, 'a'); expected.put(3, 'c'); expected.put(2, null); assertEquals(expected, table.row("foo")); }
@Override protected Map<String, Integer> makePopulatedMap() { Table<Character, String, Integer> table = HashBasedTable.create(); table.put('a', "one", 2); table.put('a', "two", 4); table.put('a', "three", 6); table.put('b', "four", 8); return Tables.transformValues(table, DIVIDE_BY_2).row('a'); } }
public void testRow() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); assertEquals(ImmutableMap.of(1, 'a', 3, 'c'), table.row("foo")); }
public void testRowMissing() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Map<Integer, Character> row = table.row("dog"); assertTrue(row.isEmpty()); try { row.put(1, 'd'); fail(); } catch (UnsupportedOperationException expected) { } }
public void testRowOrdering() { table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c'); assertThat(table.row("foo").keySet()).containsExactly(2, 3).inOrder(); } }
public void testRowNull() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); try { table.row(null); fail(); } catch (NullPointerException expected) { } }
public void testRowPutIllegal() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Map<Integer, Character> map = table.row("foo"); try { map.put(4, 'd'); fail(); } catch (IllegalArgumentException expected) { assertThat(expected).hasMessageThat().isEqualTo("Column 4 not in [1, 2, 3]"); } }
public void testCopyOf() { Table<Character, Integer, String> table = TreeBasedTable.create(); validateTableCopies(table); table.put('b', 2, "foo"); validateTableCopies(table); table.put('b', 1, "bar"); table.put('a', 2, "baz"); validateTableCopies(table); // Even though rowKeySet, columnKeySet, and cellSet have the same // iteration ordering, row has an inconsistent ordering. assertThat(table.row('b').keySet()).containsExactly(1, 2).inOrder(); assertThat(ImmutableTable.copyOf(table).row('b').keySet()).containsExactly(2, 1).inOrder(); }
public void testBuilder_orderColumnsBy_dense() { ImmutableTable.Builder<Character, Integer, String> builder = ImmutableTable.builder(); builder.orderColumnsBy(Ordering.natural()); builder.put('c', 3, "foo"); builder.put('c', 2, "bar"); builder.put('c', 1, "baz"); builder.put('b', 3, "cat"); builder.put('b', 1, "dog"); builder.put('a', 3, "foo"); builder.put('a', 2, "bar"); builder.put('a', 1, "baz"); Table<Character, Integer, String> table = builder.build(); assertThat(table.columnKeySet()).containsExactly(1, 2, 3).inOrder(); assertThat(table.row('c').keySet()).containsExactly(1, 2, 3).inOrder(); }