com.google.common.collect.Table.put()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(377)

本文整理了Java中com.google.common.collect.Table.put()方法的一些代码示例,展示了Table.put()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table.put()方法的具体详情如下:
包路径:com.google.common.collect.Table
类名称:Table
方法名:put

Table.put介绍

[英]Associates the specified value with the specified keys. If the table already contained a mapping for those keys, the old value is replaced with the specified value.
[中]将指定的值与指定的键相关联。如果表中已包含这些键的映射,则旧值将替换为指定值。

代码示例

代码示例来源:origin: google/guava

  1. void populateTable(Table<String, Integer, Character> table) {
  2. table.put("foo", 1, 'a');
  3. table.put("bar", 1, 'b');
  4. table.put("foo", 3, 'c');
  5. }

代码示例来源:origin: google/guava

  1. private static void populateForValues(
  2. Table<Integer, Character, String> table, String[] elements) {
  3. for (int i = 0; i < elements.length; i++) {
  4. table.put(i, 'a', elements[i]);
  5. }
  6. }

代码示例来源:origin: google/guava

  1. void put(R row, C column, V value, BinaryOperator<V> merger) {
  2. MutableCell<R, C, V> oldCell = table.get(row, column);
  3. if (oldCell == null) {
  4. MutableCell<R, C, V> cell = new MutableCell<>(row, column, value);
  5. insertionOrder.add(cell);
  6. table.put(row, column, cell);
  7. } else {
  8. oldCell.merge(value, merger);
  9. }
  10. }

代码示例来源:origin: google/guava

  1. @CanIgnoreReturnValue
  2. @Override
  3. public V put(R rowKey, C columnKey, V value) {
  4. return delegate().put(rowKey, columnKey, value);
  5. }

代码示例来源:origin: google/guava

  1. @Override
  2. protected Map<String, Map<Integer, Character>> makePopulatedMap() {
  3. Table<Integer, String, Character> table = makeTable();
  4. table.put(1, "foo", 'a');
  5. table.put(1, "bar", 'b');
  6. table.put(3, "foo", 'c');
  7. return table.columnMap();
  8. }

代码示例来源:origin: google/guava

  1. @Override
  2. protected Map<String, Integer> makePopulatedMap() {
  3. Table<Character, String, Integer> table = HashBasedTable.create();
  4. table.put('a', "one", 1);
  5. table.put('a', "two", 2);
  6. table.put('a', "three", 3);
  7. table.put('b', "four", 4);
  8. return Tables.unmodifiableTable(table).row('a');
  9. }
  10. }

代码示例来源:origin: google/guava

  1. @Override
  2. protected Map<String, Map<Integer, Character>> makePopulatedMap() {
  3. Table<Integer, String, Character> table = HashBasedTable.create();
  4. table.put(1, "foo", 'a');
  5. table.put(1, "bar", 'b');
  6. table.put(3, "foo", 'c');
  7. return Tables.unmodifiableTable(table).columnMap();
  8. }
  9. }

代码示例来源:origin: google/guava

  1. @Override
  2. protected Map<String, Map<Integer, Character>> makePopulatedMap() {
  3. Table<String, Integer, String> table = HashBasedTable.create();
  4. table.put("foo", 1, "apple");
  5. table.put("bar", 1, "banana");
  6. table.put("foo", 3, "cat");
  7. return Tables.transformValues(table, FIRST_CHARACTER).rowMap();
  8. }
  9. }

代码示例来源:origin: google/guava

  1. @Override
  2. protected Map<String, Map<Integer, Character>> makePopulatedMap() {
  3. Table<String, Integer, Character> table = HashBasedTable.create();
  4. table.put("foo", 1, 'a');
  5. table.put("bar", 1, 'b');
  6. table.put("foo", 3, 'c');
  7. return Tables.unmodifiableTable(table).rowMap();
  8. }
  9. }

代码示例来源:origin: google/guava

  1. @Override
  2. protected Map<String, Map<Integer, Character>> makePopulatedMap() {
  3. Table<Integer, String, String> table = HashBasedTable.create();
  4. table.put(1, "foo", "apple");
  5. table.put(1, "bar", "banana");
  6. table.put(3, "foo", "cat");
  7. return Tables.transformValues(table, FIRST_CHARACTER).columnMap();
  8. }
  9. }

代码示例来源:origin: google/guava

  1. @Override
  2. public V put(@Nullable R rowKey, @Nullable C columnKey, @Nullable V value) {
  3. synchronized (mutex) {
  4. return delegate().put(rowKey, columnKey, value);
  5. }
  6. }

代码示例来源:origin: google/guava

  1. public void testCreateExplicitComparators() {
  2. table = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString());
  3. table.put("foo", 3, 'a');
  4. table.put("foo", 12, 'b');
  5. table.put("bar", 5, 'c');
  6. table.put("cat", 8, 'd');
  7. assertThat(table.rowKeySet()).containsExactly("foo", "cat", "bar").inOrder();
  8. assertThat(table.row("foo").keySet()).containsExactly(12, 3).inOrder();
  9. }

代码示例来源:origin: google/guava

  1. public void testPutOriginalModifiesTranspose() {
  2. Table<Integer, String, Character> original = HashBasedTable.create();
  3. Table<String, Integer, Character> transpose = Tables.transpose(original);
  4. original.put(1, "foo", 'a');
  5. assertEquals((Character) 'a', transpose.get("foo", 1));
  6. }

代码示例来源:origin: google/guava

  1. @Override
  2. protected Collection<String> create(String[] elements) {
  3. Table<Integer, Character, String> table = HashBasedTable.create();
  4. table.put(1, 'a', "foo");
  5. table.clear();
  6. populateForValues(table, elements);
  7. return Tables.unmodifiableTable(table).values();
  8. }
  9. })

代码示例来源:origin: google/guava

  1. public void testIterationOrder() {
  2. Table<String, String, String> table = HashBasedTable.create();
  3. for (int i = 0; i < 5; i++) {
  4. table.put("r" + i, "c" + i, "v" + i);
  5. }
  6. assertThat(table.rowKeySet()).containsExactly("r0", "r1", "r2", "r3", "r4").inOrder();
  7. assertThat(table.columnKeySet()).containsExactly("c0", "c1", "c2", "c3", "c4").inOrder();
  8. assertThat(table.values()).containsExactly("v0", "v1", "v2", "v3", "v4").inOrder();
  9. }

代码示例来源:origin: google/guava

  1. @Override
  2. public Set<Cell<String, Integer, Character>> create(Object... elements) {
  3. Table<String, Integer, Character> table = createTable();
  4. for (Object element : elements) {
  5. @SuppressWarnings("unchecked")
  6. Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
  7. table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
  8. }
  9. return table.cellSet();
  10. }

代码示例来源:origin: google/guava

  1. @Override
  2. public Set<Cell<String, Integer, Character>> create(Object... elements) {
  3. Table<String, Integer, Character> table = HashBasedTable.create();
  4. for (Object element : elements) {
  5. @SuppressWarnings("unchecked")
  6. Cell<String, Integer, Character> cell =
  7. (Cell<String, Integer, Character>) element;
  8. table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
  9. }
  10. return Tables.unmodifiableTable(table).cellSet();
  11. }
  12. })

代码示例来源:origin: google/guava

  1. public void testCreateCopyArrayTable() {
  2. Table<String, Integer, Character> original =
  3. create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  4. Table<String, Integer, Character> copy = ArrayTable.create(original);
  5. assertEquals(original, copy);
  6. original.put("foo", 1, 'd');
  7. assertEquals((Character) 'd', original.get("foo", 1));
  8. assertEquals((Character) 'a', copy.get("foo", 1));
  9. assertEquals(copy.rowKeySet(), original.rowKeySet());
  10. assertEquals(copy.columnKeySet(), original.columnKeySet());
  11. }

代码示例来源:origin: google/guava

  1. public void testEqualsObject() {
  2. Table<Character, Integer, String> nonEmptyTable = HashBasedTable.create();
  3. nonEmptyTable.put('A', 1, "blah");
  4. new EqualsTester()
  5. .addEqualityGroup(INSTANCE, HashBasedTable.create(), TreeBasedTable.create())
  6. .addEqualityGroup(nonEmptyTable)
  7. .testEquals();
  8. }

代码示例来源:origin: google/guava

  1. @Override
  2. public Set<Cell<String, Integer, Character>> create(Object... elements) {
  3. Table<String, Integer, Character> table = createTable();
  4. for (Object element : elements) {
  5. @SuppressWarnings("unchecked")
  6. Cell<String, Integer, Character> cell =
  7. (Cell<String, Integer, Character>) element;
  8. table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
  9. }
  10. return Tables.transformValues(table, Functions.<Character>identity()).cellSet();
  11. }
  12. })

相关文章