package com.google.common.collect; import androidx.exifinterface.media.ExifInterface; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableTable; import com.google.common.collect.Table; import com.google.errorprone.annotations.Immutable; import java.lang.reflect.Array; import java.util.Map; import java.util.Objects; import javax.annotation.CheckForNull; /* JADX INFO: Access modifiers changed from: package-private */ @Immutable(containerOf = {"R", "C", ExifInterface.GPS_MEASUREMENT_INTERRUPTED}) @ElementTypesAreNonnullByDefault /* loaded from: classes3.dex */ public final class DenseImmutableTable extends RegularImmutableTable { private final int[] cellColumnIndices; private final int[] cellRowIndices; private final int[] columnCounts; private final ImmutableMap columnKeyToIndex; private final ImmutableMap> columnMap; private final int[] rowCounts; private final ImmutableMap rowKeyToIndex; private final ImmutableMap> rowMap; private final V[][] values; /* JADX INFO: Access modifiers changed from: package-private */ public DenseImmutableTable(ImmutableList> immutableList, ImmutableSet immutableSet, ImmutableSet immutableSet2) { this.values = (V[][]) ((Object[][]) Array.newInstance((Class) Object.class, immutableSet.size(), immutableSet2.size())); ImmutableMap indexMap = Maps.indexMap(immutableSet); this.rowKeyToIndex = indexMap; ImmutableMap indexMap2 = Maps.indexMap(immutableSet2); this.columnKeyToIndex = indexMap2; this.rowCounts = new int[indexMap.size()]; this.columnCounts = new int[indexMap2.size()]; int[] iArr = new int[immutableList.size()]; int[] iArr2 = new int[immutableList.size()]; for (int i = 0; i < immutableList.size(); i++) { Table.Cell cell = immutableList.get(i); R rowKey = cell.getRowKey(); C columnKey = cell.getColumnKey(); int intValue = ((Integer) Objects.requireNonNull(this.rowKeyToIndex.get(rowKey))).intValue(); int intValue2 = ((Integer) Objects.requireNonNull(this.columnKeyToIndex.get(columnKey))).intValue(); checkNoDuplicate(rowKey, columnKey, this.values[intValue][intValue2], cell.getValue()); this.values[intValue][intValue2] = cell.getValue(); int[] iArr3 = this.rowCounts; iArr3[intValue] = iArr3[intValue] + 1; int[] iArr4 = this.columnCounts; iArr4[intValue2] = iArr4[intValue2] + 1; iArr[i] = intValue; iArr2[i] = intValue2; } this.cellRowIndices = iArr; this.cellColumnIndices = iArr2; this.rowMap = new RowMap(); this.columnMap = new ColumnMap(); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public static abstract class ImmutableArrayMap extends ImmutableMap.IteratorBasedImmutableMap { private final int size; @CheckForNull abstract V getValue(int i); abstract ImmutableMap keyToIndex(); @Override // java.util.Map public int size() { return this.size; } ImmutableArrayMap(int i) { this.size = i; } private boolean isFull() { return this.size == keyToIndex().size(); } K getKey(int i) { return keyToIndex().keySet().asList().get(i); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap, com.google.common.collect.ImmutableMap public ImmutableSet createKeySet() { return isFull() ? keyToIndex().keySet() : super.createKeySet(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map @CheckForNull public V get(@CheckForNull Object obj) { Integer num = keyToIndex().get(obj); if (num == null) { return null; } return getValue(num.intValue()); } @Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap UnmodifiableIterator> entryIterator() { return new AbstractIterator>() { // from class: com.google.common.collect.DenseImmutableTable.ImmutableArrayMap.1 private int index = -1; private final int maxIndex; { this.maxIndex = ImmutableArrayMap.this.keyToIndex().size(); } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.AbstractIterator @CheckForNull public Map.Entry computeNext() { int i = this.index; while (true) { this.index = i + 1; int i2 = this.index; if (i2 < this.maxIndex) { Object value = ImmutableArrayMap.this.getValue(i2); if (value != null) { return Maps.immutableEntry(ImmutableArrayMap.this.getKey(this.index), value); } i = this.index; } else { return endOfData(); } } } }; } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public final class Row extends ImmutableArrayMap { private final int rowIndex; /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap public boolean isPartialView() { return true; } Row(int i) { super(DenseImmutableTable.this.rowCounts[i]); this.rowIndex = i; } @Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap ImmutableMap keyToIndex() { return DenseImmutableTable.this.columnKeyToIndex; } @Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap @CheckForNull V getValue(int i) { return (V) DenseImmutableTable.this.values[this.rowIndex][i]; } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public final class Column extends ImmutableArrayMap { private final int columnIndex; /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap public boolean isPartialView() { return true; } Column(int i) { super(DenseImmutableTable.this.columnCounts[i]); this.columnIndex = i; } @Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap ImmutableMap keyToIndex() { return DenseImmutableTable.this.rowKeyToIndex; } @Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap @CheckForNull V getValue(int i) { return (V) DenseImmutableTable.this.values[i][this.columnIndex]; } } /* loaded from: classes3.dex */ private final class RowMap extends ImmutableArrayMap> { /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap public boolean isPartialView() { return false; } private RowMap() { super(DenseImmutableTable.this.rowCounts.length); } @Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap ImmutableMap keyToIndex() { return DenseImmutableTable.this.rowKeyToIndex; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap public ImmutableMap getValue(int i) { return new Row(i); } } /* loaded from: classes3.dex */ private final class ColumnMap extends ImmutableArrayMap> { /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap public boolean isPartialView() { return false; } private ColumnMap() { super(DenseImmutableTable.this.columnCounts.length); } @Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap ImmutableMap keyToIndex() { return DenseImmutableTable.this.columnKeyToIndex; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap public ImmutableMap getValue(int i) { return new Column(i); } } @Override // com.google.common.collect.ImmutableTable, com.google.common.collect.Table public ImmutableMap> columnMap() { return ImmutableMap.copyOf((Map) this.columnMap); } @Override // com.google.common.collect.ImmutableTable, com.google.common.collect.Table public ImmutableMap> rowMap() { return ImmutableMap.copyOf((Map) this.rowMap); } @Override // com.google.common.collect.ImmutableTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table @CheckForNull public V get(@CheckForNull Object obj, @CheckForNull Object obj2) { Integer num = this.rowKeyToIndex.get(obj); Integer num2 = this.columnKeyToIndex.get(obj2); if (num == null || num2 == null) { return null; } return this.values[num.intValue()][num2.intValue()]; } @Override // com.google.common.collect.Table public int size() { return this.cellRowIndices.length; } @Override // com.google.common.collect.RegularImmutableTable Table.Cell getCell(int i) { int i2 = this.cellRowIndices[i]; int i3 = this.cellColumnIndices[i]; return cellOf(rowKeySet().asList().get(i2), columnKeySet().asList().get(i3), Objects.requireNonNull(this.values[i2][i3])); } @Override // com.google.common.collect.RegularImmutableTable V getValue(int i) { return (V) Objects.requireNonNull(this.values[this.cellRowIndices[i]][this.cellColumnIndices[i]]); } @Override // com.google.common.collect.ImmutableTable ImmutableTable.SerializedForm createSerializedForm() { return ImmutableTable.SerializedForm.create(this, this.cellRowIndices, this.cellColumnIndices); } }