package com.google.common.collect; import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Supplier; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.google.common.collect.Table; import java.io.Serializable; import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; /* loaded from: classes.dex */ class StandardTable extends AbstractTable implements Serializable { private static final long serialVersionUID = 0; final Map> backingMap; private transient Set columnKeySet; private transient StandardTable.ColumnMap columnMap; final Supplier> factory; private transient Map> rowMap; private class CellIterator implements Iterator> { final Iterator>> a; Map.Entry> b; Iterator> c; private CellIterator() { this.a = StandardTable.this.backingMap.entrySet().iterator(); this.c = Iterators.c(); } @Override // java.util.Iterator public boolean hasNext() { return this.a.hasNext() || this.c.hasNext(); } @Override // java.util.Iterator public void remove() { this.c.remove(); if (this.b.getValue().isEmpty()) { this.a.remove(); } } @Override // java.util.Iterator public Table.Cell next() { if (!this.c.hasNext()) { this.b = this.a.next(); this.c = this.b.getValue().entrySet().iterator(); } Map.Entry next = this.c.next(); return Tables.a(this.b.getKey(), next.getKey(), next.getValue()); } } private class ColumnKeyIterator extends AbstractIterator { final Map c; final Iterator> d; Iterator> e; private ColumnKeyIterator() { this.c = StandardTable.this.factory.get(); this.d = StandardTable.this.backingMap.values().iterator(); this.e = Iterators.a(); } @Override // com.google.common.collect.AbstractIterator protected C a() { while (true) { if (this.e.hasNext()) { Map.Entry next = this.e.next(); if (!this.c.containsKey(next.getKey())) { this.c.put(next.getKey(), next.getValue()); return next.getKey(); } } else { if (!this.d.hasNext()) { return b(); } this.e = this.d.next().entrySet().iterator(); } } } } private class ColumnKeySet extends StandardTable.TableSet { private ColumnKeySet() { super(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return StandardTable.this.containsColumn(obj); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return StandardTable.this.createColumnKeyIterator(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { boolean z = false; if (obj == null) { return false; } Iterator> it = StandardTable.this.backingMap.values().iterator(); while (it.hasNext()) { Map next = it.next(); if (next.keySet().remove(obj)) { z = true; if (next.isEmpty()) { it.remove(); } } } return z; } @Override // com.google.common.collect.Sets.ImprovedAbstractSet, java.util.AbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean removeAll(Collection collection) { Preconditions.a(collection); Iterator> it = StandardTable.this.backingMap.values().iterator(); boolean z = false; while (it.hasNext()) { Map next = it.next(); if (Iterators.a((Iterator) next.keySet().iterator(), collection)) { z = true; if (next.isEmpty()) { it.remove(); } } } return z; } @Override // com.google.common.collect.Sets.ImprovedAbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean retainAll(Collection collection) { Preconditions.a(collection); Iterator> it = StandardTable.this.backingMap.values().iterator(); boolean z = false; while (it.hasNext()) { Map next = it.next(); if (next.keySet().retainAll(collection)) { z = true; if (next.isEmpty()) { it.remove(); } } } return z; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return Iterators.h(iterator()); } } private class ColumnMap extends Maps.ViewCachingAbstractMap> { class ColumnMapEntrySet extends StandardTable.TableSet>> { ColumnMapEntrySet() { super(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; if (!StandardTable.this.containsColumn(entry.getKey())) { return false; } return ColumnMap.this.get(entry.getKey()).equals(entry.getValue()); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator>> iterator() { return Maps.a((Set) StandardTable.this.columnKeySet(), (Function) new Function>() { // from class: com.google.common.collect.StandardTable.ColumnMap.ColumnMapEntrySet.1 @Override // com.google.common.base.Function public /* bridge */ /* synthetic */ Object apply(Object obj) { return apply((AnonymousClass1) obj); } @Override // com.google.common.base.Function public Map apply(C c) { return StandardTable.this.column(c); } }); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (!contains(obj)) { return false; } StandardTable.this.removeColumn(((Map.Entry) obj).getKey()); return true; } @Override // com.google.common.collect.Sets.ImprovedAbstractSet, java.util.AbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean removeAll(Collection collection) { Preconditions.a(collection); return Sets.a((Set) this, collection.iterator()); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.Sets.ImprovedAbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean retainAll(Collection collection) { Preconditions.a(collection); Iterator it = Lists.a(StandardTable.this.columnKeySet().iterator()).iterator(); boolean z = false; while (it.hasNext()) { Object next = it.next(); if (!collection.contains(Maps.a(next, StandardTable.this.column(next)))) { StandardTable.this.removeColumn(next); z = true; } } return z; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return StandardTable.this.columnKeySet().size(); } } private class ColumnMapValues extends Maps.Values> { ColumnMapValues() { super(ColumnMap.this); } @Override // com.google.common.collect.Maps.Values, java.util.AbstractCollection, java.util.Collection public boolean remove(Object obj) { for (Map.Entry> entry : ColumnMap.this.entrySet()) { if (entry.getValue().equals(obj)) { StandardTable.this.removeColumn(entry.getKey()); return true; } } return false; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.Maps.Values, java.util.AbstractCollection, java.util.Collection public boolean removeAll(Collection collection) { Preconditions.a(collection); Iterator it = Lists.a(StandardTable.this.columnKeySet().iterator()).iterator(); boolean z = false; while (it.hasNext()) { Object next = it.next(); if (collection.contains(StandardTable.this.column(next))) { StandardTable.this.removeColumn(next); z = true; } } return z; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.Maps.Values, java.util.AbstractCollection, java.util.Collection public boolean retainAll(Collection collection) { Preconditions.a(collection); Iterator it = Lists.a(StandardTable.this.columnKeySet().iterator()).iterator(); boolean z = false; while (it.hasNext()) { Object next = it.next(); if (!collection.contains(StandardTable.this.column(next))) { StandardTable.this.removeColumn(next); z = true; } } return z; } } private ColumnMap() { } @Override // com.google.common.collect.Maps.ViewCachingAbstractMap public Set>> a() { return new ColumnMapEntrySet(); } @Override // com.google.common.collect.Maps.ViewCachingAbstractMap Collection> c() { return new ColumnMapValues(); } @Override // java.util.AbstractMap, java.util.Map public boolean containsKey(Object obj) { return StandardTable.this.containsColumn(obj); } @Override // com.google.common.collect.Maps.ViewCachingAbstractMap, java.util.AbstractMap, java.util.Map public Set keySet() { return StandardTable.this.columnKeySet(); } @Override // java.util.AbstractMap, java.util.Map public Map get(Object obj) { if (StandardTable.this.containsColumn(obj)) { return StandardTable.this.column(obj); } return null; } @Override // java.util.AbstractMap, java.util.Map public Map remove(Object obj) { if (StandardTable.this.containsColumn(obj)) { return StandardTable.this.removeColumn(obj); } return null; } } class RowMap extends Maps.ViewCachingAbstractMap> { class EntrySet extends StandardTable.TableSet>> { EntrySet() { super(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; return entry.getKey() != null && (entry.getValue() instanceof Map) && Collections2.a(StandardTable.this.backingMap.entrySet(), entry); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator>> iterator() { return Maps.a((Set) StandardTable.this.backingMap.keySet(), (Function) new Function>() { // from class: com.google.common.collect.StandardTable.RowMap.EntrySet.1 @Override // com.google.common.base.Function public /* bridge */ /* synthetic */ Object apply(Object obj) { return apply((AnonymousClass1) obj); } @Override // com.google.common.base.Function public Map apply(R r) { return StandardTable.this.row(r); } }); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; return entry.getKey() != null && (entry.getValue() instanceof Map) && StandardTable.this.backingMap.entrySet().remove(entry); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return StandardTable.this.backingMap.size(); } } RowMap() { } @Override // com.google.common.collect.Maps.ViewCachingAbstractMap protected Set>> a() { return new EntrySet(); } @Override // java.util.AbstractMap, java.util.Map public boolean containsKey(Object obj) { return StandardTable.this.containsRow(obj); } @Override // java.util.AbstractMap, java.util.Map public Map get(Object obj) { if (StandardTable.this.containsRow(obj)) { return StandardTable.this.row(obj); } return null; } @Override // java.util.AbstractMap, java.util.Map public Map remove(Object obj) { if (obj == null) { return null; } return StandardTable.this.backingMap.remove(obj); } } private abstract class TableSet extends Sets.ImprovedAbstractSet { private TableSet() { } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { StandardTable.this.backingMap.clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean isEmpty() { return StandardTable.this.backingMap.isEmpty(); } } StandardTable(Map> map, Supplier> supplier) { this.backingMap = map; this.factory = supplier; } /* JADX INFO: Access modifiers changed from: private */ public boolean containsMapping(Object obj, Object obj2, Object obj3) { return obj3 != null && obj3.equals(get(obj, obj2)); } private Map getOrCreate(R r) { Map map = this.backingMap.get(r); if (map != null) { return map; } Map map2 = this.factory.get(); this.backingMap.put(r, map2); return map2; } /* JADX INFO: Access modifiers changed from: private */ public Map removeColumn(Object obj) { LinkedHashMap linkedHashMap = new LinkedHashMap(); Iterator>> it = this.backingMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry> next = it.next(); V remove = next.getValue().remove(obj); if (remove != null) { linkedHashMap.put(next.getKey(), remove); if (next.getValue().isEmpty()) { it.remove(); } } } return linkedHashMap; } /* JADX INFO: Access modifiers changed from: private */ public boolean removeMapping(Object obj, Object obj2, Object obj3) { if (!containsMapping(obj, obj2, obj3)) { return false; } remove(obj, obj2); return true; } @Override // com.google.common.collect.AbstractTable Iterator> cellIterator() { return new CellIterator(); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public Set> cellSet() { return super.cellSet(); } @Override // com.google.common.collect.AbstractTable public void clear() { this.backingMap.clear(); } public Map column(C c) { return new Column(c); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public Set columnKeySet() { Set set = this.columnKeySet; if (set != null) { return set; } ColumnKeySet columnKeySet = new ColumnKeySet(); this.columnKeySet = columnKeySet; return columnKeySet; } @Override // com.google.common.collect.Table public Map> columnMap() { StandardTable.ColumnMap columnMap = this.columnMap; if (columnMap != null) { return columnMap; } StandardTable.ColumnMap columnMap2 = new ColumnMap(); this.columnMap = columnMap2; return columnMap2; } @Override // com.google.common.collect.AbstractTable public boolean contains(Object obj, Object obj2) { return (obj == null || obj2 == null || !super.contains(obj, obj2)) ? false : true; } @Override // com.google.common.collect.AbstractTable public boolean containsColumn(Object obj) { if (obj == null) { return false; } Iterator> it = this.backingMap.values().iterator(); while (it.hasNext()) { if (Maps.d(it.next(), obj)) { return true; } } return false; } @Override // com.google.common.collect.AbstractTable public boolean containsRow(Object obj) { return obj != null && Maps.d(this.backingMap, obj); } @Override // com.google.common.collect.AbstractTable public boolean containsValue(Object obj) { return obj != null && super.containsValue(obj); } Iterator createColumnKeyIterator() { return new ColumnKeyIterator(); } Map> createRowMap() { return new RowMap(); } @Override // com.google.common.collect.AbstractTable public V get(Object obj, Object obj2) { if (obj == null || obj2 == null) { return null; } return (V) super.get(obj, obj2); } @Override // com.google.common.collect.AbstractTable public boolean isEmpty() { return this.backingMap.isEmpty(); } @Override // com.google.common.collect.AbstractTable public V put(R r, C c, V v) { Preconditions.a(r); Preconditions.a(c); Preconditions.a(v); return getOrCreate(r).put(c, v); } @Override // com.google.common.collect.AbstractTable public V remove(Object obj, Object obj2) { Map map; if (obj == null || obj2 == null || (map = (Map) Maps.e(this.backingMap, obj)) == null) { return null; } V v = (V) map.remove(obj2); if (map.isEmpty()) { this.backingMap.remove(obj); } return v; } public Map row(R r) { return new Row(r); } @Override // com.google.common.collect.AbstractTable, com.google.common.collect.Table public Set rowKeySet() { return rowMap().keySet(); } @Override // com.google.common.collect.Table public Map> rowMap() { Map> map = this.rowMap; if (map != null) { return map; } Map> createRowMap = createRowMap(); this.rowMap = createRowMap; return createRowMap; } @Override // com.google.common.collect.Table public int size() { Iterator> it = this.backingMap.values().iterator(); int i = 0; while (it.hasNext()) { i += it.next().size(); } return i; } @Override // com.google.common.collect.AbstractTable public Collection values() { return super.values(); } class Row extends Maps.IteratorBasedAbstractMap { final R a; Map b; Row(R r) { Preconditions.a(r); this.a = r; } Map a() { Map map = this.b; if (map != null && (!map.isEmpty() || !StandardTable.this.backingMap.containsKey(this.a))) { return this.b; } Map b = b(); this.b = b; return b; } Map b() { return StandardTable.this.backingMap.get(this.a); } void c() { if (a() == null || !this.b.isEmpty()) { return; } StandardTable.this.backingMap.remove(this.a); this.b = null; } @Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map public void clear() { Map a = a(); if (a != null) { a.clear(); } c(); } @Override // java.util.AbstractMap, java.util.Map public boolean containsKey(Object obj) { Map a = a(); return (obj == null || a == null || !Maps.d(a, obj)) ? false : true; } @Override // com.google.common.collect.Maps.IteratorBasedAbstractMap Iterator> entryIterator() { Map a = a(); if (a == null) { return Iterators.c(); } final Iterator> it = a.entrySet().iterator(); return new Iterator>() { // from class: com.google.common.collect.StandardTable.Row.1 @Override // java.util.Iterator public boolean hasNext() { return it.hasNext(); } @Override // java.util.Iterator public void remove() { it.remove(); Row.this.c(); } @Override // java.util.Iterator public Map.Entry next() { return Row.this.a((Map.Entry) it.next()); } }; } @Override // java.util.AbstractMap, java.util.Map public V get(Object obj) { Map a = a(); if (obj == null || a == null) { return null; } return (V) Maps.e(a, obj); } @Override // java.util.AbstractMap, java.util.Map public V put(C c, V v) { Preconditions.a(c); Preconditions.a(v); Map map = this.b; return (map == null || map.isEmpty()) ? (V) StandardTable.this.put(this.a, c, v) : this.b.put(c, v); } @Override // java.util.AbstractMap, java.util.Map public V remove(Object obj) { Map a = a(); if (a == null) { return null; } V v = (V) Maps.f(a, obj); c(); return v; } @Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map public int size() { Map a = a(); if (a == null) { return 0; } return a.size(); } Map.Entry a(final Map.Entry entry) { return new ForwardingMapEntry(this) { // from class: com.google.common.collect.StandardTable.Row.2 @Override // com.google.common.collect.ForwardingMapEntry, java.util.Map.Entry public boolean equals(Object obj) { return standardEquals(obj); } @Override // com.google.common.collect.ForwardingMapEntry, java.util.Map.Entry public V setValue(V v) { Preconditions.a(v); return (V) super.setValue(v); } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingObject public Map.Entry delegate() { return entry; } }; } } private class Column extends Maps.ViewCachingAbstractMap { final C d; private class EntrySet extends Sets.ImprovedAbstractSet> { private EntrySet() { } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { Column.this.a(Predicates.a()); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; return StandardTable.this.containsMapping(entry.getKey(), Column.this.d, entry.getValue()); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean isEmpty() { Column column = Column.this; return !StandardTable.this.containsColumn(column.d); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator> iterator() { return new EntrySetIterator(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; return StandardTable.this.removeMapping(entry.getKey(), Column.this.d, entry.getValue()); } @Override // com.google.common.collect.Sets.ImprovedAbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean retainAll(Collection collection) { return Column.this.a(Predicates.a(Predicates.a((Collection) collection))); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { Iterator> it = StandardTable.this.backingMap.values().iterator(); int i = 0; while (it.hasNext()) { if (it.next().containsKey(Column.this.d)) { i++; } } return i; } } private class EntrySetIterator extends AbstractIterator> { final Iterator>> c; private EntrySetIterator() { this.c = StandardTable.this.backingMap.entrySet().iterator(); } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.AbstractIterator public Map.Entry a() { while (this.c.hasNext()) { final Map.Entry> next = this.c.next(); if (next.getValue().containsKey(Column.this.d)) { return new AbstractMapEntry() { // from class: com.google.common.collect.StandardTable.Column.EntrySetIterator.1EntryImpl @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public R getKey() { return (R) next.getKey(); } @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public V getValue() { return (V) ((Map) next.getValue()).get(Column.this.d); } @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public V setValue(V v) { Map map = (Map) next.getValue(); C c = Column.this.d; Preconditions.a(v); return (V) map.put(c, v); } }; } } return b(); } } private class KeySet extends Maps.KeySet { KeySet() { super(Column.this); } @Override // com.google.common.collect.Maps.KeySet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { Column column = Column.this; return StandardTable.this.contains(obj, column.d); } @Override // com.google.common.collect.Maps.KeySet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { Column column = Column.this; return StandardTable.this.remove(obj, column.d) != null; } @Override // com.google.common.collect.Sets.ImprovedAbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean retainAll(Collection collection) { return Column.this.a(Maps.a(Predicates.a(Predicates.a((Collection) collection)))); } } private class Values extends Maps.Values { Values() { super(Column.this); } @Override // com.google.common.collect.Maps.Values, java.util.AbstractCollection, java.util.Collection public boolean remove(Object obj) { return obj != null && Column.this.a(Maps.b(Predicates.a(obj))); } @Override // com.google.common.collect.Maps.Values, java.util.AbstractCollection, java.util.Collection public boolean removeAll(Collection collection) { return Column.this.a(Maps.b(Predicates.a((Collection) collection))); } @Override // com.google.common.collect.Maps.Values, java.util.AbstractCollection, java.util.Collection public boolean retainAll(Collection collection) { return Column.this.a(Maps.b(Predicates.a(Predicates.a((Collection) collection)))); } } Column(C c) { Preconditions.a(c); this.d = c; } boolean a(Predicate> predicate) { Iterator>> it = StandardTable.this.backingMap.entrySet().iterator(); boolean z = false; while (it.hasNext()) { Map.Entry> next = it.next(); Map value = next.getValue(); V v = value.get(this.d); if (v != null && predicate.apply(Maps.a(next.getKey(), v))) { value.remove(this.d); z = true; if (value.isEmpty()) { it.remove(); } } } return z; } @Override // com.google.common.collect.Maps.ViewCachingAbstractMap Set b() { return new KeySet(); } @Override // com.google.common.collect.Maps.ViewCachingAbstractMap Collection c() { return new Values(); } @Override // java.util.AbstractMap, java.util.Map public boolean containsKey(Object obj) { return StandardTable.this.contains(obj, this.d); } @Override // java.util.AbstractMap, java.util.Map public V get(Object obj) { return (V) StandardTable.this.get(obj, this.d); } @Override // java.util.AbstractMap, java.util.Map public V put(R r, V v) { return (V) StandardTable.this.put(r, this.d, v); } @Override // java.util.AbstractMap, java.util.Map public V remove(Object obj) { return (V) StandardTable.this.remove(obj, this.d); } @Override // com.google.common.collect.Maps.ViewCachingAbstractMap Set> a() { return new EntrySet(); } } }