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

101 lines
4.0 KiB
Java

package com.google.common.collect;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Table;
import java.util.LinkedHashMap;
import java.util.Map;
/* loaded from: classes.dex */
final class SparseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> {
static final ImmutableTable<Object, Object, Object> e = new SparseImmutableTable(ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of());
private final ImmutableMap<R, Map<C, V>> a;
private final ImmutableMap<C, Map<R, V>> b;
private final int[] c;
private final int[] d;
SparseImmutableTable(ImmutableList<Table.Cell<R, C, V>> immutableList, ImmutableSet<R> immutableSet, ImmutableSet<C> immutableSet2) {
ImmutableMap a = Maps.a(immutableSet);
LinkedHashMap c = Maps.c();
UnmodifiableIterator<R> it = immutableSet.iterator();
while (it.hasNext()) {
c.put(it.next(), new LinkedHashMap());
}
LinkedHashMap c2 = Maps.c();
UnmodifiableIterator<C> it2 = immutableSet2.iterator();
while (it2.hasNext()) {
c2.put(it2.next(), new LinkedHashMap());
}
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 a2 = cell.a();
V value = cell.getValue();
iArr[i] = ((Integer) a.get(b)).intValue();
Map map = (Map) c.get(b);
iArr2[i] = map.size();
Object put = map.put(a2, value);
if (put != null) {
throw new IllegalArgumentException("Duplicate value for row=" + b + ", column=" + a2 + ": " + value + ", " + put);
}
((Map) c2.get(a2)).put(b, value);
}
this.c = iArr;
this.d = iArr2;
ImmutableMap.Builder builder = new ImmutableMap.Builder(c.size());
for (Map.Entry entry : c.entrySet()) {
builder.a(entry.getKey(), ImmutableMap.copyOf((Map) entry.getValue()));
}
this.a = builder.a();
ImmutableMap.Builder builder2 = new ImmutableMap.Builder(c2.size());
for (Map.Entry entry2 : c2.entrySet()) {
builder2.a(entry2.getKey(), ImmutableMap.copyOf((Map) entry2.getValue()));
}
this.b = builder2.a();
}
@Override // com.google.common.collect.ImmutableTable
ImmutableTable.SerializedForm createSerializedForm() {
ImmutableMap a = Maps.a(columnKeySet());
int[] iArr = new int[cellSet().size()];
UnmodifiableIterator<Table.Cell<R, C, V>> it = cellSet().iterator();
int i = 0;
while (it.hasNext()) {
iArr[i] = ((Integer) a.get(it.next().a())).intValue();
i++;
}
return ImmutableTable.SerializedForm.a(this, this.c, iArr);
}
@Override // com.google.common.collect.RegularImmutableTable
Table.Cell<R, C, V> getCell(int i) {
Map.Entry<R, Map<C, V>> entry = this.a.entrySet().asList().get(this.c[i]);
ImmutableMap immutableMap = (ImmutableMap) entry.getValue();
Map.Entry entry2 = (Map.Entry) immutableMap.entrySet().asList().get(this.d[i]);
return ImmutableTable.cellOf(entry.getKey(), entry2.getKey(), entry2.getValue());
}
@Override // com.google.common.collect.RegularImmutableTable
V getValue(int i) {
ImmutableMap immutableMap = (ImmutableMap) this.a.values().asList().get(this.c[i]);
return immutableMap.values().asList().get(this.d[i]);
}
@Override // com.google.common.collect.Table
public int size() {
return this.c.length;
}
@Override // com.google.common.collect.ImmutableTable, com.google.common.collect.Table
public ImmutableMap<C, Map<R, V>> columnMap() {
return this.b;
}
@Override // com.google.common.collect.ImmutableTable, com.google.common.collect.Table
public ImmutableMap<R, Map<C, V>> rowMap() {
return this.a;
}
}