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.Objects; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import javax.annotation.CheckForNull; @ElementTypesAreNonnullByDefault /* loaded from: classes3.dex */ public class TreeBasedTable extends StandardRowSortedTable { private static final long serialVersionUID = 0; private final Comparator columnComparator; @Deprecated public Comparator columnComparator() { return this.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(@CheckForNull Object obj, @CheckForNull 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(@CheckForNull 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(@CheckForNull 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(@CheckForNull Object obj) { return super.containsValue(obj); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public /* bridge */ /* synthetic */ boolean equals(@CheckForNull Object obj) { return super.equals(obj); } @Override // com.google.common.collect.StandardTable, com.google.common.collect.AbstractTable, com.google.common.collect.Table @CheckForNull public /* bridge */ /* synthetic */ Object get(@CheckForNull Object obj, @CheckForNull 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 @CheckForNull 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 @CheckForNull public /* bridge */ /* synthetic */ Object remove(@CheckForNull Object obj, @CheckForNull 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) 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: classes3.dex */ private static class Factory implements Supplier>, Serializable { private static final long serialVersionUID = 0; final Comparator comparator; Factory(Comparator comparator) { this.comparator = comparator; } @Override // com.google.common.base.Supplier public TreeMap get() { return new TreeMap<>(this.comparator); } } public static TreeBasedTable create() { return new TreeBasedTable<>(Ordering.natural(), Ordering.natural()); } public static TreeBasedTable create(Comparator comparator, Comparator comparator2) { Preconditions.checkNotNull(comparator); Preconditions.checkNotNull(comparator2); return new TreeBasedTable<>(comparator, comparator2); } public static TreeBasedTable create(TreeBasedTable treeBasedTable) { TreeBasedTable treeBasedTable2 = new TreeBasedTable<>(treeBasedTable.rowComparator(), treeBasedTable.columnComparator()); treeBasedTable2.putAll(treeBasedTable); return treeBasedTable2; } TreeBasedTable(Comparator comparator, Comparator comparator2) { super(new TreeMap(comparator), new Factory(comparator2)); this.columnComparator = comparator2; } @Deprecated public Comparator rowComparator() { return (Comparator) Objects.requireNonNull(rowKeySet().comparator()); } @Override // com.google.common.collect.StandardTable, com.google.common.collect.Table public SortedMap row(R r) { return new TreeRow(this, r); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public class TreeRow extends StandardTable.Row implements SortedMap { @CheckForNull final C lowerBound; @CheckForNull final C upperBound; @CheckForNull transient SortedMap wholeRow; TreeRow(TreeBasedTable treeBasedTable, R r) { this(r, null, null); } TreeRow(R r, @CheckForNull C c, @CheckForNull C c2) { super(r); 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 keySet() { return new Maps.SortedKeySet(this); } @Override // java.util.SortedMap public Comparator comparator() { return TreeBasedTable.this.columnComparator(); } int compare(Object obj, Object obj2) { return comparator().compare(obj, obj2); } boolean rangeContains(@CheckForNull 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 subMap(C c, C c2) { Preconditions.checkArgument(rangeContains(Preconditions.checkNotNull(c)) && rangeContains(Preconditions.checkNotNull(c2))); return new TreeRow(this.rowKey, c, c2); } @Override // java.util.SortedMap public SortedMap headMap(C c) { Preconditions.checkArgument(rangeContains(Preconditions.checkNotNull(c))); return new TreeRow(this.rowKey, this.lowerBound, c); } @Override // java.util.SortedMap public SortedMap tailMap(C c) { Preconditions.checkArgument(rangeContains(Preconditions.checkNotNull(c))); return new TreeRow(this.rowKey, c, this.upperBound); } @Override // java.util.SortedMap public C firstKey() { updateBackingRowMapField(); if (this.backingRowMap == null) { throw new NoSuchElementException(); } return (C) ((SortedMap) this.backingRowMap).firstKey(); } @Override // java.util.SortedMap public C lastKey() { updateBackingRowMapField(); if (this.backingRowMap == null) { throw new NoSuchElementException(); } return (C) ((SortedMap) this.backingRowMap).lastKey(); } void updateWholeRowField() { SortedMap sortedMap = this.wholeRow; if (sortedMap == null || (sortedMap.isEmpty() && TreeBasedTable.this.backingMap.containsKey(this.rowKey))) { this.wholeRow = (SortedMap) TreeBasedTable.this.backingMap.get(this.rowKey); } } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.StandardTable.Row @CheckForNull public SortedMap computeBackingRowMap() { updateWholeRowField(); SortedMap sortedMap = this.wholeRow; if (sortedMap == null) { return null; } C c = this.lowerBound; if (c != null) { sortedMap = sortedMap.tailMap(c); } C c2 = this.upperBound; return c2 != null ? sortedMap.headMap(c2) : sortedMap; } @Override // com.google.common.collect.StandardTable.Row void maintainEmptyInvariant() { updateWholeRowField(); SortedMap sortedMap = this.wholeRow; if (sortedMap == null || !sortedMap.isEmpty()) { return; } TreeBasedTable.this.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(@CheckForNull Object obj) { return rangeContains(obj) && super.containsKey(obj); } @Override // com.google.common.collect.StandardTable.Row, java.util.AbstractMap, java.util.Map @CheckForNull 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 rowKeySet() { return super.rowKeySet(); } @Override // com.google.common.collect.StandardRowSortedTable, com.google.common.collect.StandardTable, com.google.common.collect.Table public SortedMap> rowMap() { return super.rowMap(); } @Override // com.google.common.collect.StandardTable Iterator createColumnKeyIterator() { final Comparator columnComparator = columnComparator(); final UnmodifiableIterator mergeSorted = Iterators.mergeSorted(Iterables.transform(this.backingMap.values(), new Function() { // from class: com.google.common.collect.TreeBasedTable$$ExternalSyntheticLambda0 @Override // com.google.common.base.Function public final Object apply(Object obj) { Iterator it; it = ((Map) obj).keySet().iterator(); return it; } }), columnComparator); return new AbstractIterator(this) { // from class: com.google.common.collect.TreeBasedTable.1 @CheckForNull C lastValue; @Override // com.google.common.collect.AbstractIterator @CheckForNull protected C computeNext() { while (mergeSorted.hasNext()) { C c = (C) mergeSorted.next(); C c2 = this.lastValue; if (c2 == null || columnComparator.compare(c, c2) != 0) { this.lastValue = c; return c; } } this.lastValue = null; return endOfData(); } }; } }