MCPcopy Create free account
hub / github.com/antlr/codebuff / copyOf

Method copyOf

output/java_guava/1.4.18/ImmutableTable.java:74–99  ·  view source on GitHub ↗

Returns an immutable copy of the provided table. The Table#cellSet() iteration order of the provided table determines the iteration ordering of all views in the returned table. Note that some views of the original table and the copied table may have different iteration orders. For more c

(Table<? extends R, ? extends C, ? extends V> table)

Source from the content-addressed store, hash-verified

72
73
74 public static <R, C, V> ImmutableTable<R, C, V> copyOf(Table<? extends R, ? extends C, ? extends V> table) {
75 if (table instanceof ImmutableTable) {
76 @SuppressWarnings("unchecked")
77 ImmutableTable<R, C, V> parameterizedTable = (ImmutableTable<R, C, V>) table;
78 return parameterizedTable;
79 } else {
80 int size = table.size();
81 switch (size) {
82 case 0:
83 return of();
84 case 1:
85 Cell<? extends R, ? extends C, ? extends V> onlyCell = Iterables.getOnlyElement(table.cellSet());
86 return ImmutableTable.<R, C, V>of(onlyCell.getRowKey(), onlyCell.getColumnKey(), onlyCell.getValue());
87 default:
88 ImmutableSet.Builder<Cell<R, C, V>> cellSetBuilder = new ImmutableSet.Builder<Cell<R, C, V>>(size);
89 for (Cell<? extends R, ? extends C, ? extends V> cell : table.cellSet()) {
90 /*
91 * Must cast to be able to create a Cell<R, C, V> rather than a
92 * Cell<? extends R, ? extends C, ? extends V>
93 */
94 cellSetBuilder.add(cellOf((R) cell.getRowKey(), (C) cell.getColumnKey(), (V) cell.getValue()));
95 }
96 return RegularImmutableTable.forCells(cellSetBuilder.build());
97 }
98 }
99 }
100
101 /**
102 * Returns a new builder. The generated builder is equivalent to the builder

Callers

nothing calls this directly

Calls 11

ofMethod · 0.95
getOnlyElementMethod · 0.95
addMethod · 0.95
cellOfMethod · 0.95
forCellsMethod · 0.95
buildMethod · 0.95
sizeMethod · 0.65
cellSetMethod · 0.65
getRowKeyMethod · 0.65
getColumnKeyMethod · 0.65
getValueMethod · 0.65

Tested by

no test coverage detected