what-the-bank/sources/com/google/common/collect/TreeBasedTable.java

348 lines
14 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps;
import com.google.common.collect.StandardTable;
import java.io.Serializable;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
/* loaded from: classes2.dex */
public class TreeBasedTable<R, C, V> extends StandardRowSortedTable<R, C, V> {
private static final long serialVersionUID = 0;
private final Comparator<? super C> columnComparator;
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ Set cellSet() {
return super.cellSet();
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ void clear() {
super.clear();
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.collect.StandardTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ Map column(Object obj) {
return super.column(obj);
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ Set columnKeySet() {
return super.columnKeySet();
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ Map columnMap() {
return super.columnMap();
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ boolean contains(Object obj, Object obj2) {
return super.contains(obj, obj2);
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ boolean containsColumn(Object obj) {
return super.containsColumn(obj);
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ boolean containsRow(Object obj) {
return super.containsRow(obj);
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ boolean containsValue(Object obj) {
return super.containsValue(obj);
}
@Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ boolean equals(Object obj) {
return super.equals(obj);
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ Object get(Object obj, Object obj2) {
return super.get(obj, obj2);
}
@Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ int hashCode() {
return super.hashCode();
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ boolean isEmpty() {
return super.isEmpty();
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ Object put(Object obj, Object obj2, Object obj3) {
return super.put(obj, obj2, obj3);
}
@Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ void putAll(Table table) {
super.putAll(table);
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ Object remove(Object obj, Object obj2) {
return super.remove(obj, obj2);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.collect.StandardTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ Map row(Object obj) {
return row((TreeBasedTable<R, C, V>) obj);
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ int size() {
return super.size();
}
@Override // com.google.common.collect.AbstractTable
public /* bridge */ /* synthetic */ String toString() {
return super.toString();
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public /* bridge */ /* synthetic */ Collection values() {
return super.values();
}
/* loaded from: classes2.dex */
static class Factory<C, V> implements Supplier<TreeMap<C, V>>, Serializable {
private static final long serialVersionUID = 0;
final Comparator<? super C> comparator;
Factory(Comparator<? super C> comparator) {
this.comparator = comparator;
}
@Override // com.google.common.base.Supplier
public TreeMap<C, V> get() {
return new TreeMap<>(this.comparator);
}
}
public static <R extends Comparable, C extends Comparable, V> TreeBasedTable<R, C, V> create() {
return new TreeBasedTable<>(Ordering.natural(), Ordering.natural());
}
public static <R, C, V> TreeBasedTable<R, C, V> create(Comparator<? super R> comparator, Comparator<? super C> comparator2) {
Preconditions.checkNotNull(comparator);
Preconditions.checkNotNull(comparator2);
return new TreeBasedTable<>(comparator, comparator2);
}
public static <R, C, V> TreeBasedTable<R, C, V> create(TreeBasedTable<R, C, ? extends V> treeBasedTable) {
TreeBasedTable<R, C, V> treeBasedTable2 = new TreeBasedTable<>(treeBasedTable.rowComparator(), treeBasedTable.columnComparator());
treeBasedTable2.putAll(treeBasedTable);
return treeBasedTable2;
}
TreeBasedTable(Comparator<? super R> comparator, Comparator<? super C> comparator2) {
super(new TreeMap(comparator), new Factory(comparator2));
this.columnComparator = comparator2;
}
@Deprecated
public Comparator<? super R> rowComparator() {
return rowKeySet().comparator();
}
@Override // com.google.common.collect.StandardTable, com.google.common.collect.Table
public SortedMap<C, V> row(R r) {
return new TreeRow(this, r);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class TreeRow extends StandardTable.Row implements SortedMap {
final C lowerBound;
final TreeBasedTable this$0;
final C upperBound;
transient SortedMap<C, V> wholeRow;
TreeRow(TreeBasedTable treeBasedTable, R r) {
this(treeBasedTable, r, null, null);
}
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
TreeRow(TreeBasedTable treeBasedTable, R r, C c, C c2) {
super(treeBasedTable, r);
this.this$0 = treeBasedTable;
this.lowerBound = c;
this.upperBound = c2;
Preconditions.checkArgument(c == null || c2 == null || compare(c, c2) <= 0);
}
@Override // java.util.AbstractMap, java.util.Map, java.util.SortedMap
public SortedSet<C> keySet() {
return new Maps.SortedKeySet(this);
}
@Override // java.util.SortedMap
public Comparator<? super C> comparator() {
return this.this$0.columnComparator();
}
int compare(Object obj, Object obj2) {
return comparator().compare(obj, obj2);
}
boolean rangeContains(Object obj) {
C c;
C c2;
return obj != null && ((c = this.lowerBound) == null || compare(c, obj) <= 0) && ((c2 = this.upperBound) == null || compare(c2, obj) > 0);
}
@Override // java.util.SortedMap
public SortedMap<C, V> subMap(C c, C c2) {
Preconditions.checkArgument(rangeContains(Preconditions.checkNotNull(c)) && rangeContains(Preconditions.checkNotNull(c2)));
return new TreeRow(this.this$0, this.rowKey, c, c2);
}
@Override // java.util.SortedMap
public SortedMap<C, V> headMap(C c) {
Preconditions.checkArgument(rangeContains(Preconditions.checkNotNull(c)));
return new TreeRow(this.this$0, this.rowKey, this.lowerBound, c);
}
@Override // java.util.SortedMap
public SortedMap<C, V> tailMap(C c) {
Preconditions.checkArgument(rangeContains(Preconditions.checkNotNull(c)));
return new TreeRow(this.this$0, this.rowKey, c, this.upperBound);
}
@Override // java.util.SortedMap
public C firstKey() {
if (backingRowMap() == null) {
throw new NoSuchElementException();
}
return backingRowMap().firstKey();
}
@Override // java.util.SortedMap
public C lastKey() {
if (backingRowMap() == null) {
throw new NoSuchElementException();
}
return backingRowMap().lastKey();
}
SortedMap<C, V> wholeRow() {
SortedMap<C, V> sortedMap = this.wholeRow;
if (sortedMap == null || (sortedMap.isEmpty() && this.this$0.backingMap.containsKey(this.rowKey))) {
this.wholeRow = (SortedMap) this.this$0.backingMap.get(this.rowKey);
}
return this.wholeRow;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.StandardTable.Row
public SortedMap<C, V> backingRowMap() {
return (SortedMap) super.backingRowMap();
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.StandardTable.Row
public SortedMap<C, V> computeBackingRowMap() {
SortedMap<C, V> wholeRow = wholeRow();
if (wholeRow == null) {
return null;
}
C c = this.lowerBound;
if (c != null) {
wholeRow = wholeRow.tailMap(c);
}
C c2 = this.upperBound;
return c2 != null ? wholeRow.headMap(c2) : wholeRow;
}
@Override // com.google.common.collect.StandardTable.Row
void maintainEmptyInvariant() {
if (wholeRow() == null || !this.wholeRow.isEmpty()) {
return;
}
this.this$0.backingMap.remove(this.rowKey);
this.wholeRow = null;
this.backingRowMap = null;
}
@Override // com.google.common.collect.StandardTable.Row, java.util.AbstractMap, java.util.Map
public boolean containsKey(Object obj) {
return rangeContains(obj) && super.containsKey(obj);
}
@Override // com.google.common.collect.StandardTable.Row, java.util.AbstractMap, java.util.Map
public V put(C c, V v) {
Preconditions.checkArgument(rangeContains(Preconditions.checkNotNull(c)));
return (V) super.put(c, v);
}
}
@Override // com.google.common.collect.StandardRowSortedTable, com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table
public SortedSet<R> rowKeySet() {
return super.rowKeySet();
}
@Override // com.google.common.collect.StandardRowSortedTable, com.google.common.collect.StandardTable, com.google.common.collect.Table
public SortedMap<R, Map<C, V>> rowMap() {
return super.rowMap();
}
@Override // com.google.common.collect.StandardTable
Iterator<C> createColumnKeyIterator() {
Comparator<? super C> columnComparator = columnComparator();
return new AbstractIterator<C>(this, Iterators.mergeSorted(Iterables.transform(this.backingMap.values(), new Function<Map<C, V>, Iterator<C>>(this) { // from class: com.google.common.collect.TreeBasedTable.1
@Override // com.google.common.base.Function
public Iterator<C> apply(Map<C, V> map) {
return map.keySet().iterator();
}
}), columnComparator), columnComparator) { // from class: com.google.common.collect.TreeBasedTable.2
C lastValue;
final Comparator val$comparator;
final Iterator val$merged;
{
this.val$merged = r2;
this.val$comparator = columnComparator;
}
@Override // com.google.common.collect.AbstractIterator
protected C computeNext() {
while (this.val$merged.hasNext()) {
C c = (C) this.val$merged.next();
C c2 = this.lastValue;
if (c2 == null || this.val$comparator.compare(c, c2) != 0) {
this.lastValue = c;
return c;
}
}
this.lastValue = null;
return endOfData();
}
};
}
@Deprecated
public Comparator<? super C> columnComparator() {
return this.columnComparator;
}
}