jimu-decompiled/sources/com/google/common/collect/ArrayTable.java
2025-05-13 19:24:51 +02:00

530 lines
18 KiB
Java

package com.google.common.collect;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;
import com.google.common.collect.Tables;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/* loaded from: classes.dex */
public final class ArrayTable<R, C, V> extends AbstractTable<R, C, V> implements Serializable {
private static final long serialVersionUID = 0;
private final V[][] array;
private final ImmutableMap<C, Integer> columnKeyToIndex;
private final ImmutableList<C> columnList;
private transient ArrayTable<R, C, V>.ColumnMap columnMap;
private final ImmutableMap<R, Integer> rowKeyToIndex;
private final ImmutableList<R> rowList;
private transient ArrayTable<R, C, V>.RowMap rowMap;
private static abstract class ArrayMap<K, V> extends Maps.IteratorBasedAbstractMap<K, V> {
private final ImmutableMap<K, Integer> a;
abstract V a(int i, V v);
abstract String a();
Map.Entry<K, V> a(final int i) {
Preconditions.a(i, size());
return new AbstractMapEntry<K, V>() { // from class: com.google.common.collect.ArrayTable.ArrayMap.1
@Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry
public K getKey() {
return (K) ArrayMap.this.b(i);
}
@Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry
public V getValue() {
return (V) ArrayMap.this.c(i);
}
@Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry
public V setValue(V v) {
return (V) ArrayMap.this.a(i, v);
}
};
}
K b(int i) {
return this.a.keySet().asList().get(i);
}
abstract V c(int i);
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map
public void clear() {
throw new UnsupportedOperationException();
}
@Override // java.util.AbstractMap, java.util.Map
public boolean containsKey(Object obj) {
return this.a.containsKey(obj);
}
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap
Iterator<Map.Entry<K, V>> entryIterator() {
return new AbstractIndexedListIterator<Map.Entry<K, V>>(size()) { // from class: com.google.common.collect.ArrayTable.ArrayMap.2
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractIndexedListIterator
public Map.Entry<K, V> a(int i) {
return ArrayMap.this.a(i);
}
};
}
@Override // java.util.AbstractMap, java.util.Map
public V get(Object obj) {
Integer num = this.a.get(obj);
if (num == null) {
return null;
}
return c(num.intValue());
}
@Override // java.util.AbstractMap, java.util.Map
public boolean isEmpty() {
return this.a.isEmpty();
}
@Override // java.util.AbstractMap, java.util.Map
public Set<K> keySet() {
return this.a.keySet();
}
@Override // java.util.AbstractMap, java.util.Map
public V put(K k, V v) {
Integer num = this.a.get(k);
if (num != null) {
return a(num.intValue(), v);
}
throw new IllegalArgumentException(a() + " " + k + " not in " + this.a.keySet());
}
@Override // java.util.AbstractMap, java.util.Map
public V remove(Object obj) {
throw new UnsupportedOperationException();
}
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map
public int size() {
return this.a.size();
}
private ArrayMap(ImmutableMap<K, Integer> immutableMap) {
this.a = immutableMap;
}
}
private class Column extends ArrayMap<R, V> {
final int b;
Column(int i) {
super(ArrayTable.this.rowKeyToIndex);
this.b = i;
}
@Override // com.google.common.collect.ArrayTable.ArrayMap
V a(int i, V v) {
return (V) ArrayTable.this.set(i, this.b, v);
}
@Override // com.google.common.collect.ArrayTable.ArrayMap
String a() {
return "Row";
}
@Override // com.google.common.collect.ArrayTable.ArrayMap
V c(int i) {
return (V) ArrayTable.this.at(i, this.b);
}
}
private class ColumnMap extends ArrayMap<C, Map<R, V>> {
@Override // com.google.common.collect.ArrayTable.ArrayMap
/* bridge */ /* synthetic */ Object a(int i, Object obj) {
a(i, (Map) obj);
throw null;
}
@Override // com.google.common.collect.ArrayTable.ArrayMap
String a() {
return "Column";
}
@Override // com.google.common.collect.ArrayTable.ArrayMap, java.util.AbstractMap, java.util.Map
public /* bridge */ /* synthetic */ Object put(Object obj, Object obj2) {
a((ColumnMap) obj, (Map) obj2);
throw null;
}
private ColumnMap() {
super(ArrayTable.this.columnKeyToIndex);
}
Map<R, V> a(int i, Map<R, V> map) {
throw new UnsupportedOperationException();
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ArrayTable.ArrayMap
public Map<R, V> c(int i) {
return new Column(i);
}
public Map<R, V> a(C c, Map<R, V> map) {
throw new UnsupportedOperationException();
}
}
private class Row extends ArrayMap<C, V> {
final int b;
Row(int i) {
super(ArrayTable.this.columnKeyToIndex);
this.b = i;
}
@Override // com.google.common.collect.ArrayTable.ArrayMap
V a(int i, V v) {
return (V) ArrayTable.this.set(this.b, i, v);
}
@Override // com.google.common.collect.ArrayTable.ArrayMap
String a() {
return "Column";
}
@Override // com.google.common.collect.ArrayTable.ArrayMap
V c(int i) {
return (V) ArrayTable.this.at(this.b, i);
}
}
private class RowMap extends ArrayMap<R, Map<C, V>> {
@Override // com.google.common.collect.ArrayTable.ArrayMap
/* bridge */ /* synthetic */ Object a(int i, Object obj) {
a(i, (Map) obj);
throw null;
}
@Override // com.google.common.collect.ArrayTable.ArrayMap
String a() {
return "Row";
}
@Override // com.google.common.collect.ArrayTable.ArrayMap, java.util.AbstractMap, java.util.Map
public /* bridge */ /* synthetic */ Object put(Object obj, Object obj2) {
a((RowMap) obj, (Map) obj2);
throw null;
}
private RowMap() {
super(ArrayTable.this.rowKeyToIndex);
}
Map<C, V> a(int i, Map<C, V> map) {
throw new UnsupportedOperationException();
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ArrayTable.ArrayMap
public Map<C, V> c(int i) {
return new Row(i);
}
public Map<C, V> a(R r, Map<C, V> map) {
throw new UnsupportedOperationException();
}
}
private ArrayTable(Iterable<? extends R> iterable, Iterable<? extends C> iterable2) {
this.rowList = ImmutableList.copyOf(iterable);
this.columnList = ImmutableList.copyOf(iterable2);
Preconditions.a(!this.rowList.isEmpty());
Preconditions.a(!this.columnList.isEmpty());
this.rowKeyToIndex = Maps.a(this.rowList);
this.columnKeyToIndex = Maps.a(this.columnList);
this.array = (V[][]) ((Object[][]) Array.newInstance((Class<?>) Object.class, this.rowList.size(), this.columnList.size()));
eraseAll();
}
public static <R, C, V> ArrayTable<R, C, V> create(Iterable<? extends R> iterable, Iterable<? extends C> iterable2) {
return new ArrayTable<>(iterable, iterable2);
}
/* JADX INFO: Access modifiers changed from: private */
public Table.Cell<R, C, V> getCell(final int i) {
return new Tables.AbstractCell<R, C, V>() { // from class: com.google.common.collect.ArrayTable.2
final int a;
final int b;
{
this.a = i / ArrayTable.this.columnList.size();
this.b = i % ArrayTable.this.columnList.size();
}
@Override // com.google.common.collect.Table.Cell
public C a() {
return (C) ArrayTable.this.columnList.get(this.b);
}
@Override // com.google.common.collect.Table.Cell
public R b() {
return (R) ArrayTable.this.rowList.get(this.a);
}
@Override // com.google.common.collect.Table.Cell
public V getValue() {
return (V) ArrayTable.this.at(this.a, this.b);
}
};
}
/* JADX INFO: Access modifiers changed from: private */
public V getValue(int i) {
return at(i / this.columnList.size(), i % this.columnList.size());
}
public V at(int i, int i2) {
Preconditions.a(i, this.rowList.size());
Preconditions.a(i2, this.columnList.size());
return this.array[i][i2];
}
@Override // com.google.common.collect.AbstractTable
Iterator<Table.Cell<R, C, V>> cellIterator() {
return new AbstractIndexedListIterator<Table.Cell<R, C, V>>(size()) { // from class: com.google.common.collect.ArrayTable.1
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractIndexedListIterator
public Table.Cell<R, C, V> a(int i) {
return ArrayTable.this.getCell(i);
}
};
}
@Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table
public Set<Table.Cell<R, C, V>> cellSet() {
return super.cellSet();
}
@Override // com.google.common.collect.AbstractTable
@Deprecated
public void clear() {
throw new UnsupportedOperationException();
}
public Map<R, V> column(C c) {
Preconditions.a(c);
Integer num = this.columnKeyToIndex.get(c);
return num == null ? ImmutableMap.of() : new Column(num.intValue());
}
public ImmutableList<C> columnKeyList() {
return this.columnList;
}
@Override // com.google.common.collect.Table
public Map<C, Map<R, V>> columnMap() {
ArrayTable<R, C, V>.ColumnMap columnMap = this.columnMap;
if (columnMap != null) {
return columnMap;
}
ArrayTable<R, C, V>.ColumnMap columnMap2 = new ColumnMap();
this.columnMap = columnMap2;
return columnMap2;
}
@Override // com.google.common.collect.AbstractTable
public boolean contains(Object obj, Object obj2) {
return containsRow(obj) && containsColumn(obj2);
}
@Override // com.google.common.collect.AbstractTable
public boolean containsColumn(Object obj) {
return this.columnKeyToIndex.containsKey(obj);
}
@Override // com.google.common.collect.AbstractTable
public boolean containsRow(Object obj) {
return this.rowKeyToIndex.containsKey(obj);
}
@Override // com.google.common.collect.AbstractTable
public boolean containsValue(Object obj) {
for (V[] vArr : this.array) {
for (V v : vArr) {
if (Objects.a(obj, v)) {
return true;
}
}
}
return false;
}
@Override // com.google.common.collect.AbstractTable
public /* bridge */ /* synthetic */ boolean equals(Object obj) {
return super.equals(obj);
}
public V erase(Object obj, Object obj2) {
Integer num = this.rowKeyToIndex.get(obj);
Integer num2 = this.columnKeyToIndex.get(obj2);
if (num == null || num2 == null) {
return null;
}
return set(num.intValue(), num2.intValue(), null);
}
public void eraseAll() {
for (V[] vArr : this.array) {
Arrays.fill(vArr, (Object) null);
}
}
@Override // com.google.common.collect.AbstractTable
public V get(Object obj, Object obj2) {
Integer num = this.rowKeyToIndex.get(obj);
Integer num2 = this.columnKeyToIndex.get(obj2);
if (num == null || num2 == null) {
return null;
}
return at(num.intValue(), num2.intValue());
}
@Override // com.google.common.collect.AbstractTable
public /* bridge */ /* synthetic */ int hashCode() {
return super.hashCode();
}
@Override // com.google.common.collect.AbstractTable
public boolean isEmpty() {
return false;
}
@Override // com.google.common.collect.AbstractTable
public V put(R r, C c, V v) {
Preconditions.a(r);
Preconditions.a(c);
Integer num = this.rowKeyToIndex.get(r);
Preconditions.a(num != null, "Row %s not in %s", r, this.rowList);
Integer num2 = this.columnKeyToIndex.get(c);
Preconditions.a(num2 != null, "Column %s not in %s", c, this.columnList);
return set(num.intValue(), num2.intValue(), v);
}
@Override // com.google.common.collect.AbstractTable
public void putAll(Table<? extends R, ? extends C, ? extends V> table) {
super.putAll(table);
}
@Override // com.google.common.collect.AbstractTable
@Deprecated
public V remove(Object obj, Object obj2) {
throw new UnsupportedOperationException();
}
public Map<C, V> row(R r) {
Preconditions.a(r);
Integer num = this.rowKeyToIndex.get(r);
return num == null ? ImmutableMap.of() : new Row(num.intValue());
}
public ImmutableList<R> rowKeyList() {
return this.rowList;
}
@Override // com.google.common.collect.Table
public Map<R, Map<C, V>> rowMap() {
ArrayTable<R, C, V>.RowMap rowMap = this.rowMap;
if (rowMap != null) {
return rowMap;
}
ArrayTable<R, C, V>.RowMap rowMap2 = new RowMap();
this.rowMap = rowMap2;
return rowMap2;
}
public V set(int i, int i2, V v) {
Preconditions.a(i, this.rowList.size());
Preconditions.a(i2, this.columnList.size());
V[][] vArr = this.array;
V v2 = vArr[i][i2];
vArr[i][i2] = v;
return v2;
}
@Override // com.google.common.collect.Table
public int size() {
return this.rowList.size() * this.columnList.size();
}
public V[][] toArray(Class<V> cls) {
V[][] vArr = (V[][]) ((Object[][]) Array.newInstance((Class<?>) cls, this.rowList.size(), this.columnList.size()));
for (int i = 0; i < this.rowList.size(); i++) {
V[][] vArr2 = this.array;
System.arraycopy(vArr2[i], 0, vArr[i], 0, vArr2[i].length);
}
return vArr;
}
@Override // com.google.common.collect.AbstractTable
public /* bridge */ /* synthetic */ String toString() {
return super.toString();
}
@Override // com.google.common.collect.AbstractTable
public Collection<V> values() {
return super.values();
}
@Override // com.google.common.collect.AbstractTable
Iterator<V> valuesIterator() {
return new AbstractIndexedListIterator<V>(size()) { // from class: com.google.common.collect.ArrayTable.3
@Override // com.google.common.collect.AbstractIndexedListIterator
protected V a(int i) {
return (V) ArrayTable.this.getValue(i);
}
};
}
public static <R, C, V> ArrayTable<R, C, V> create(Table<R, C, V> table) {
return table instanceof ArrayTable ? new ArrayTable<>((ArrayTable) table) : new ArrayTable<>(table);
}
@Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table
public ImmutableSet<C> columnKeySet() {
return this.columnKeyToIndex.keySet();
}
@Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table
public ImmutableSet<R> rowKeySet() {
return this.rowKeyToIndex.keySet();
}
/* JADX WARN: Multi-variable type inference failed */
private ArrayTable(Table<R, C, V> table) {
this(table.rowKeySet(), table.columnKeySet());
putAll(table);
}
private ArrayTable(ArrayTable<R, C, V> arrayTable) {
this.rowList = arrayTable.rowList;
this.columnList = arrayTable.columnList;
this.rowKeyToIndex = arrayTable.rowKeyToIndex;
this.columnKeyToIndex = arrayTable.columnKeyToIndex;
V[][] vArr = (V[][]) ((Object[][]) Array.newInstance((Class<?>) Object.class, this.rowList.size(), this.columnList.size()));
this.array = vArr;
eraseAll();
for (int i = 0; i < this.rowList.size(); i++) {
V[][] vArr2 = arrayTable.array;
System.arraycopy(vArr2[i], 0, vArr[i], 0, vArr2[i].length);
}
}
}