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: classes2.dex */ public final class ArrayTable extends AbstractTable implements Serializable { private static final long serialVersionUID = 0; private final V[][] array; private final ImmutableMap columnKeyToIndex; private final ImmutableList columnList; private transient ArrayTable.ColumnMap columnMap; private final ImmutableMap rowKeyToIndex; private final ImmutableList rowList; private transient ArrayTable.RowMap rowMap; @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final /* bridge */ /* synthetic */ boolean equals(Object obj) { return super.equals(obj); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final /* bridge */ /* synthetic */ int hashCode() { return super.hashCode(); } @Override // com.google.common.collect.AbstractTable public final /* bridge */ /* synthetic */ String toString() { return super.toString(); } public static ArrayTable create(Iterable iterable, Iterable iterable2) { return new ArrayTable<>(iterable, iterable2); } public static ArrayTable create(Table table) { if (table instanceof ArrayTable) { return new ArrayTable<>((ArrayTable) table); } return new ArrayTable<>(table); } private ArrayTable(Iterable iterable, Iterable iterable2) { ImmutableList copyOf = ImmutableList.copyOf(iterable); this.rowList = copyOf; ImmutableList copyOf2 = ImmutableList.copyOf(iterable2); this.columnList = copyOf2; Preconditions.checkArgument(copyOf.isEmpty() == copyOf2.isEmpty()); this.rowKeyToIndex = Maps.indexMap(copyOf); this.columnKeyToIndex = Maps.indexMap(copyOf2); this.array = (V[][]) ((Object[][]) Array.newInstance((Class) Object.class, copyOf.size(), copyOf2.size())); eraseAll(); } /* JADX WARN: Multi-variable type inference failed */ private ArrayTable(Table table) { this(table.rowKeySet(), table.columnKeySet()); putAll(table); } private ArrayTable(ArrayTable arrayTable) { ImmutableList immutableList = arrayTable.rowList; this.rowList = immutableList; ImmutableList immutableList2 = arrayTable.columnList; this.columnList = immutableList2; this.rowKeyToIndex = arrayTable.rowKeyToIndex; this.columnKeyToIndex = arrayTable.columnKeyToIndex; V[][] vArr = (V[][]) ((Object[][]) Array.newInstance((Class) Object.class, immutableList.size(), immutableList2.size())); this.array = vArr; for (int i = 0; i < this.rowList.size(); i++) { V[] vArr2 = arrayTable.array[i]; System.arraycopy(vArr2, 0, vArr[i], 0, vArr2.length); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static abstract class ArrayMap extends Maps.IteratorBasedAbstractMap { private final ImmutableMap keyIndex; abstract String getKeyRole(); abstract V getValue(int i); abstract V setValue(int i, V v); private ArrayMap(ImmutableMap immutableMap) { this.keyIndex = immutableMap; } @Override // java.util.AbstractMap, java.util.Map public Set keySet() { return this.keyIndex.keySet(); } K getKey(int i) { return this.keyIndex.keySet().asList().get(i); } @Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map public int size() { return this.keyIndex.size(); } @Override // java.util.AbstractMap, java.util.Map public boolean isEmpty() { return this.keyIndex.isEmpty(); } Map.Entry getEntry(int i) { Preconditions.checkElementIndex(i, size()); return new AbstractMapEntry(this, i) { // from class: com.google.common.collect.ArrayTable.ArrayMap.1 final ArrayMap this$0; final int val$index; { this.this$0 = this; this.val$index = i; } @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public K getKey() { return (K) this.this$0.getKey(this.val$index); } @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public V getValue() { return (V) this.this$0.getValue(this.val$index); } @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public V setValue(V v) { return (V) this.this$0.setValue(this.val$index, v); } }; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.Maps.IteratorBasedAbstractMap public Iterator> entryIterator() { return new AbstractIndexedListIterator>(this, size()) { // from class: com.google.common.collect.ArrayTable.ArrayMap.2 final ArrayMap this$0; { this.this$0 = this; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.AbstractIndexedListIterator public Map.Entry get(int i) { return this.this$0.getEntry(i); } }; } @Override // java.util.AbstractMap, java.util.Map public boolean containsKey(Object obj) { return this.keyIndex.containsKey(obj); } @Override // java.util.AbstractMap, java.util.Map public V get(Object obj) { Integer num = this.keyIndex.get(obj); if (num == null) { return null; } return getValue(num.intValue()); } @Override // java.util.AbstractMap, java.util.Map public V put(K k, V v) { Integer num = this.keyIndex.get(k); if (num == null) { String keyRole = getKeyRole(); String valueOf = String.valueOf(k); String valueOf2 = String.valueOf(this.keyIndex.keySet()); StringBuilder sb = new StringBuilder(String.valueOf(keyRole).length() + 9 + String.valueOf(valueOf).length() + String.valueOf(valueOf2).length()); sb.append(keyRole); sb.append(" "); sb.append(valueOf); sb.append(" not in "); sb.append(valueOf2); throw new IllegalArgumentException(sb.toString()); } return setValue(num.intValue(), v); } @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 void clear() { throw new UnsupportedOperationException(); } } public final V at(int i, int i2) { Preconditions.checkElementIndex(i, this.rowList.size()); Preconditions.checkElementIndex(i2, this.columnList.size()); return this.array[i][i2]; } public final V set(int i, int i2, V v) { Preconditions.checkElementIndex(i, this.rowList.size()); Preconditions.checkElementIndex(i2, this.columnList.size()); V[] vArr = this.array[i]; V v2 = vArr[i2]; vArr[i2] = v; return v2; } public final V[][] toArray(Class 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[i]; System.arraycopy(vArr2, 0, vArr[i], 0, vArr2.length); } return vArr; } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table @Deprecated public final void clear() { throw new UnsupportedOperationException(); } public final void eraseAll() { for (V[] vArr : this.array) { Arrays.fill(vArr, (Object) null); } } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final boolean contains(Object obj, Object obj2) { return containsRow(obj) && containsColumn(obj2); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final boolean containsColumn(Object obj) { return this.columnKeyToIndex.containsKey(obj); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final boolean containsRow(Object obj) { return this.rowKeyToIndex.containsKey(obj); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final boolean containsValue(Object obj) { for (V[] vArr : this.array) { for (V v : vArr) { if (Objects.equal(obj, v)) { return true; } } } return false; } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final 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, com.google.common.collect.Table public final boolean isEmpty() { return this.rowList.isEmpty() || this.columnList.isEmpty(); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final V put(R r, C c, V v) { Preconditions.checkNotNull(r); Preconditions.checkNotNull(c); Integer num = this.rowKeyToIndex.get(r); Preconditions.checkArgument(num != null, "Row %s not in %s", r, this.rowList); Integer num2 = this.columnKeyToIndex.get(c); Preconditions.checkArgument(num2 != null, "Column %s not in %s", c, this.columnList); return set(num.intValue(), num2.intValue(), v); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final void putAll(Table table) { super.putAll(table); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table @Deprecated public final V remove(Object obj, Object obj2) { throw new UnsupportedOperationException(); } public final 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); } @Override // com.google.common.collect.Table public final int size() { return this.rowList.size() * this.columnList.size(); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final Set> cellSet() { return super.cellSet(); } @Override // com.google.common.collect.AbstractTable final Iterator> cellIterator() { return new AbstractIndexedListIterator>(this, size()) { // from class: com.google.common.collect.ArrayTable.1 final ArrayTable this$0; { this.this$0 = this; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.AbstractIndexedListIterator public Table.Cell get(int i) { return this.this$0.getCell(i); } }; } /* JADX INFO: Access modifiers changed from: private */ public Table.Cell getCell(int i) { return new Tables.AbstractCell(this, i) { // from class: com.google.common.collect.ArrayTable.2 final int columnIndex; final int rowIndex; final ArrayTable this$0; final int val$index; { this.this$0 = this; this.val$index = i; this.rowIndex = i / this.columnList.size(); this.columnIndex = i % this.columnList.size(); } @Override // com.google.common.collect.Table.Cell public R getRowKey() { return (R) this.this$0.rowList.get(this.rowIndex); } @Override // com.google.common.collect.Table.Cell public C getColumnKey() { return (C) this.this$0.columnList.get(this.columnIndex); } @Override // com.google.common.collect.Table.Cell public V getValue() { return (V) this.this$0.at(this.rowIndex, this.columnIndex); } }; } /* JADX INFO: Access modifiers changed from: private */ public V getValue(int i) { return at(i / this.columnList.size(), i % this.columnList.size()); } @Override // com.google.common.collect.Table public final Map column(C c) { Preconditions.checkNotNull(c); Integer num = this.columnKeyToIndex.get(c); return num == null ? ImmutableMap.of() : new Column(this, num.intValue()); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public class Column extends ArrayMap { final int columnIndex; final ArrayTable this$0; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ Column(ArrayTable arrayTable, int i) { super(arrayTable.rowKeyToIndex); this.this$0 = arrayTable; this.columnIndex = i; } @Override // com.google.common.collect.ArrayTable.ArrayMap V getValue(int i) { return (V) this.this$0.at(i, this.columnIndex); } @Override // com.google.common.collect.ArrayTable.ArrayMap V setValue(int i, V v) { return (V) this.this$0.set(i, this.columnIndex, v); } @Override // com.google.common.collect.ArrayTable.ArrayMap String getKeyRole() { return "Row"; } } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final ImmutableSet columnKeySet() { return this.columnKeyToIndex.keySet(); } @Override // com.google.common.collect.Table public final Map> columnMap() { ArrayTable.ColumnMap columnMap = this.columnMap; if (columnMap != null) { return columnMap; } ArrayTable.ColumnMap columnMap2 = new ColumnMap(); this.columnMap = columnMap2; return columnMap2; } /* loaded from: classes2.dex */ class ColumnMap extends ArrayMap> { final ArrayTable this$0; @Override // com.google.common.collect.ArrayTable.ArrayMap, java.util.AbstractMap, java.util.Map public /* bridge */ /* synthetic */ Object put(Object obj, Object obj2) { return put((ColumnMap) obj, (Map) obj2); } /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ private ColumnMap(ArrayTable arrayTable) { super(arrayTable.columnKeyToIndex); this.this$0 = arrayTable; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ArrayTable.ArrayMap public Map getValue(int i) { return new Column(this.this$0, i); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ArrayTable.ArrayMap public Map setValue(int i, Map map) { throw new UnsupportedOperationException(); } public Map put(C c, Map map) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ArrayTable.ArrayMap String getKeyRole() { return "Column"; } } @Override // com.google.common.collect.Table public final Map row(R r) { Preconditions.checkNotNull(r); Integer num = this.rowKeyToIndex.get(r); return num == null ? ImmutableMap.of() : new Row(this, num.intValue()); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public class Row extends ArrayMap { final int rowIndex; final ArrayTable this$0; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ Row(ArrayTable arrayTable, int i) { super(arrayTable.columnKeyToIndex); this.this$0 = arrayTable; this.rowIndex = i; } @Override // com.google.common.collect.ArrayTable.ArrayMap V getValue(int i) { return (V) this.this$0.at(this.rowIndex, i); } @Override // com.google.common.collect.ArrayTable.ArrayMap V setValue(int i, V v) { return (V) this.this$0.set(this.rowIndex, i, v); } @Override // com.google.common.collect.ArrayTable.ArrayMap String getKeyRole() { return "Column"; } } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final ImmutableSet rowKeySet() { return this.rowKeyToIndex.keySet(); } @Override // com.google.common.collect.Table public final Map> rowMap() { ArrayTable.RowMap rowMap = this.rowMap; if (rowMap != null) { return rowMap; } ArrayTable.RowMap rowMap2 = new RowMap(); this.rowMap = rowMap2; return rowMap2; } /* loaded from: classes2.dex */ class RowMap extends ArrayMap> { final ArrayTable this$0; @Override // com.google.common.collect.ArrayTable.ArrayMap, java.util.AbstractMap, java.util.Map public /* bridge */ /* synthetic */ Object put(Object obj, Object obj2) { return put((RowMap) obj, (Map) obj2); } /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ private RowMap(ArrayTable arrayTable) { super(arrayTable.rowKeyToIndex); this.this$0 = arrayTable; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ArrayTable.ArrayMap public Map getValue(int i) { return new Row(this.this$0, i); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ArrayTable.ArrayMap public Map setValue(int i, Map map) { throw new UnsupportedOperationException(); } public Map put(R r, Map map) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ArrayTable.ArrayMap String getKeyRole() { return "Row"; } } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public final Collection values() { return super.values(); } @Override // com.google.common.collect.AbstractTable final Iterator valuesIterator() { return new AbstractIndexedListIterator(this, size()) { // from class: com.google.common.collect.ArrayTable.3 final ArrayTable this$0; { this.this$0 = this; } @Override // com.google.common.collect.AbstractIndexedListIterator protected V get(int i) { return (V) this.this$0.getValue(i); } }; } public final ImmutableList rowKeyList() { return this.rowList; } public final ImmutableList columnKeyList() { return this.columnList; } }