本文整理了Java中com.google.common.collect.Table.row()
方法的一些代码示例,展示了Table.row()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table.row()
方法的具体详情如下:
包路径:com.google.common.collect.Table
类名称:Table
方法名:row
[英]Returns a view of all mappings that have the given row key. For each row key / column key / value mapping in the table with that row key, the returned map associates the column key with the value. If no mappings in the table have the provided row key, an empty map is returned.
Changes to the returned map will update the underlying table, and vice versa.
[中]返回具有给定行键的所有映射的视图。对于表中具有该行键的每个行键/列键/值映射,返回的映射将列键与值相关联。如果表中没有映射具有提供的行键,则返回空映射。
对返回映射的更改将更新基础表,反之亦然。
代码示例来源:origin: google/guava
@Override
public Map<C, V> column(R columnKey) {
return original.row(columnKey);
}
代码示例来源:origin: google/guava
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();
}
代码示例来源:origin: google/guava
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"));
}
}
代码示例来源:origin: google/guava
@Override
public Map<C, V2> row(R rowKey) {
return Maps.transformValues(fromTable.row(rowKey), function);
}
代码示例来源:origin: google/guava
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);
}
代码示例来源:origin: google/guava
@Override
public Map<C, V> row(R rowKey) {
return delegate().row(rowKey);
}
代码示例来源:origin: google/guava
@Override
public Map<C, V> row(R rowKey) {
assertTrue(Thread.holdsLock(mutex));
return delegate.row(rowKey);
}
代码示例来源:origin: google/guava
@Override
public Map<C, V> row(@Nullable R rowKey) {
synchronized (mutex) {
return map(delegate().row(rowKey), mutex);
}
}
代码示例来源:origin: google/guava
@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');
}
}
代码示例来源:origin: google/guava
@Override
protected Map<String, Integer> makeEmptyMap() {
return makeTable().row('a');
}
代码示例来源:origin: google/guava
@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');
}
}
代码示例来源:origin: google/guava
@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"));
}
代码示例来源:origin: google/guava
@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');
}
}
代码示例来源:origin: google/guava
public void testRow() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
assertEquals(ImmutableMap.of(1, 'a', 3, 'c'), table.row("foo"));
}
代码示例来源:origin: google/guava
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) {
}
}
代码示例来源:origin: google/guava
public void testRowOrdering() {
table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
assertThat(table.row("foo").keySet()).containsExactly(2, 3).inOrder();
}
}
代码示例来源:origin: google/guava
public void testRowNull() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
try {
table.row(null);
fail();
} catch (NullPointerException expected) {
}
}
代码示例来源:origin: google/guava
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]");
}
}
代码示例来源:origin: google/guava
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();
}
代码示例来源:origin: google/guava
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();
}
内容来源于网络,如有侵权,请联系作者删除!