下面列出了怎么用com.google.common.collect.Tables的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public Table<ResourceNamespace, ResourceType, ResourceValueMap> getConfiguredResources(
@NonNull FolderConfiguration referenceConfig) {
synchronized (ITEM_MAP_LOCK) {
Set<ResourceNamespace> namespaces = getNamespaces();
Map<ResourceNamespace, Map<ResourceType, ResourceValueMap>> backingMap;
if (KnownNamespacesMap.canContainAll(namespaces)) {
backingMap = new KnownNamespacesMap<>();
} else {
backingMap = new HashMap<>();
}
Table<ResourceNamespace, ResourceType, ResourceValueMap> table
= Tables.newCustomTable(backingMap, () -> new EnumMap<>(ResourceType.class));
for (ResourceNamespace namespace : namespaces) {
// TODO(namespaces): Move this method to ResourceResolverCache.
// For performance reasons don't mix framework and non-framework resources since
// they have different life spans.
for (ResourceType type : ResourceType.values()) {
// get the local results and put them in the map
table.put(
namespace,
type,
getConfiguredResources(namespace, type, referenceConfig));
}
}
return table;
}
}
@Override
public Set<Cell<R, C, V>> cellSet() {
return new AbstractSet<Cell<R, C, V>>() {
@Override
public int size() {
return TableView.this.size();
}
@Override
public boolean isEmpty() {
return TableView.this.isEmpty();
}
@Override
public boolean contains(Object o) {
if(!(o instanceof Cell)) return false;
final Cell cell = (Cell) o;
return Objects.equals(get(cell.getRowKey(), cell.getColumnKey()), cell.getValue());
}
@Override
public Stream<Cell<R, C, V>> stream() {
return map.entrySet()
.stream()
.flatMap(row -> row.getValue()
.entrySet()
.stream()
.map(col -> Tables.immutableCell(row.getKey(),
col.getKey(),
col.getValue())));
}
@Override
public Spliterator<Cell<R, C, V>> spliterator() {
return stream().spliterator();
}
@Override
public Iterator<Cell<R, C, V>> iterator() {
return Spliterators.iterator(spliterator());
}
};
}
@Override
public Table<Integer, String, Object> load(InlineTable inlineTable){
return Tables.unmodifiableTable(parse(inlineTable));
}
/**
* Returns an immutable copy of the input table that has been materialized in transposed form.
*
* <p>Use this instead of {@link Tables#transpose(Table)} if the result will be iterated on in
* row-major order. Transposing the table alone does not change the row-major vs column-major
* internal representation so the performance of row-oriented operations is abysmal. Instead, we
* need to actually materialize the transposed representation.
*/
public static <R, C, V> Table<C, R, V> transposeAndMaterialize(Table<R, C, V> edgeTable) {
return ImmutableTable.copyOf(Tables.transpose(edgeTable));
}