349 lines
12 KiB
Java
349 lines
12 KiB
Java
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 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: classes.dex */
|
|
public class TreeBasedTable<R, C, V> extends StandardRowSortedTable<R, C, V> {
|
|
private static final long serialVersionUID = 0;
|
|
private final Comparator<? super C> columnComparator;
|
|
|
|
private static class Factory<C, V> implements Supplier<TreeMap<C, V>>, Serializable {
|
|
final Comparator<? super C> a;
|
|
|
|
Factory(Comparator<? super C> comparator) {
|
|
this.a = comparator;
|
|
}
|
|
|
|
@Override // com.google.common.base.Supplier
|
|
public TreeMap<C, V> get() {
|
|
return new TreeMap<>(this.a);
|
|
}
|
|
}
|
|
|
|
private class TreeRow extends StandardTable<R, C, V>.Row implements SortedMap<C, V> {
|
|
final C d;
|
|
final C e;
|
|
transient SortedMap<C, V> f;
|
|
|
|
TreeRow(TreeBasedTable treeBasedTable, R r) {
|
|
this(r, null, null);
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable.Row
|
|
void c() {
|
|
if (d() == null || !this.f.isEmpty()) {
|
|
return;
|
|
}
|
|
TreeBasedTable.this.backingMap.remove(this.a);
|
|
this.f = null;
|
|
this.b = null;
|
|
}
|
|
|
|
@Override // java.util.SortedMap
|
|
public Comparator<? super C> comparator() {
|
|
return TreeBasedTable.this.columnComparator();
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable.Row, java.util.AbstractMap, java.util.Map
|
|
public boolean containsKey(Object obj) {
|
|
return a(obj) && super.containsKey(obj);
|
|
}
|
|
|
|
SortedMap<C, V> d() {
|
|
SortedMap<C, V> sortedMap = this.f;
|
|
if (sortedMap == null || (sortedMap.isEmpty() && TreeBasedTable.this.backingMap.containsKey(this.a))) {
|
|
this.f = (SortedMap) TreeBasedTable.this.backingMap.get(this.a);
|
|
}
|
|
return this.f;
|
|
}
|
|
|
|
@Override // java.util.SortedMap
|
|
public C firstKey() {
|
|
if (a() != null) {
|
|
return a().firstKey();
|
|
}
|
|
throw new NoSuchElementException();
|
|
}
|
|
|
|
@Override // java.util.SortedMap
|
|
public SortedMap<C, V> headMap(C c) {
|
|
Preconditions.a(c);
|
|
Preconditions.a(a(c));
|
|
return new TreeRow(this.a, this.d, c);
|
|
}
|
|
|
|
@Override // java.util.SortedMap
|
|
public C lastKey() {
|
|
if (a() != null) {
|
|
return a().lastKey();
|
|
}
|
|
throw new NoSuchElementException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable.Row, java.util.AbstractMap, java.util.Map
|
|
public V put(C c, V v) {
|
|
Preconditions.a(c);
|
|
Preconditions.a(a(c));
|
|
return (V) super.put(c, v);
|
|
}
|
|
|
|
@Override // java.util.SortedMap
|
|
public SortedMap<C, V> subMap(C c, C c2) {
|
|
boolean z;
|
|
Preconditions.a(c);
|
|
if (a(c)) {
|
|
Preconditions.a(c2);
|
|
if (a(c2)) {
|
|
z = true;
|
|
Preconditions.a(z);
|
|
return new TreeRow(this.a, c, c2);
|
|
}
|
|
}
|
|
z = false;
|
|
Preconditions.a(z);
|
|
return new TreeRow(this.a, c, c2);
|
|
}
|
|
|
|
@Override // java.util.SortedMap
|
|
public SortedMap<C, V> tailMap(C c) {
|
|
Preconditions.a(c);
|
|
Preconditions.a(a(c));
|
|
return new TreeRow(this.a, c, this.e);
|
|
}
|
|
|
|
TreeRow(R r, C c, C c2) {
|
|
super(r);
|
|
this.d = c;
|
|
this.e = c2;
|
|
Preconditions.a(c == null || c2 == null || a(c, c2) <= 0);
|
|
}
|
|
|
|
int a(Object obj, Object obj2) {
|
|
return comparator().compare(obj, obj2);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.StandardTable.Row
|
|
public SortedMap<C, V> b() {
|
|
SortedMap<C, V> d = d();
|
|
if (d == null) {
|
|
return null;
|
|
}
|
|
C c = this.d;
|
|
if (c != null) {
|
|
d = d.tailMap(c);
|
|
}
|
|
C c2 = this.e;
|
|
return c2 != null ? d.headMap(c2) : d;
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map, java.util.SortedMap
|
|
public SortedSet<C> keySet() {
|
|
return new Maps.SortedKeySet(this);
|
|
}
|
|
|
|
boolean a(Object obj) {
|
|
C c;
|
|
C c2;
|
|
return obj != null && ((c = this.d) == null || a(c, obj) <= 0) && ((c2 = this.e) == null || a(c2, obj) > 0);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.StandardTable.Row
|
|
public SortedMap<C, V> a() {
|
|
return (SortedMap) super.a();
|
|
}
|
|
}
|
|
|
|
TreeBasedTable(Comparator<? super R> comparator, Comparator<? super C> comparator2) {
|
|
super(new TreeMap(comparator), new Factory(comparator2));
|
|
this.columnComparator = comparator2;
|
|
}
|
|
|
|
public static <R extends Comparable, C extends Comparable, V> TreeBasedTable<R, C, V> create() {
|
|
return new TreeBasedTable<>(Ordering.c(), Ordering.c());
|
|
}
|
|
|
|
@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
|
|
public /* bridge */ /* synthetic */ void clear() {
|
|
super.clear();
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.StandardTable
|
|
public /* bridge */ /* synthetic */ Map column(Object obj) {
|
|
return super.column(obj);
|
|
}
|
|
|
|
@Deprecated
|
|
public Comparator<? super C> columnComparator() {
|
|
return this.columnComparator;
|
|
}
|
|
|
|
@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
|
|
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
|
|
public /* bridge */ /* synthetic */ boolean containsColumn(Object obj) {
|
|
return super.containsColumn(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable
|
|
public /* bridge */ /* synthetic */ boolean containsRow(Object obj) {
|
|
return super.containsRow(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable
|
|
public /* bridge */ /* synthetic */ boolean containsValue(Object obj) {
|
|
return super.containsValue(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable
|
|
Iterator<C> createColumnKeyIterator() {
|
|
final Comparator<? super C> columnComparator = columnComparator();
|
|
final UnmodifiableIterator a = Iterators.a(Iterables.a((Iterable) this.backingMap.values(), (Function) new Function<Map<C, V>, Iterator<C>>(this) { // from class: com.google.common.collect.TreeBasedTable.1
|
|
@Override // com.google.common.base.Function
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public Iterator<C> apply(Map<C, V> map) {
|
|
return map.keySet().iterator();
|
|
}
|
|
}), columnComparator);
|
|
return new AbstractIterator<C>(this) { // from class: com.google.common.collect.TreeBasedTable.2
|
|
C c;
|
|
|
|
@Override // com.google.common.collect.AbstractIterator
|
|
protected C a() {
|
|
while (a.hasNext()) {
|
|
C c = (C) a.next();
|
|
C c2 = this.c;
|
|
if (!(c2 != null && columnComparator.compare(c, c2) == 0)) {
|
|
this.c = c;
|
|
return this.c;
|
|
}
|
|
}
|
|
this.c = null;
|
|
return b();
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractTable
|
|
public /* bridge */ /* synthetic */ boolean equals(Object obj) {
|
|
return super.equals(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable
|
|
public /* bridge */ /* synthetic */ Object get(Object obj, Object obj2) {
|
|
return super.get(obj, obj2);
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractTable
|
|
public /* bridge */ /* synthetic */ int hashCode() {
|
|
return super.hashCode();
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable
|
|
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
|
|
public /* bridge */ /* synthetic */ Object put(Object obj, Object obj2, Object obj3) {
|
|
return super.put(obj, obj2, obj3);
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractTable
|
|
public /* bridge */ /* synthetic */ void putAll(Table table) {
|
|
super.putAll(table);
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable
|
|
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
|
|
public /* bridge */ /* synthetic */ Map row(Object obj) {
|
|
return row((TreeBasedTable<R, C, V>) obj);
|
|
}
|
|
|
|
@Deprecated
|
|
public Comparator<? super R> rowComparator() {
|
|
return rowKeySet().comparator();
|
|
}
|
|
|
|
@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
|
|
public /* bridge */ /* synthetic */ Collection values() {
|
|
return super.values();
|
|
}
|
|
|
|
public static <R, C, V> TreeBasedTable<R, C, V> create(Comparator<? super R> comparator, Comparator<? super C> comparator2) {
|
|
Preconditions.a(comparator);
|
|
Preconditions.a(comparator2);
|
|
return new TreeBasedTable<>(comparator, comparator2);
|
|
}
|
|
|
|
@Override // com.google.common.collect.StandardTable
|
|
public SortedMap<C, V> row(R r) {
|
|
return new TreeRow(this, r);
|
|
}
|
|
|
|
@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();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|