Rabbit-R1/switch port/java/sources/com/google/common/collect/DenseImmutableTable.java
2024-05-21 17:08:36 -04:00

282 lines
11 KiB
Java

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<R, C, V> extends RegularImmutableTable<R, C, V> {
private final int[] cellColumnIndices;
private final int[] cellRowIndices;
private final int[] columnCounts;
private final ImmutableMap<C, Integer> columnKeyToIndex;
private final ImmutableMap<C, ImmutableMap<R, V>> columnMap;
private final int[] rowCounts;
private final ImmutableMap<R, Integer> rowKeyToIndex;
private final ImmutableMap<R, ImmutableMap<C, V>> rowMap;
private final V[][] values;
/* JADX INFO: Access modifiers changed from: package-private */
public DenseImmutableTable(ImmutableList<Table.Cell<R, C, V>> immutableList, ImmutableSet<R> immutableSet, ImmutableSet<C> immutableSet2) {
this.values = (V[][]) ((Object[][]) Array.newInstance((Class<?>) Object.class, immutableSet.size(), immutableSet2.size()));
ImmutableMap<R, Integer> indexMap = Maps.indexMap(immutableSet);
this.rowKeyToIndex = indexMap;
ImmutableMap<C, Integer> 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<R, C, V> 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<K, V> extends ImmutableMap.IteratorBasedImmutableMap<K, V> {
private final int size;
@CheckForNull
abstract V getValue(int i);
abstract ImmutableMap<K, Integer> 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<K> 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<Map.Entry<K, V>> entryIterator() {
return new AbstractIterator<Map.Entry<K, V>>() { // 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<K, V> 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<C, V> {
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<C, Integer> 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<R, V> {
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<R, Integer> 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<R, ImmutableMap<C, V>> {
/* 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<R, Integer> keyToIndex() {
return DenseImmutableTable.this.rowKeyToIndex;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
public ImmutableMap<C, V> getValue(int i) {
return new Row(i);
}
}
/* loaded from: classes3.dex */
private final class ColumnMap extends ImmutableArrayMap<C, ImmutableMap<R, V>> {
/* 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<C, Integer> keyToIndex() {
return DenseImmutableTable.this.columnKeyToIndex;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
public ImmutableMap<R, V> getValue(int i) {
return new Column(i);
}
}
@Override // com.google.common.collect.ImmutableTable, com.google.common.collect.Table
public ImmutableMap<C, Map<R, V>> columnMap() {
return ImmutableMap.copyOf((Map) this.columnMap);
}
@Override // com.google.common.collect.ImmutableTable, com.google.common.collect.Table
public ImmutableMap<R, Map<C, V>> 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<R, C, V> 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);
}
}