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

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

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

Table.cellSet介绍

[英]Returns a set of all row key / column key / value triplets. Changes to the returned set will update the underlying table, and vice versa. The cell set does not support the add or addAll methods.
[中]返回所有行键/列键/值三元组的集合。对返回集的更改将更新基础表,反之亦然。单元格集不支持add或addAll方法。

代码示例

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

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. Iterator<Cell<C, R, V>> cellIterator() {
  4. return Iterators.transform(original.cellSet().iterator(), (Function) TRANSPOSE_CELL);
  5. }

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

  1. static boolean equalsImpl(Table<?, ?, ?> table, @Nullable Object obj) {
  2. if (obj == table) {
  3. return true;
  4. } else if (obj instanceof Table) {
  5. Table<?, ?, ?> that = (Table<?, ?, ?>) obj;
  6. return table.cellSet().equals(that.cellSet());
  7. } else {
  8. return false;
  9. }
  10. }
  11. }

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

  1. @Override
  2. public Set<Cell<R, C, V>> cellSet() {
  3. return delegate().cellSet();
  4. }

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

  1. @Override
  2. Iterator<Cell<R, C, V2>> cellIterator() {
  3. return Iterators.transform(fromTable.cellSet().iterator(), cellFunction());
  4. }

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

  1. /**
  2. * Returns an immutable copy of the provided table.
  3. *
  4. * <p>The {@link Table#cellSet()} iteration order of the provided table determines the iteration
  5. * ordering of all views in the returned table. Note that some views of the original table and the
  6. * copied table may have different iteration orders. For more control over the ordering, create a
  7. * {@link Builder} and call {@link Builder#orderRowsBy}, {@link Builder#orderColumnsBy}, and
  8. * {@link Builder#putAll}
  9. *
  10. * <p>Despite the method name, this method attempts to avoid actually copying the data when it is
  11. * safe to do so. The exact circumstances under which a copy will or will not be performed are
  12. * undocumented and subject to change.
  13. */
  14. public static <R, C, V> ImmutableTable<R, C, V> copyOf(
  15. Table<? extends R, ? extends C, ? extends V> table) {
  16. if (table instanceof ImmutableTable) {
  17. @SuppressWarnings("unchecked")
  18. ImmutableTable<R, C, V> parameterizedTable = (ImmutableTable<R, C, V>) table;
  19. return parameterizedTable;
  20. } else {
  21. return copyOf(table.cellSet());
  22. }
  23. }

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

  1. @Override
  2. public Set<Cell<R, C, V>> cellSet() {
  3. assertTrue(Thread.holdsLock(mutex));
  4. return delegate.cellSet();
  5. }

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

  1. @Override
  2. public Set<Cell<R, C, V>> cellSet() {
  3. synchronized (mutex) {
  4. return set(delegate().cellSet(), mutex);
  5. }
  6. }

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

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. Spliterator<Cell<C, R, V>> cellSpliterator() {
  4. return CollectSpliterators.map(original.cellSet().spliterator(), (Function) TRANSPOSE_CELL);
  5. }
  6. }

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

  1. /**
  2. * Associates all of the given table's keys and values in the built table. Duplicate row key
  3. * column key pairs are not allowed, and will cause {@link #build} to fail.
  4. *
  5. * @throws NullPointerException if any key or value in {@code table} is null
  6. */
  7. @CanIgnoreReturnValue
  8. public Builder<R, C, V> putAll(Table<? extends R, ? extends C, ? extends V> table) {
  9. for (Cell<? extends R, ? extends C, ? extends V> cell : table.cellSet()) {
  10. put(cell);
  11. }
  12. return this;
  13. }

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

  1. @Override
  2. Spliterator<Cell<R, C, V2>> cellSpliterator() {
  3. return CollectSpliterators.map(fromTable.cellSet().spliterator(), cellFunction());
  4. }

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

  1. @Override
  2. public void putAll(Table<? extends R, ? extends C, ? extends V> table) {
  3. for (Table.Cell<? extends R, ? extends C, ? extends V> cell : table.cellSet()) {
  4. put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
  5. }
  6. }

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

  1. public void testCellSetToString_ordered() {
  2. table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  3. assertEquals(
  4. "[(foo,1)=a, (foo,2)=null, (foo,3)=c, "
  5. + "(bar,1)=b, (bar,2)=null, (bar,3)=null, "
  6. + "(cat,1)=null, (cat,2)=null, (cat,3)=null]",
  7. table.cellSet().toString());
  8. }

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

  1. public void testCellSetToString_ordered() {
  2. table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  3. assertEquals("[(bar,1)=b, (foo,1)=a, (foo,3)=c]", table.cellSet().toString());
  4. }

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

  1. public void testCellReflectsChanges() {
  2. table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  3. Cell<String, Integer, Character> cell = table.cellSet().iterator().next();
  4. assertEquals(Tables.immutableCell("foo", 1, 'a'), cell);
  5. assertEquals((Character) 'a', table.put("foo", 1, 'd'));
  6. assertEquals(Tables.immutableCell("foo", 1, 'd'), cell);
  7. }

代码示例来源: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. List<Integer> columnKeys = Lists.newArrayList();
  4. for (Object element : elements) {
  5. @SuppressWarnings("unchecked")
  6. Cell<String, Integer, Character> cell =
  7. (Cell<String, Integer, Character>) element;
  8. columnKeys.add(cell.getColumnKey());
  9. }
  10. Table<String, Integer, Character> table =
  11. ArrayTable.create(ImmutableList.of("bar"), columnKeys);
  12. for (Object element : elements) {
  13. @SuppressWarnings("unchecked")
  14. Cell<String, Integer, Character> cell =
  15. (Cell<String, Integer, Character>) element;
  16. table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
  17. }
  18. return table.cellSet();
  19. }

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

  1. private static <R, C, V> void validateViewOrdering(Table<R, C, V> original, Table<R, C, V> copy) {
  2. assertThat(copy.cellSet()).containsExactlyElementsIn(original.cellSet()).inOrder();
  3. assertThat(copy.rowKeySet()).containsExactlyElementsIn(original.rowKeySet()).inOrder();
  4. assertThat(copy.values()).containsExactlyElementsIn(original.values()).inOrder();
  5. }

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

  1. private static <R, C, V> void validateReserialization(Table<R, C, V> original) {
  2. Table<R, C, V> copy = SerializableTester.reserializeAndAssert(original);
  3. assertThat(copy.cellSet()).containsExactlyElementsIn(original.cellSet()).inOrder();
  4. assertThat(copy.rowKeySet()).containsExactlyElementsIn(original.rowKeySet()).inOrder();
  5. assertThat(copy.columnKeySet()).containsExactlyElementsIn(original.columnKeySet()).inOrder();
  6. }

代码示例来源: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. @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. })

相关文章