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 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; private static abstract class ArrayMap extends Maps.IteratorBasedAbstractMap { private final ImmutableMap a; abstract V a(int i, V v); abstract String a(); Map.Entry a(final int i) { Preconditions.a(i, size()); return new AbstractMapEntry() { // 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> entryIterator() { return new AbstractIndexedListIterator>(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 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 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 immutableMap) { this.a = immutableMap; } } private class Column extends ArrayMap { 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> { @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 a(int i, Map map) { throw new UnsupportedOperationException(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ArrayTable.ArrayMap public Map c(int i) { return new Column(i); } public Map a(C c, Map map) { throw new UnsupportedOperationException(); } } private class Row extends ArrayMap { 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> { @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 a(int i, Map map) { throw new UnsupportedOperationException(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ArrayTable.ArrayMap public Map c(int i) { return new Row(i); } public Map a(R r, Map map) { throw new UnsupportedOperationException(); } } private ArrayTable(Iterable iterable, Iterable 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 ArrayTable create(Iterable iterable, Iterable iterable2) { return new ArrayTable<>(iterable, iterable2); } /* JADX INFO: Access modifiers changed from: private */ public Table.Cell getCell(final int i) { return new Tables.AbstractCell() { // 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> cellIterator() { return new AbstractIndexedListIterator>(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 a(int i) { return ArrayTable.this.getCell(i); } }; } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public Set> cellSet() { return super.cellSet(); } @Override // com.google.common.collect.AbstractTable @Deprecated public void clear() { throw new UnsupportedOperationException(); } public Map column(C c) { Preconditions.a(c); Integer num = this.columnKeyToIndex.get(c); return num == null ? ImmutableMap.of() : new Column(num.intValue()); } public ImmutableList columnKeyList() { return this.columnList; } @Override // com.google.common.collect.Table public Map> columnMap() { ArrayTable.ColumnMap columnMap = this.columnMap; if (columnMap != null) { return columnMap; } ArrayTable.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 table) { super.putAll(table); } @Override // com.google.common.collect.AbstractTable @Deprecated public V remove(Object obj, Object obj2) { throw new UnsupportedOperationException(); } public Map row(R r) { Preconditions.a(r); Integer num = this.rowKeyToIndex.get(r); return num == null ? ImmutableMap.of() : new Row(num.intValue()); } public ImmutableList rowKeyList() { return this.rowList; } @Override // com.google.common.collect.Table public Map> rowMap() { ArrayTable.RowMap rowMap = this.rowMap; if (rowMap != null) { return rowMap; } ArrayTable.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 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 values() { return super.values(); } @Override // com.google.common.collect.AbstractTable Iterator valuesIterator() { return new AbstractIndexedListIterator(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 ArrayTable create(Table 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 columnKeySet() { return this.columnKeyToIndex.keySet(); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public ImmutableSet rowKeySet() { return this.rowKeyToIndex.keySet(); } /* JADX WARN: Multi-variable type inference failed */ private ArrayTable(Table table) { this(table.rowKeySet(), table.columnKeySet()); putAll(table); } private ArrayTable(ArrayTable 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); } } }