package com.google.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.AbstractMultimap; import com.google.common.collect.Maps; import com.google.common.collect.Multimaps; import java.io.Serializable; import java.util.AbstractCollection; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.NavigableMap; import java.util.NavigableSet; import java.util.Objects; import java.util.RandomAccess; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import javax.annotation.CheckForNull; /* JADX INFO: Access modifiers changed from: package-private */ @ElementTypesAreNonnullByDefault /* loaded from: classes3.dex */ public abstract class AbstractMapBasedMultimap extends AbstractMultimap implements Serializable { private static final long serialVersionUID = 2447537837011683357L; private transient Map> map; private transient int totalSize; /* JADX INFO: Access modifiers changed from: package-private */ public Map> backingMap() { return this.map; } abstract Collection createCollection(); @Override // com.google.common.collect.Multimap public int size() { return this.totalSize; } static /* synthetic */ int access$208(AbstractMapBasedMultimap abstractMapBasedMultimap) { int i = abstractMapBasedMultimap.totalSize; abstractMapBasedMultimap.totalSize = i + 1; return i; } static /* synthetic */ int access$210(AbstractMapBasedMultimap abstractMapBasedMultimap) { int i = abstractMapBasedMultimap.totalSize; abstractMapBasedMultimap.totalSize = i - 1; return i; } static /* synthetic */ int access$212(AbstractMapBasedMultimap abstractMapBasedMultimap, int i) { int i2 = abstractMapBasedMultimap.totalSize + i; abstractMapBasedMultimap.totalSize = i2; return i2; } static /* synthetic */ int access$220(AbstractMapBasedMultimap abstractMapBasedMultimap, int i) { int i2 = abstractMapBasedMultimap.totalSize - i; abstractMapBasedMultimap.totalSize = i2; return i2; } /* JADX INFO: Access modifiers changed from: protected */ public AbstractMapBasedMultimap(Map> map) { Preconditions.checkArgument(map.isEmpty()); this.map = map; } /* JADX INFO: Access modifiers changed from: package-private */ public final void setMap(Map> map) { this.map = map; this.totalSize = 0; for (Collection collection : map.values()) { Preconditions.checkArgument(!collection.isEmpty()); this.totalSize += collection.size(); } } Collection createUnmodifiableEmptyCollection() { return (Collection) unmodifiableCollectionSubclass(createCollection()); } /* JADX INFO: Access modifiers changed from: package-private */ public Collection createCollection(@ParametricNullness K k) { return createCollection(); } @Override // com.google.common.collect.Multimap public boolean containsKey(@CheckForNull Object obj) { return this.map.containsKey(obj); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public boolean put(@ParametricNullness K k, @ParametricNullness V v) { Collection collection = this.map.get(k); if (collection == null) { Collection createCollection = createCollection(k); if (createCollection.add(v)) { this.totalSize++; this.map.put(k, createCollection); return true; } throw new AssertionError("New Collection violated the Collection spec"); } if (!collection.add(v)) { return false; } this.totalSize++; return true; } private Collection getOrCreateCollection(@ParametricNullness K k) { Collection collection = this.map.get(k); if (collection != null) { return collection; } Collection createCollection = createCollection(k); this.map.put(k, createCollection); return createCollection; } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap, com.google.common.collect.ListMultimap public Collection replaceValues(@ParametricNullness K k, Iterable iterable) { Iterator it = iterable.iterator(); if (!it.hasNext()) { return removeAll(k); } Collection orCreateCollection = getOrCreateCollection(k); Collection createCollection = createCollection(); createCollection.addAll(orCreateCollection); this.totalSize -= orCreateCollection.size(); orCreateCollection.clear(); while (it.hasNext()) { if (orCreateCollection.add(it.next())) { this.totalSize++; } } return (Collection) unmodifiableCollectionSubclass(createCollection); } @Override // com.google.common.collect.Multimap, com.google.common.collect.ListMultimap public Collection removeAll(@CheckForNull Object obj) { Collection remove = this.map.remove(obj); if (remove == null) { return createUnmodifiableEmptyCollection(); } Collection createCollection = createCollection(); createCollection.addAll(remove); this.totalSize -= remove.size(); remove.clear(); return (Collection) unmodifiableCollectionSubclass(createCollection); } Collection unmodifiableCollectionSubclass(Collection collection) { return Collections.unmodifiableCollection(collection); } @Override // com.google.common.collect.Multimap public void clear() { Iterator> it = this.map.values().iterator(); while (it.hasNext()) { it.next().clear(); } this.map.clear(); this.totalSize = 0; } @Override // com.google.common.collect.Multimap, com.google.common.collect.ListMultimap public Collection get(@ParametricNullness K k) { Collection collection = this.map.get(k); if (collection == null) { collection = createCollection(k); } return wrapCollection(k, collection); } Collection wrapCollection(@ParametricNullness K k, Collection collection) { return new WrappedCollection(k, collection, null); } /* JADX INFO: Access modifiers changed from: package-private */ public final List wrapList(@ParametricNullness K k, List list, @CheckForNull AbstractMapBasedMultimap.WrappedCollection wrappedCollection) { if (list instanceof RandomAccess) { return new RandomAccessWrappedList(this, k, list, wrappedCollection); } return new WrappedList(k, list, wrappedCollection); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public class WrappedCollection extends AbstractCollection { @CheckForNull final AbstractMapBasedMultimap.WrappedCollection ancestor; @CheckForNull final Collection ancestorDelegate; Collection delegate; @ParametricNullness final K key; @CheckForNull AbstractMapBasedMultimap.WrappedCollection getAncestor() { return this.ancestor; } Collection getDelegate() { return this.delegate; } @ParametricNullness K getKey() { return this.key; } /* JADX INFO: Access modifiers changed from: package-private */ public WrappedCollection(@ParametricNullness K k, Collection collection, @CheckForNull AbstractMapBasedMultimap.WrappedCollection wrappedCollection) { this.key = k; this.delegate = collection; this.ancestor = wrappedCollection; this.ancestorDelegate = wrappedCollection == null ? null : wrappedCollection.getDelegate(); } void refreshIfEmpty() { Collection collection; AbstractMapBasedMultimap.WrappedCollection wrappedCollection = this.ancestor; if (wrappedCollection != null) { wrappedCollection.refreshIfEmpty(); if (this.ancestor.getDelegate() != this.ancestorDelegate) { throw new ConcurrentModificationException(); } } else { if (!this.delegate.isEmpty() || (collection = (Collection) AbstractMapBasedMultimap.this.map.get(this.key)) == null) { return; } this.delegate = collection; } } void removeIfEmpty() { AbstractMapBasedMultimap.WrappedCollection wrappedCollection = this.ancestor; if (wrappedCollection != null) { wrappedCollection.removeIfEmpty(); } else if (this.delegate.isEmpty()) { AbstractMapBasedMultimap.this.map.remove(this.key); } } void addToMap() { AbstractMapBasedMultimap.WrappedCollection wrappedCollection = this.ancestor; if (wrappedCollection == null) { AbstractMapBasedMultimap.this.map.put(this.key, this.delegate); } else { wrappedCollection.addToMap(); } } @Override // java.util.AbstractCollection, java.util.Collection public int size() { refreshIfEmpty(); return this.delegate.size(); } @Override // java.util.Collection public boolean equals(@CheckForNull Object obj) { if (obj == this) { return true; } refreshIfEmpty(); return this.delegate.equals(obj); } @Override // java.util.Collection public int hashCode() { refreshIfEmpty(); return this.delegate.hashCode(); } @Override // java.util.AbstractCollection public String toString() { refreshIfEmpty(); return this.delegate.toString(); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable public Iterator iterator() { refreshIfEmpty(); return new WrappedIterator(); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public class WrappedIterator implements Iterator { final Iterator delegateIterator; final Collection originalDelegate; WrappedIterator() { this.originalDelegate = WrappedCollection.this.delegate; this.delegateIterator = AbstractMapBasedMultimap.iteratorOrListIterator(WrappedCollection.this.delegate); } WrappedIterator(Iterator it) { this.originalDelegate = WrappedCollection.this.delegate; this.delegateIterator = it; } void validateIterator() { WrappedCollection.this.refreshIfEmpty(); if (WrappedCollection.this.delegate != this.originalDelegate) { throw new ConcurrentModificationException(); } } @Override // java.util.Iterator public boolean hasNext() { validateIterator(); return this.delegateIterator.hasNext(); } @Override // java.util.Iterator @ParametricNullness public V next() { validateIterator(); return this.delegateIterator.next(); } @Override // java.util.Iterator public void remove() { this.delegateIterator.remove(); AbstractMapBasedMultimap.access$210(AbstractMapBasedMultimap.this); WrappedCollection.this.removeIfEmpty(); } Iterator getDelegateIterator() { validateIterator(); return this.delegateIterator; } } @Override // java.util.AbstractCollection, java.util.Collection public boolean add(@ParametricNullness V v) { refreshIfEmpty(); boolean isEmpty = this.delegate.isEmpty(); boolean add = this.delegate.add(v); if (add) { AbstractMapBasedMultimap.access$208(AbstractMapBasedMultimap.this); if (isEmpty) { addToMap(); } } return add; } @Override // java.util.AbstractCollection, java.util.Collection public boolean addAll(Collection collection) { if (collection.isEmpty()) { return false; } int size = size(); boolean addAll = this.delegate.addAll(collection); if (addAll) { AbstractMapBasedMultimap.access$212(AbstractMapBasedMultimap.this, this.delegate.size() - size); if (size == 0) { addToMap(); } } return addAll; } @Override // java.util.AbstractCollection, java.util.Collection public boolean contains(@CheckForNull Object obj) { refreshIfEmpty(); return this.delegate.contains(obj); } @Override // java.util.AbstractCollection, java.util.Collection public boolean containsAll(Collection collection) { refreshIfEmpty(); return this.delegate.containsAll(collection); } @Override // java.util.AbstractCollection, java.util.Collection public void clear() { int size = size(); if (size == 0) { return; } this.delegate.clear(); AbstractMapBasedMultimap.access$220(AbstractMapBasedMultimap.this, size); removeIfEmpty(); } @Override // java.util.AbstractCollection, java.util.Collection public boolean remove(@CheckForNull Object obj) { refreshIfEmpty(); boolean remove = this.delegate.remove(obj); if (remove) { AbstractMapBasedMultimap.access$210(AbstractMapBasedMultimap.this); removeIfEmpty(); } return remove; } @Override // java.util.AbstractCollection, java.util.Collection public boolean removeAll(Collection collection) { if (collection.isEmpty()) { return false; } int size = size(); boolean removeAll = this.delegate.removeAll(collection); if (removeAll) { AbstractMapBasedMultimap.access$212(AbstractMapBasedMultimap.this, this.delegate.size() - size); removeIfEmpty(); } return removeAll; } @Override // java.util.AbstractCollection, java.util.Collection public boolean retainAll(Collection collection) { Preconditions.checkNotNull(collection); int size = size(); boolean retainAll = this.delegate.retainAll(collection); if (retainAll) { AbstractMapBasedMultimap.access$212(AbstractMapBasedMultimap.this, this.delegate.size() - size); removeIfEmpty(); } return retainAll; } } /* JADX INFO: Access modifiers changed from: private */ public static Iterator iteratorOrListIterator(Collection collection) { if (collection instanceof List) { return ((List) collection).listIterator(); } return collection.iterator(); } /* loaded from: classes3.dex */ class WrappedSet extends AbstractMapBasedMultimap.WrappedCollection implements Set { /* JADX INFO: Access modifiers changed from: package-private */ public WrappedSet(@ParametricNullness K k, Set set) { super(k, set, null); } @Override // com.google.common.collect.AbstractMapBasedMultimap.WrappedCollection, java.util.AbstractCollection, java.util.Collection public boolean removeAll(Collection collection) { if (collection.isEmpty()) { return false; } int size = size(); boolean removeAllImpl = Sets.removeAllImpl((Set) this.delegate, collection); if (removeAllImpl) { AbstractMapBasedMultimap.access$212(AbstractMapBasedMultimap.this, this.delegate.size() - size); removeIfEmpty(); } return removeAllImpl; } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public class WrappedSortedSet extends AbstractMapBasedMultimap.WrappedCollection implements SortedSet { /* JADX INFO: Access modifiers changed from: package-private */ public WrappedSortedSet(@ParametricNullness K k, SortedSet sortedSet, @CheckForNull AbstractMapBasedMultimap.WrappedCollection wrappedCollection) { super(k, sortedSet, wrappedCollection); } SortedSet getSortedSetDelegate() { return (SortedSet) getDelegate(); } @Override // java.util.SortedSet @CheckForNull public Comparator comparator() { return getSortedSetDelegate().comparator(); } @Override // java.util.SortedSet @ParametricNullness public V first() { refreshIfEmpty(); return getSortedSetDelegate().first(); } @Override // java.util.SortedSet @ParametricNullness public V last() { refreshIfEmpty(); return getSortedSetDelegate().last(); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r4v1, types: [com.google.common.collect.AbstractMapBasedMultimap$WrappedCollection] */ /* JADX WARN: Type inference failed for: r4v3 */ /* JADX WARN: Type inference failed for: r4v4 */ @Override // java.util.SortedSet public SortedSet headSet(@ParametricNullness V v) { refreshIfEmpty(); AbstractMapBasedMultimap abstractMapBasedMultimap = AbstractMapBasedMultimap.this; Object key = getKey(); SortedSet headSet = getSortedSetDelegate().headSet(v); AbstractMapBasedMultimap.WrappedCollection ancestor = getAncestor(); ?? r4 = this; if (ancestor != null) { r4 = getAncestor(); } return new WrappedSortedSet(key, headSet, r4); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r4v1, types: [com.google.common.collect.AbstractMapBasedMultimap$WrappedCollection] */ /* JADX WARN: Type inference failed for: r4v3 */ /* JADX WARN: Type inference failed for: r4v4 */ @Override // java.util.SortedSet public SortedSet subSet(@ParametricNullness V v, @ParametricNullness V v2) { refreshIfEmpty(); AbstractMapBasedMultimap abstractMapBasedMultimap = AbstractMapBasedMultimap.this; Object key = getKey(); SortedSet subSet = getSortedSetDelegate().subSet(v, v2); AbstractMapBasedMultimap.WrappedCollection ancestor = getAncestor(); ?? r4 = this; if (ancestor != null) { r4 = getAncestor(); } return new WrappedSortedSet(key, subSet, r4); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r4v1, types: [com.google.common.collect.AbstractMapBasedMultimap$WrappedCollection] */ /* JADX WARN: Type inference failed for: r4v3 */ /* JADX WARN: Type inference failed for: r4v4 */ @Override // java.util.SortedSet public SortedSet tailSet(@ParametricNullness V v) { refreshIfEmpty(); AbstractMapBasedMultimap abstractMapBasedMultimap = AbstractMapBasedMultimap.this; Object key = getKey(); SortedSet tailSet = getSortedSetDelegate().tailSet(v); AbstractMapBasedMultimap.WrappedCollection ancestor = getAncestor(); ?? r4 = this; if (ancestor != null) { r4 = getAncestor(); } return new WrappedSortedSet(key, tailSet, r4); } } /* loaded from: classes3.dex */ class WrappedNavigableSet extends AbstractMapBasedMultimap.WrappedSortedSet implements NavigableSet { /* JADX INFO: Access modifiers changed from: package-private */ public WrappedNavigableSet(@ParametricNullness K k, NavigableSet navigableSet, @CheckForNull AbstractMapBasedMultimap.WrappedCollection wrappedCollection) { super(k, navigableSet, wrappedCollection); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.AbstractMapBasedMultimap.WrappedSortedSet public NavigableSet getSortedSetDelegate() { return (NavigableSet) super.getSortedSetDelegate(); } @Override // java.util.NavigableSet @CheckForNull public V lower(@ParametricNullness V v) { return getSortedSetDelegate().lower(v); } @Override // java.util.NavigableSet @CheckForNull public V floor(@ParametricNullness V v) { return getSortedSetDelegate().floor(v); } @Override // java.util.NavigableSet @CheckForNull public V ceiling(@ParametricNullness V v) { return getSortedSetDelegate().ceiling(v); } @Override // java.util.NavigableSet @CheckForNull public V higher(@ParametricNullness V v) { return getSortedSetDelegate().higher(v); } @Override // java.util.NavigableSet @CheckForNull public V pollFirst() { return (V) Iterators.pollNext(iterator()); } @Override // java.util.NavigableSet @CheckForNull public V pollLast() { return (V) Iterators.pollNext(descendingIterator()); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r4v1, types: [com.google.common.collect.AbstractMapBasedMultimap$WrappedCollection] */ /* JADX WARN: Type inference failed for: r4v3 */ /* JADX WARN: Type inference failed for: r4v4 */ private NavigableSet wrap(NavigableSet navigableSet) { AbstractMapBasedMultimap abstractMapBasedMultimap = AbstractMapBasedMultimap.this; K k = this.key; AbstractMapBasedMultimap.WrappedCollection ancestor = getAncestor(); ?? r4 = this; if (ancestor != null) { r4 = getAncestor(); } return new WrappedNavigableSet(k, navigableSet, r4); } @Override // java.util.NavigableSet public NavigableSet descendingSet() { return wrap(getSortedSetDelegate().descendingSet()); } @Override // java.util.NavigableSet public Iterator descendingIterator() { return new WrappedCollection.WrappedIterator(getSortedSetDelegate().descendingIterator()); } @Override // java.util.NavigableSet public NavigableSet subSet(@ParametricNullness V v, boolean z, @ParametricNullness V v2, boolean z2) { return wrap(getSortedSetDelegate().subSet(v, z, v2, z2)); } @Override // java.util.NavigableSet public NavigableSet headSet(@ParametricNullness V v, boolean z) { return wrap(getSortedSetDelegate().headSet(v, z)); } @Override // java.util.NavigableSet public NavigableSet tailSet(@ParametricNullness V v, boolean z) { return wrap(getSortedSetDelegate().tailSet(v, z)); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public class WrappedList extends AbstractMapBasedMultimap.WrappedCollection implements List { WrappedList(@ParametricNullness K k, List list, @CheckForNull AbstractMapBasedMultimap.WrappedCollection wrappedCollection) { super(k, list, wrappedCollection); } List getListDelegate() { return (List) getDelegate(); } @Override // java.util.List public boolean addAll(int i, Collection collection) { if (collection.isEmpty()) { return false; } int size = size(); boolean addAll = getListDelegate().addAll(i, collection); if (addAll) { AbstractMapBasedMultimap.access$212(AbstractMapBasedMultimap.this, getDelegate().size() - size); if (size == 0) { addToMap(); } } return addAll; } @Override // java.util.List @ParametricNullness public V get(int i) { refreshIfEmpty(); return getListDelegate().get(i); } @Override // java.util.List @ParametricNullness public V set(int i, @ParametricNullness V v) { refreshIfEmpty(); return getListDelegate().set(i, v); } @Override // java.util.List public void add(int i, @ParametricNullness V v) { refreshIfEmpty(); boolean isEmpty = getDelegate().isEmpty(); getListDelegate().add(i, v); AbstractMapBasedMultimap.access$208(AbstractMapBasedMultimap.this); if (isEmpty) { addToMap(); } } @Override // java.util.List @ParametricNullness public V remove(int i) { refreshIfEmpty(); V remove = getListDelegate().remove(i); AbstractMapBasedMultimap.access$210(AbstractMapBasedMultimap.this); removeIfEmpty(); return remove; } @Override // java.util.List public int indexOf(@CheckForNull Object obj) { refreshIfEmpty(); return getListDelegate().indexOf(obj); } @Override // java.util.List public int lastIndexOf(@CheckForNull Object obj) { refreshIfEmpty(); return getListDelegate().lastIndexOf(obj); } @Override // java.util.List public ListIterator listIterator() { refreshIfEmpty(); return new WrappedListIterator(); } @Override // java.util.List public ListIterator listIterator(int i) { refreshIfEmpty(); return new WrappedListIterator(i); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r0v0, types: [com.google.common.collect.AbstractMapBasedMultimap] */ /* JADX WARN: Type inference failed for: r3v1, types: [com.google.common.collect.AbstractMapBasedMultimap$WrappedCollection] */ /* JADX WARN: Type inference failed for: r3v4 */ /* JADX WARN: Type inference failed for: r3v5 */ @Override // java.util.List public List subList(int i, int i2) { refreshIfEmpty(); ?? r0 = AbstractMapBasedMultimap.this; Object key = getKey(); List subList = getListDelegate().subList(i, i2); AbstractMapBasedMultimap.WrappedCollection ancestor = getAncestor(); ?? r3 = this; if (ancestor != null) { r3 = getAncestor(); } return r0.wrapList(key, subList, r3); } /* loaded from: classes3.dex */ private class WrappedListIterator extends AbstractMapBasedMultimap.WrappedCollection.WrappedIterator implements ListIterator { WrappedListIterator() { super(); } public WrappedListIterator(int i) { super(WrappedList.this.getListDelegate().listIterator(i)); } private ListIterator getDelegateListIterator() { return (ListIterator) getDelegateIterator(); } @Override // java.util.ListIterator public boolean hasPrevious() { return getDelegateListIterator().hasPrevious(); } @Override // java.util.ListIterator @ParametricNullness public V previous() { return getDelegateListIterator().previous(); } @Override // java.util.ListIterator public int nextIndex() { return getDelegateListIterator().nextIndex(); } @Override // java.util.ListIterator public int previousIndex() { return getDelegateListIterator().previousIndex(); } @Override // java.util.ListIterator public void set(@ParametricNullness V v) { getDelegateListIterator().set(v); } @Override // java.util.ListIterator public void add(@ParametricNullness V v) { boolean isEmpty = WrappedList.this.isEmpty(); getDelegateListIterator().add(v); AbstractMapBasedMultimap.access$208(AbstractMapBasedMultimap.this); if (isEmpty) { WrappedList.this.addToMap(); } } } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public class RandomAccessWrappedList extends AbstractMapBasedMultimap.WrappedList implements RandomAccess { RandomAccessWrappedList(@ParametricNullness AbstractMapBasedMultimap abstractMapBasedMultimap, K k, @CheckForNull List list, AbstractMapBasedMultimap.WrappedCollection wrappedCollection) { super(k, list, wrappedCollection); } } @Override // com.google.common.collect.AbstractMultimap Set createKeySet() { return new KeySet(this.map); } /* JADX INFO: Access modifiers changed from: package-private */ public final Set createMaybeNavigableKeySet() { Map> map = this.map; if (map instanceof NavigableMap) { return new NavigableKeySet((NavigableMap) this.map); } if (map instanceof SortedMap) { return new SortedKeySet((SortedMap) this.map); } return new KeySet(this.map); } /* loaded from: classes3.dex */ private class KeySet extends Maps.KeySet> { KeySet(Map> map) { super(map); } @Override // com.google.common.collect.Maps.KeySet, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { final Iterator>> it = map().entrySet().iterator(); return new Iterator() { // from class: com.google.common.collect.AbstractMapBasedMultimap.KeySet.1 @CheckForNull Map.Entry> entry; @Override // java.util.Iterator public boolean hasNext() { return it.hasNext(); } @Override // java.util.Iterator @ParametricNullness public K next() { Map.Entry> entry = (Map.Entry) it.next(); this.entry = entry; return entry.getKey(); } @Override // java.util.Iterator public void remove() { Preconditions.checkState(this.entry != null, "no calls to next() since the last call to remove()"); Collection value = this.entry.getValue(); it.remove(); AbstractMapBasedMultimap.access$220(AbstractMapBasedMultimap.this, value.size()); value.clear(); this.entry = null; } }; } @Override // com.google.common.collect.Maps.KeySet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(@CheckForNull Object obj) { Collection remove = map().remove(obj); if (remove != null) { int size = remove.size(); remove.clear(); AbstractMapBasedMultimap.access$220(AbstractMapBasedMultimap.this, size); if (size > 0) { return true; } } return false; } @Override // com.google.common.collect.Maps.KeySet, java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { Iterators.clear(iterator()); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean containsAll(Collection collection) { return map().keySet().containsAll(collection); } @Override // java.util.AbstractSet, java.util.Collection, java.util.Set public boolean equals(@CheckForNull Object obj) { return this == obj || map().keySet().equals(obj); } @Override // java.util.AbstractSet, java.util.Collection, java.util.Set public int hashCode() { return map().keySet().hashCode(); } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public class SortedKeySet extends AbstractMapBasedMultimap.KeySet implements SortedSet { SortedKeySet(SortedMap> sortedMap) { super(sortedMap); } SortedMap> sortedMap() { return (SortedMap) super.map(); } @Override // java.util.SortedSet @CheckForNull public Comparator comparator() { return sortedMap().comparator(); } @Override // java.util.SortedSet @ParametricNullness public K first() { return sortedMap().firstKey(); } public SortedSet headSet(@ParametricNullness K k) { return new SortedKeySet(sortedMap().headMap(k)); } @Override // java.util.SortedSet @ParametricNullness public K last() { return sortedMap().lastKey(); } public SortedSet subSet(@ParametricNullness K k, @ParametricNullness K k2) { return new SortedKeySet(sortedMap().subMap(k, k2)); } public SortedSet tailSet(@ParametricNullness K k) { return new SortedKeySet(sortedMap().tailMap(k)); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public class NavigableKeySet extends AbstractMapBasedMultimap.SortedKeySet implements NavigableSet { @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedKeySet, java.util.SortedSet, java.util.NavigableSet public /* bridge */ /* synthetic */ SortedSet headSet(@ParametricNullness Object obj) { return headSet((NavigableKeySet) obj); } @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedKeySet, java.util.SortedSet, java.util.NavigableSet public /* bridge */ /* synthetic */ SortedSet tailSet(@ParametricNullness Object obj) { return tailSet((NavigableKeySet) obj); } NavigableKeySet(NavigableMap> navigableMap) { super(navigableMap); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedKeySet public NavigableMap> sortedMap() { return (NavigableMap) super.sortedMap(); } @Override // java.util.NavigableSet @CheckForNull public K lower(@ParametricNullness K k) { return sortedMap().lowerKey(k); } @Override // java.util.NavigableSet @CheckForNull public K floor(@ParametricNullness K k) { return sortedMap().floorKey(k); } @Override // java.util.NavigableSet @CheckForNull public K ceiling(@ParametricNullness K k) { return sortedMap().ceilingKey(k); } @Override // java.util.NavigableSet @CheckForNull public K higher(@ParametricNullness K k) { return sortedMap().higherKey(k); } @Override // java.util.NavigableSet @CheckForNull public K pollFirst() { return (K) Iterators.pollNext(iterator()); } @Override // java.util.NavigableSet @CheckForNull public K pollLast() { return (K) Iterators.pollNext(descendingIterator()); } @Override // java.util.NavigableSet public NavigableSet descendingSet() { return new NavigableKeySet(sortedMap().descendingMap()); } @Override // java.util.NavigableSet public Iterator descendingIterator() { return descendingSet().iterator(); } @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedKeySet, java.util.SortedSet, java.util.NavigableSet public NavigableSet headSet(@ParametricNullness K k) { return headSet(k, false); } @Override // java.util.NavigableSet public NavigableSet headSet(@ParametricNullness K k, boolean z) { return new NavigableKeySet(sortedMap().headMap(k, z)); } @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedKeySet, java.util.SortedSet, java.util.NavigableSet public NavigableSet subSet(@ParametricNullness K k, @ParametricNullness K k2) { return subSet(k, true, k2, false); } @Override // java.util.NavigableSet public NavigableSet subSet(@ParametricNullness K k, boolean z, @ParametricNullness K k2, boolean z2) { return new NavigableKeySet(sortedMap().subMap(k, z, k2, z2)); } @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedKeySet, java.util.SortedSet, java.util.NavigableSet public NavigableSet tailSet(@ParametricNullness K k) { return tailSet(k, true); } @Override // java.util.NavigableSet public NavigableSet tailSet(@ParametricNullness K k, boolean z) { return new NavigableKeySet(sortedMap().tailMap(k, z)); } } /* JADX INFO: Access modifiers changed from: private */ public void removeValuesForKey(@CheckForNull Object obj) { Collection collection = (Collection) Maps.safeRemove(this.map, obj); if (collection != null) { int size = collection.size(); collection.clear(); this.totalSize -= size; } } /* loaded from: classes3.dex */ private abstract class Itr implements Iterator { final Iterator>> keyIterator; @CheckForNull K key = null; @CheckForNull Collection collection = null; Iterator valueIterator = Iterators.emptyModifiableIterator(); abstract T output(@ParametricNullness K k, @ParametricNullness V v); Itr() { this.keyIterator = AbstractMapBasedMultimap.this.map.entrySet().iterator(); } @Override // java.util.Iterator public boolean hasNext() { return this.keyIterator.hasNext() || this.valueIterator.hasNext(); } @Override // java.util.Iterator public T next() { if (!this.valueIterator.hasNext()) { Map.Entry> next = this.keyIterator.next(); this.key = next.getKey(); Collection value = next.getValue(); this.collection = value; this.valueIterator = value.iterator(); } return output(NullnessCasts.uncheckedCastNullableTToT(this.key), this.valueIterator.next()); } @Override // java.util.Iterator public void remove() { this.valueIterator.remove(); if (((Collection) Objects.requireNonNull(this.collection)).isEmpty()) { this.keyIterator.remove(); } AbstractMapBasedMultimap.access$210(AbstractMapBasedMultimap.this); } } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public Collection values() { return super.values(); } @Override // com.google.common.collect.AbstractMultimap Collection createValues() { return new AbstractMultimap.Values(); } @Override // com.google.common.collect.AbstractMultimap Iterator valueIterator() { return new AbstractMapBasedMultimap.Itr(this) { // from class: com.google.common.collect.AbstractMapBasedMultimap.1 @Override // com.google.common.collect.AbstractMapBasedMultimap.Itr @ParametricNullness V output(@ParametricNullness K k, @ParametricNullness V v) { return v; } }; } @Override // com.google.common.collect.AbstractMultimap Multiset createKeys() { return new Multimaps.Keys(this); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public Collection> entries() { return super.entries(); } @Override // com.google.common.collect.AbstractMultimap Collection> createEntries() { if (this instanceof SetMultimap) { return new AbstractMultimap.EntrySet(this); } return new AbstractMultimap.Entries(); } @Override // com.google.common.collect.AbstractMultimap Iterator> entryIterator() { return new AbstractMapBasedMultimap.Itr>(this) { // from class: com.google.common.collect.AbstractMapBasedMultimap.2 @Override // com.google.common.collect.AbstractMapBasedMultimap.Itr /* bridge */ /* synthetic */ Object output(@ParametricNullness Object obj, @ParametricNullness Object obj2) { return output((AnonymousClass2) obj, obj2); } @Override // com.google.common.collect.AbstractMapBasedMultimap.Itr Map.Entry output(@ParametricNullness K k, @ParametricNullness V v) { return Maps.immutableEntry(k, v); } }; } @Override // com.google.common.collect.AbstractMultimap Map> createAsMap() { return new AsMap(this.map); } /* JADX INFO: Access modifiers changed from: package-private */ public final Map> createMaybeNavigableAsMap() { Map> map = this.map; if (map instanceof NavigableMap) { return new NavigableAsMap((NavigableMap) this.map); } if (map instanceof SortedMap) { return new SortedAsMap((SortedMap) this.map); } return new AsMap(this.map); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public class AsMap extends Maps.ViewCachingAbstractMap> { final transient Map> submap; AsMap(Map> map) { this.submap = map; } @Override // com.google.common.collect.Maps.ViewCachingAbstractMap protected Set>> createEntrySet() { return new AsMapEntries(); } @Override // java.util.AbstractMap, java.util.Map public boolean containsKey(@CheckForNull Object obj) { return Maps.safeContainsKey(this.submap, obj); } @Override // java.util.AbstractMap, java.util.Map @CheckForNull public Collection get(@CheckForNull Object obj) { Collection collection = (Collection) Maps.safeGet(this.submap, obj); if (collection == null) { return null; } return AbstractMapBasedMultimap.this.wrapCollection(obj, collection); } @Override // com.google.common.collect.Maps.ViewCachingAbstractMap, java.util.AbstractMap, java.util.Map public Set keySet() { return AbstractMapBasedMultimap.this.keySet(); } @Override // java.util.AbstractMap, java.util.Map public int size() { return this.submap.size(); } @Override // java.util.AbstractMap, java.util.Map @CheckForNull public Collection remove(@CheckForNull Object obj) { Collection remove = this.submap.remove(obj); if (remove == null) { return null; } Collection createCollection = AbstractMapBasedMultimap.this.createCollection(); createCollection.addAll(remove); AbstractMapBasedMultimap.access$220(AbstractMapBasedMultimap.this, remove.size()); remove.clear(); return createCollection; } @Override // java.util.AbstractMap, java.util.Map public boolean equals(@CheckForNull Object obj) { return this == obj || this.submap.equals(obj); } @Override // java.util.AbstractMap, java.util.Map public int hashCode() { return this.submap.hashCode(); } @Override // java.util.AbstractMap public String toString() { return this.submap.toString(); } @Override // java.util.AbstractMap, java.util.Map public void clear() { if (this.submap == AbstractMapBasedMultimap.this.map) { AbstractMapBasedMultimap.this.clear(); } else { Iterators.clear(new AsMapIterator()); } } Map.Entry> wrapEntry(Map.Entry> entry) { K key = entry.getKey(); return Maps.immutableEntry(key, AbstractMapBasedMultimap.this.wrapCollection(key, entry.getValue())); } /* loaded from: classes3.dex */ class AsMapEntries extends Maps.EntrySet> { @Override // com.google.common.collect.Maps.EntrySet Map> map() { return AsMap.this; } AsMapEntries() { } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator>> iterator() { return new AsMapIterator(); } @Override // com.google.common.collect.Maps.EntrySet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(@CheckForNull Object obj) { return Collections2.safeContains(AsMap.this.submap.entrySet(), obj); } @Override // com.google.common.collect.Maps.EntrySet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(@CheckForNull Object obj) { if (!contains(obj)) { return false; } AbstractMapBasedMultimap.this.removeValuesForKey(((Map.Entry) Objects.requireNonNull((Map.Entry) obj)).getKey()); return true; } } /* loaded from: classes3.dex */ class AsMapIterator implements Iterator>> { @CheckForNull Collection collection; final Iterator>> delegateIterator; AsMapIterator() { this.delegateIterator = AsMap.this.submap.entrySet().iterator(); } @Override // java.util.Iterator public boolean hasNext() { return this.delegateIterator.hasNext(); } @Override // java.util.Iterator public Map.Entry> next() { Map.Entry> next = this.delegateIterator.next(); this.collection = next.getValue(); return AsMap.this.wrapEntry(next); } @Override // java.util.Iterator public void remove() { Preconditions.checkState(this.collection != null, "no calls to next() since the last call to remove()"); this.delegateIterator.remove(); AbstractMapBasedMultimap.access$220(AbstractMapBasedMultimap.this, this.collection.size()); this.collection.clear(); this.collection = null; } } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public class SortedAsMap extends AbstractMapBasedMultimap.AsMap implements SortedMap> { @CheckForNull SortedSet sortedKeySet; SortedAsMap(SortedMap> sortedMap) { super(sortedMap); } SortedMap> sortedMap() { return (SortedMap) this.submap; } @Override // java.util.SortedMap @CheckForNull public Comparator comparator() { return sortedMap().comparator(); } @Override // java.util.SortedMap @ParametricNullness public K firstKey() { return sortedMap().firstKey(); } @Override // java.util.SortedMap @ParametricNullness public K lastKey() { return sortedMap().lastKey(); } public SortedMap> headMap(@ParametricNullness K k) { return new SortedAsMap(sortedMap().headMap(k)); } public SortedMap> subMap(@ParametricNullness K k, @ParametricNullness K k2) { return new SortedAsMap(sortedMap().subMap(k, k2)); } public SortedMap> tailMap(@ParametricNullness K k) { return new SortedAsMap(sortedMap().tailMap(k)); } @Override // com.google.common.collect.AbstractMapBasedMultimap.AsMap, com.google.common.collect.Maps.ViewCachingAbstractMap, java.util.AbstractMap, java.util.Map public SortedSet keySet() { SortedSet sortedSet = this.sortedKeySet; if (sortedSet != null) { return sortedSet; } SortedSet createKeySet = createKeySet(); this.sortedKeySet = createKeySet; return createKeySet; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.Maps.ViewCachingAbstractMap public SortedSet createKeySet() { return new SortedKeySet(sortedMap()); } } /* loaded from: classes3.dex */ class NavigableAsMap extends AbstractMapBasedMultimap.SortedAsMap implements NavigableMap> { @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedAsMap, java.util.SortedMap, java.util.NavigableMap public /* bridge */ /* synthetic */ SortedMap headMap(@ParametricNullness Object obj) { return headMap((NavigableAsMap) obj); } @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedAsMap, java.util.SortedMap, java.util.NavigableMap public /* bridge */ /* synthetic */ SortedMap tailMap(@ParametricNullness Object obj) { return tailMap((NavigableAsMap) obj); } NavigableAsMap(NavigableMap> navigableMap) { super(navigableMap); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedAsMap public NavigableMap> sortedMap() { return (NavigableMap) super.sortedMap(); } @Override // java.util.NavigableMap @CheckForNull public Map.Entry> lowerEntry(@ParametricNullness K k) { Map.Entry> lowerEntry = sortedMap().lowerEntry(k); if (lowerEntry == null) { return null; } return wrapEntry(lowerEntry); } @Override // java.util.NavigableMap @CheckForNull public K lowerKey(@ParametricNullness K k) { return sortedMap().lowerKey(k); } @Override // java.util.NavigableMap @CheckForNull public Map.Entry> floorEntry(@ParametricNullness K k) { Map.Entry> floorEntry = sortedMap().floorEntry(k); if (floorEntry == null) { return null; } return wrapEntry(floorEntry); } @Override // java.util.NavigableMap @CheckForNull public K floorKey(@ParametricNullness K k) { return sortedMap().floorKey(k); } @Override // java.util.NavigableMap @CheckForNull public Map.Entry> ceilingEntry(@ParametricNullness K k) { Map.Entry> ceilingEntry = sortedMap().ceilingEntry(k); if (ceilingEntry == null) { return null; } return wrapEntry(ceilingEntry); } @Override // java.util.NavigableMap @CheckForNull public K ceilingKey(@ParametricNullness K k) { return sortedMap().ceilingKey(k); } @Override // java.util.NavigableMap @CheckForNull public Map.Entry> higherEntry(@ParametricNullness K k) { Map.Entry> higherEntry = sortedMap().higherEntry(k); if (higherEntry == null) { return null; } return wrapEntry(higherEntry); } @Override // java.util.NavigableMap @CheckForNull public K higherKey(@ParametricNullness K k) { return sortedMap().higherKey(k); } @Override // java.util.NavigableMap @CheckForNull public Map.Entry> firstEntry() { Map.Entry> firstEntry = sortedMap().firstEntry(); if (firstEntry == null) { return null; } return wrapEntry(firstEntry); } @Override // java.util.NavigableMap @CheckForNull public Map.Entry> lastEntry() { Map.Entry> lastEntry = sortedMap().lastEntry(); if (lastEntry == null) { return null; } return wrapEntry(lastEntry); } @Override // java.util.NavigableMap @CheckForNull public Map.Entry> pollFirstEntry() { return pollAsMapEntry(entrySet().iterator()); } @Override // java.util.NavigableMap @CheckForNull public Map.Entry> pollLastEntry() { return pollAsMapEntry(descendingMap().entrySet().iterator()); } @CheckForNull Map.Entry> pollAsMapEntry(Iterator>> it) { if (!it.hasNext()) { return null; } Map.Entry> next = it.next(); Collection createCollection = AbstractMapBasedMultimap.this.createCollection(); createCollection.addAll(next.getValue()); it.remove(); return Maps.immutableEntry(next.getKey(), AbstractMapBasedMultimap.this.unmodifiableCollectionSubclass(createCollection)); } @Override // java.util.NavigableMap public NavigableMap> descendingMap() { return new NavigableAsMap(sortedMap().descendingMap()); } @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedAsMap, com.google.common.collect.AbstractMapBasedMultimap.AsMap, com.google.common.collect.Maps.ViewCachingAbstractMap, java.util.AbstractMap, java.util.Map public NavigableSet keySet() { return (NavigableSet) super.keySet(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedAsMap, com.google.common.collect.Maps.ViewCachingAbstractMap public NavigableSet createKeySet() { return new NavigableKeySet(sortedMap()); } @Override // java.util.NavigableMap public NavigableSet navigableKeySet() { return keySet(); } @Override // java.util.NavigableMap public NavigableSet descendingKeySet() { return descendingMap().navigableKeySet(); } @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedAsMap, java.util.SortedMap, java.util.NavigableMap public NavigableMap> subMap(@ParametricNullness K k, @ParametricNullness K k2) { return subMap(k, true, k2, false); } @Override // java.util.NavigableMap public NavigableMap> subMap(@ParametricNullness K k, boolean z, @ParametricNullness K k2, boolean z2) { return new NavigableAsMap(sortedMap().subMap(k, z, k2, z2)); } @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedAsMap, java.util.SortedMap, java.util.NavigableMap public NavigableMap> headMap(@ParametricNullness K k) { return headMap(k, false); } @Override // java.util.NavigableMap public NavigableMap> headMap(@ParametricNullness K k, boolean z) { return new NavigableAsMap(sortedMap().headMap(k, z)); } @Override // com.google.common.collect.AbstractMapBasedMultimap.SortedAsMap, java.util.SortedMap, java.util.NavigableMap public NavigableMap> tailMap(@ParametricNullness K k) { return tailMap(k, true); } @Override // java.util.NavigableMap public NavigableMap> tailMap(@ParametricNullness K k, boolean z) { return new NavigableAsMap(sortedMap().tailMap(k, z)); } } }