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

254 lines
8.4 KiB
Java

package com.google.common.collect;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Table;
import java.lang.reflect.Array;
import java.util.Map;
/* loaded from: classes.dex */
final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> {
private final ImmutableMap<R, Integer> a;
private final ImmutableMap<C, Integer> b;
private final ImmutableMap<R, Map<C, V>> c;
private final ImmutableMap<C, Map<R, V>> d;
private final int[] e;
private final int[] f;
private final V[][] g;
private final int[] h;
private final int[] i;
private final class Column extends ImmutableArrayMap<R, V> {
private final int b;
Column(int i) {
super(DenseImmutableTable.this.f[i]);
this.b = i;
}
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
ImmutableMap<R, Integer> b() {
return DenseImmutableTable.this.a;
}
@Override // com.google.common.collect.ImmutableMap
boolean isPartialView() {
return true;
}
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
V b(int i) {
return (V) DenseImmutableTable.this.g[i][this.b];
}
}
private final class ColumnMap extends ImmutableArrayMap<C, Map<R, V>> {
@Override // com.google.common.collect.ImmutableMap
boolean isPartialView() {
return false;
}
private ColumnMap() {
super(DenseImmutableTable.this.f.length);
}
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
ImmutableMap<C, Integer> b() {
return DenseImmutableTable.this.b;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
public Map<R, V> b(int i) {
return new Column(i);
}
}
private static abstract class ImmutableArrayMap<K, V> extends ImmutableMap.IteratorBasedImmutableMap<K, V> {
private final int a;
ImmutableArrayMap(int i) {
this.a = i;
}
private boolean c() {
return this.a == b().size();
}
K a(int i) {
return b().keySet().asList().get(i);
}
abstract ImmutableMap<K, Integer> b();
abstract V b(int i);
@Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap, com.google.common.collect.ImmutableMap
ImmutableSet<K> createKeySet() {
return c() ? b().keySet() : super.createKeySet();
}
@Override // com.google.common.collect.ImmutableMap, java.util.Map
public V get(Object obj) {
Integer num = b().get(obj);
if (num == null) {
return null;
}
return b(num.intValue());
}
@Override // java.util.Map
public int size() {
return this.a;
}
@Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap
UnmodifiableIterator<Map.Entry<K, V>> a() {
return new AbstractIterator<Map.Entry<K, V>>() { // from class: com.google.common.collect.DenseImmutableTable.ImmutableArrayMap.1
private int c = -1;
private final int d;
{
this.d = ImmutableArrayMap.this.b().size();
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractIterator
public Map.Entry<K, V> a() {
int i = this.c;
while (true) {
this.c = i + 1;
int i2 = this.c;
if (i2 >= this.d) {
return b();
}
Object b = ImmutableArrayMap.this.b(i2);
if (b != null) {
return Maps.a(ImmutableArrayMap.this.a(this.c), b);
}
i = this.c;
}
}
};
}
}
private final class Row extends ImmutableArrayMap<C, V> {
private final int b;
Row(int i) {
super(DenseImmutableTable.this.e[i]);
this.b = i;
}
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
ImmutableMap<C, Integer> b() {
return DenseImmutableTable.this.b;
}
@Override // com.google.common.collect.ImmutableMap
boolean isPartialView() {
return true;
}
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
V b(int i) {
return (V) DenseImmutableTable.this.g[this.b][i];
}
}
private final class RowMap extends ImmutableArrayMap<R, Map<C, V>> {
@Override // com.google.common.collect.ImmutableMap
boolean isPartialView() {
return false;
}
private RowMap() {
super(DenseImmutableTable.this.e.length);
}
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
ImmutableMap<R, Integer> b() {
return DenseImmutableTable.this.a;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.DenseImmutableTable.ImmutableArrayMap
public Map<C, V> b(int i) {
return new Row(i);
}
}
DenseImmutableTable(ImmutableList<Table.Cell<R, C, V>> immutableList, ImmutableSet<R> immutableSet, ImmutableSet<C> immutableSet2) {
this.g = (V[][]) ((Object[][]) Array.newInstance((Class<?>) Object.class, immutableSet.size(), immutableSet2.size()));
this.a = Maps.a(immutableSet);
this.b = Maps.a(immutableSet2);
this.e = new int[this.a.size()];
this.f = new int[this.b.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 b = cell.b();
C a = cell.a();
int intValue = this.a.get(b).intValue();
int intValue2 = this.b.get(a).intValue();
Preconditions.a(this.g[intValue][intValue2] == null, "duplicate key: (%s, %s)", b, a);
this.g[intValue][intValue2] = cell.getValue();
int[] iArr3 = this.e;
iArr3[intValue] = iArr3[intValue] + 1;
int[] iArr4 = this.f;
iArr4[intValue2] = iArr4[intValue2] + 1;
iArr[i] = intValue;
iArr2[i] = intValue2;
}
this.h = iArr;
this.i = iArr2;
this.c = new RowMap();
this.d = new ColumnMap();
}
@Override // com.google.common.collect.ImmutableTable
ImmutableTable.SerializedForm createSerializedForm() {
return ImmutableTable.SerializedForm.a(this, this.h, this.i);
}
@Override // com.google.common.collect.ImmutableTable, com.google.common.collect.AbstractTable
public V get(Object obj, Object obj2) {
Integer num = this.a.get(obj);
Integer num2 = this.b.get(obj2);
if (num == null || num2 == null) {
return null;
}
return this.g[num.intValue()][num2.intValue()];
}
@Override // com.google.common.collect.RegularImmutableTable
Table.Cell<R, C, V> getCell(int i) {
int i2 = this.h[i];
int i3 = this.i[i];
return ImmutableTable.cellOf(rowKeySet().asList().get(i2), columnKeySet().asList().get(i3), this.g[i2][i3]);
}
@Override // com.google.common.collect.RegularImmutableTable
V getValue(int i) {
return this.g[this.h[i]][this.i[i]];
}
@Override // com.google.common.collect.Table
public int size() {
return this.h.length;
}
@Override // com.google.common.collect.ImmutableTable, com.google.common.collect.Table
public ImmutableMap<C, Map<R, V>> columnMap() {
return this.d;
}
@Override // com.google.common.collect.ImmutableTable, com.google.common.collect.Table
public ImmutableMap<R, Map<C, V>> rowMap() {
return this.c;
}
}