135 lines
5.5 KiB
Java
135 lines
5.5 KiB
Java
package com.google.common.collect;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.google.common.collect.Table;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
|
|
|
|
private final class CellSet extends ImmutableSet.Indexed<Table.Cell<R, C, V>> {
|
|
private CellSet() {
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
if (!(obj instanceof Table.Cell)) {
|
|
return false;
|
|
}
|
|
Table.Cell cell = (Table.Cell) obj;
|
|
Object obj2 = RegularImmutableTable.this.get(cell.b(), cell.a());
|
|
return obj2 != null && obj2.equals(cell.getValue());
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
boolean isPartialView() {
|
|
return false;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public int size() {
|
|
return RegularImmutableTable.this.size();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.ImmutableSet.Indexed
|
|
public Table.Cell<R, C, V> get(int i) {
|
|
return RegularImmutableTable.this.getCell(i);
|
|
}
|
|
}
|
|
|
|
private final class Values extends ImmutableList<V> {
|
|
private Values() {
|
|
}
|
|
|
|
@Override // java.util.List
|
|
public V get(int i) {
|
|
return (V) RegularImmutableTable.this.getValue(i);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
boolean isPartialView() {
|
|
return true;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
|
public int size() {
|
|
return RegularImmutableTable.this.size();
|
|
}
|
|
}
|
|
|
|
RegularImmutableTable() {
|
|
}
|
|
|
|
static <R, C, V> RegularImmutableTable<R, C, V> a(List<Table.Cell<R, C, V>> list, final Comparator<? super R> comparator, final Comparator<? super C> comparator2) {
|
|
Preconditions.a(list);
|
|
if (comparator != null || comparator2 != null) {
|
|
Collections.sort(list, new Comparator<Table.Cell<R, C, V>>() { // from class: com.google.common.collect.RegularImmutableTable.1
|
|
@Override // java.util.Comparator
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public int compare(Table.Cell<R, C, V> cell, Table.Cell<R, C, V> cell2) {
|
|
Comparator comparator3 = comparator;
|
|
int compare = comparator3 == null ? 0 : comparator3.compare(cell.b(), cell2.b());
|
|
if (compare != 0) {
|
|
return compare;
|
|
}
|
|
Comparator comparator4 = comparator2;
|
|
if (comparator4 == null) {
|
|
return 0;
|
|
}
|
|
return comparator4.compare(cell.a(), cell2.a());
|
|
}
|
|
});
|
|
}
|
|
return a((Iterable) list, (Comparator) comparator, (Comparator) comparator2);
|
|
}
|
|
|
|
abstract Table.Cell<R, C, V> getCell(int i);
|
|
|
|
abstract V getValue(int i);
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.ImmutableTable, com.google.common.collect.AbstractTable
|
|
public final ImmutableSet<Table.Cell<R, C, V>> createCellSet() {
|
|
return isEmpty() ? ImmutableSet.of() : new CellSet();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.ImmutableTable, com.google.common.collect.AbstractTable
|
|
public final ImmutableCollection<V> createValues() {
|
|
return isEmpty() ? ImmutableList.of() : new Values();
|
|
}
|
|
|
|
private static final <R, C, V> RegularImmutableTable<R, C, V> a(Iterable<Table.Cell<R, C, V>> iterable, Comparator<? super R> comparator, Comparator<? super C> comparator2) {
|
|
ImmutableSet copyOf;
|
|
ImmutableSet copyOf2;
|
|
LinkedHashSet linkedHashSet = new LinkedHashSet();
|
|
LinkedHashSet linkedHashSet2 = new LinkedHashSet();
|
|
ImmutableList copyOf3 = ImmutableList.copyOf(iterable);
|
|
for (Table.Cell<R, C, V> cell : iterable) {
|
|
linkedHashSet.add(cell.b());
|
|
linkedHashSet2.add(cell.a());
|
|
}
|
|
if (comparator == null) {
|
|
copyOf = ImmutableSet.copyOf((Collection) linkedHashSet);
|
|
} else {
|
|
copyOf = ImmutableSet.copyOf((Collection) ImmutableList.sortedCopyOf(comparator, linkedHashSet));
|
|
}
|
|
if (comparator2 == null) {
|
|
copyOf2 = ImmutableSet.copyOf((Collection) linkedHashSet2);
|
|
} else {
|
|
copyOf2 = ImmutableSet.copyOf((Collection) ImmutableList.sortedCopyOf(comparator2, linkedHashSet2));
|
|
}
|
|
return a(copyOf3, copyOf, copyOf2);
|
|
}
|
|
|
|
static <R, C, V> RegularImmutableTable<R, C, V> a(ImmutableList<Table.Cell<R, C, V>> immutableList, ImmutableSet<R> immutableSet, ImmutableSet<C> immutableSet2) {
|
|
return ((long) immutableList.size()) > (((long) immutableSet.size()) * ((long) immutableSet2.size())) / 2 ? new DenseImmutableTable(immutableList, immutableSet, immutableSet2) : new SparseImmutableTable(immutableList, immutableSet, immutableSet2);
|
|
}
|
|
}
|