164 lines
7.0 KiB
Java
164 lines
7.0 KiB
Java
package com.google.common.collect;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
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;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes2.dex */
|
|
public abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
|
|
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 */
|
|
/* loaded from: classes2.dex */
|
|
public final class CellSet extends IndexedImmutableSet<Table.Cell<R, C, V>> {
|
|
final RegularImmutableTable this$0;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
public final boolean isPartialView() {
|
|
return false;
|
|
}
|
|
|
|
private CellSet(RegularImmutableTable regularImmutableTable) {
|
|
this.this$0 = regularImmutableTable;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public final int size() {
|
|
return this.this$0.size();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.IndexedImmutableSet
|
|
public final Table.Cell<R, C, V> get(int i) {
|
|
return this.this$0.getCell(i);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public final boolean contains(Object obj) {
|
|
if (!(obj instanceof Table.Cell)) {
|
|
return false;
|
|
}
|
|
Table.Cell cell = (Table.Cell) obj;
|
|
Object obj2 = this.this$0.get(cell.getRowKey(), cell.getColumnKey());
|
|
return obj2 != null && obj2.equals(cell.getValue());
|
|
}
|
|
}
|
|
|
|
/* 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();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes2.dex */
|
|
public final class Values extends ImmutableList<V> {
|
|
final RegularImmutableTable this$0;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
public final boolean isPartialView() {
|
|
return true;
|
|
}
|
|
|
|
private Values(RegularImmutableTable regularImmutableTable) {
|
|
this.this$0 = regularImmutableTable;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
|
public final int size() {
|
|
return this.this$0.size();
|
|
}
|
|
|
|
@Override // java.util.List
|
|
public final V get(int i) {
|
|
return (V) this.this$0.getValue(i);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static <R, C, V> RegularImmutableTable<R, C, V> forCells(List<Table.Cell<R, C, V>> list, Comparator<? super R> comparator, Comparator<? super C> comparator2) {
|
|
Preconditions.checkNotNull(list);
|
|
if (comparator != null || comparator2 != null) {
|
|
Collections.sort(list, new Comparator<Table.Cell<R, C, V>>(comparator, comparator2) { // from class: com.google.common.collect.RegularImmutableTable.1
|
|
final Comparator val$columnComparator;
|
|
final Comparator val$rowComparator;
|
|
|
|
{
|
|
this.val$rowComparator = comparator;
|
|
this.val$columnComparator = comparator2;
|
|
}
|
|
|
|
@Override // java.util.Comparator
|
|
public int compare(Table.Cell<R, C, V> cell, Table.Cell<R, C, V> cell2) {
|
|
Comparator comparator3 = this.val$rowComparator;
|
|
int compare = comparator3 == null ? 0 : comparator3.compare(cell.getRowKey(), cell2.getRowKey());
|
|
if (compare != 0) {
|
|
return compare;
|
|
}
|
|
Comparator comparator4 = this.val$columnComparator;
|
|
if (comparator4 == null) {
|
|
return 0;
|
|
}
|
|
return comparator4.compare(cell.getColumnKey(), cell2.getColumnKey());
|
|
}
|
|
});
|
|
}
|
|
return forCellsInternal(list, comparator, comparator2);
|
|
}
|
|
|
|
static <R, C, V> RegularImmutableTable<R, C, V> forCells(Iterable<Table.Cell<R, C, V>> iterable) {
|
|
return forCellsInternal(iterable, null, null);
|
|
}
|
|
|
|
private static <R, C, V> RegularImmutableTable<R, C, V> forCellsInternal(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.getRowKey());
|
|
linkedHashSet2.add(cell.getColumnKey());
|
|
}
|
|
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 forOrderedComponents(copyOf3, copyOf, copyOf2);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static <R, C, V> RegularImmutableTable<R, C, V> forOrderedComponents(ImmutableList<Table.Cell<R, C, V>> immutableList, ImmutableSet<R> immutableSet, ImmutableSet<C> immutableSet2) {
|
|
if (immutableList.size() > (immutableSet.size() * immutableSet2.size()) / 2) {
|
|
return new DenseImmutableTable(immutableList, immutableSet, immutableSet2);
|
|
}
|
|
return new SparseImmutableTable(immutableList, immutableSet, immutableSet2);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public final void checkNoDuplicate(R r, C c, V v, V v2) {
|
|
Preconditions.checkArgument(v == null, "Duplicate key: (row=%s, column=%s), values: [%s, %s].", r, c, v2, v);
|
|
}
|
|
}
|