jimu-decompiled/sources/com/squareup/haha/guava/collect/AbstractMapBasedMultimap.java
2025-05-13 19:24:51 +02:00

950 lines
34 KiB
Java

package com.squareup.haha.guava.collect;
import com.squareup.haha.guava.base.Joiner;
import com.squareup.haha.guava.collect.Maps;
import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.Collection;
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.RandomAccess;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
/* loaded from: classes.dex */
abstract class AbstractMapBasedMultimap<K, V> extends AbstractMultimap<K, V> implements Serializable {
private transient Map<K, Collection<V>> map;
private transient int totalSize;
class AsMap extends Maps.ImprovedAbstractMap<K, Collection<V>> {
final transient Map<K, Collection<V>> submap;
class AsMapEntries extends Maps.EntrySet<K, Collection<V>> {
AsMapEntries() {
}
@Override // com.squareup.haha.guava.collect.Maps.EntrySet, java.util.AbstractCollection, java.util.Collection, java.util.Set
public final boolean contains(Object obj) {
return Collections2.safeContains(AsMap.this.submap.entrySet(), obj);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
public final Iterator<Map.Entry<K, Collection<V>>> iterator() {
return AsMap.this.new AsMapIterator();
}
@Override // com.squareup.haha.guava.collect.Maps.EntrySet
final Map<K, Collection<V>> map() {
return AsMap.this;
}
@Override // com.squareup.haha.guava.collect.Maps.EntrySet, java.util.AbstractCollection, java.util.Collection, java.util.Set
public final boolean remove(Object obj) {
if (!contains(obj)) {
return false;
}
AbstractMapBasedMultimap.access$400(AbstractMapBasedMultimap.this, ((Map.Entry) obj).getKey());
return true;
}
}
class AsMapIterator implements Iterator<Map.Entry<K, Collection<V>>> {
private Collection<V> collection;
private Iterator<Map.Entry<K, Collection<V>>> delegateIterator;
AsMapIterator() {
this.delegateIterator = AsMap.this.submap.entrySet().iterator();
}
@Override // java.util.Iterator
public final boolean hasNext() {
return this.delegateIterator.hasNext();
}
@Override // java.util.Iterator
public final /* bridge */ /* synthetic */ Object next() {
Map.Entry<K, Collection<V>> next = this.delegateIterator.next();
this.collection = next.getValue();
AsMap asMap = AsMap.this;
K key = next.getKey();
return Maps.immutableEntry(key, AbstractMapBasedMultimap.this.wrapCollection(key, next.getValue()));
}
@Override // java.util.Iterator
public final void remove() {
this.delegateIterator.remove();
AbstractMapBasedMultimap.access$220(AbstractMapBasedMultimap.this, this.collection.size());
this.collection.clear();
}
}
AsMap(Map<K, Collection<V>> map) {
this.submap = map;
}
@Override // java.util.AbstractMap, java.util.Map
public void clear() {
if (this.submap == AbstractMapBasedMultimap.this.map) {
AbstractMapBasedMultimap.this.clear();
} else {
Iterators.clear(new AsMapIterator());
}
}
@Override // java.util.AbstractMap, java.util.Map
public boolean containsKey(Object obj) {
return Maps.safeContainsKey(this.submap, obj);
}
@Override // com.squareup.haha.guava.collect.Maps.ImprovedAbstractMap
protected final Set<Map.Entry<K, Collection<V>>> createEntrySet() {
return new AsMapEntries();
}
@Override // java.util.AbstractMap, java.util.Map
public boolean equals(Object obj) {
return this == obj || this.submap.equals(obj);
}
@Override // java.util.AbstractMap, java.util.Map
public /* bridge */ /* synthetic */ Object get(Object obj) {
Collection<V> collection = (Collection) Maps.safeGet(this.submap, obj);
if (collection == null) {
return null;
}
return AbstractMapBasedMultimap.this.wrapCollection(obj, collection);
}
@Override // java.util.AbstractMap, java.util.Map
public int hashCode() {
return this.submap.hashCode();
}
@Override // com.squareup.haha.guava.collect.Maps.ImprovedAbstractMap, java.util.AbstractMap, java.util.Map
public Set<K> keySet() {
return AbstractMapBasedMultimap.this.keySet();
}
@Override // java.util.AbstractMap, java.util.Map
public /* bridge */ /* synthetic */ Object remove(Object obj) {
Collection<V> remove = this.submap.remove(obj);
if (remove == null) {
return null;
}
Collection<V> 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 int size() {
return this.submap.size();
}
@Override // java.util.AbstractMap
public String toString() {
return this.submap.toString();
}
}
abstract class Itr<T> implements Iterator<T> {
private Iterator<Map.Entry<K, Collection<V>>> keyIterator;
private K key = null;
private Collection<V> collection = null;
private Iterator<V> valueIterator = Iterators.emptyModifiableIterator();
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<K, Collection<V>> next = this.keyIterator.next();
this.key = next.getKey();
this.collection = next.getValue();
this.valueIterator = this.collection.iterator();
}
return output(this.key, this.valueIterator.next());
}
abstract T output(K k, V v);
@Override // java.util.Iterator
public void remove() {
this.valueIterator.remove();
if (this.collection.isEmpty()) {
this.keyIterator.remove();
}
AbstractMapBasedMultimap.access$210(AbstractMapBasedMultimap.this);
}
}
class KeySet extends Maps.KeySet<K, Collection<V>> {
KeySet(Map<K, Collection<V>> map) {
super(map);
}
@Override // com.squareup.haha.guava.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 this.map.keySet().containsAll(collection);
}
@Override // java.util.AbstractSet, java.util.Collection, java.util.Set
public boolean equals(Object obj) {
return this == obj || this.map.keySet().equals(obj);
}
@Override // java.util.AbstractSet, java.util.Collection, java.util.Set
public int hashCode() {
return this.map.keySet().hashCode();
}
@Override // com.squareup.haha.guava.collect.Maps.KeySet, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
public Iterator<K> iterator() {
final Iterator<Map.Entry<K, V>> it = this.map.entrySet().iterator();
return new Iterator<K>() { // from class: com.squareup.haha.guava.collect.AbstractMapBasedMultimap.KeySet.1
private Map.Entry<K, Collection<V>> entry;
@Override // java.util.Iterator
public final boolean hasNext() {
return it.hasNext();
}
@Override // java.util.Iterator
public final K next() {
this.entry = (Map.Entry) it.next();
return this.entry.getKey();
}
@Override // java.util.Iterator
public final void remove() {
Joiner.checkRemove(this.entry != null);
Collection<V> value = this.entry.getValue();
it.remove();
AbstractMapBasedMultimap.access$220(AbstractMapBasedMultimap.this, value.size());
value.clear();
}
};
}
@Override // com.squareup.haha.guava.collect.Maps.KeySet, java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean remove(Object obj) {
int i;
Collection collection = (Collection) this.map.remove(obj);
if (collection != null) {
i = collection.size();
collection.clear();
AbstractMapBasedMultimap.access$220(AbstractMapBasedMultimap.this, i);
} else {
i = 0;
}
return i > 0;
}
}
class RandomAccessWrappedList extends WrappedList implements RandomAccess {
RandomAccessWrappedList(AbstractMapBasedMultimap abstractMapBasedMultimap, Object obj, List list, WrappedCollection wrappedCollection) {
super(obj, list, wrappedCollection);
}
}
class SortedAsMap extends AsMap implements SortedMap {
private SortedSet<K> sortedKeySet;
SortedAsMap(SortedMap<K, Collection<V>> sortedMap) {
super(sortedMap);
}
@Override // java.util.SortedMap
public final Comparator<? super K> comparator() {
return ((SortedMap) this.submap).comparator();
}
@Override // java.util.SortedMap
public final K firstKey() {
return (K) ((SortedMap) this.submap).firstKey();
}
@Override // java.util.SortedMap
public final SortedMap<K, Collection<V>> headMap(K k) {
return new SortedAsMap(((SortedMap) this.submap).headMap(k));
}
@Override // com.squareup.haha.guava.collect.AbstractMapBasedMultimap.AsMap, com.squareup.haha.guava.collect.Maps.ImprovedAbstractMap, java.util.AbstractMap, java.util.Map
public final /* bridge */ /* synthetic */ Set keySet() {
SortedSet<K> sortedSet = this.sortedKeySet;
if (sortedSet != null) {
return sortedSet;
}
SortedSet<K> mo16createKeySet = mo16createKeySet();
this.sortedKeySet = mo16createKeySet;
return mo16createKeySet;
}
@Override // java.util.SortedMap
public final K lastKey() {
return (K) ((SortedMap) this.submap).lastKey();
}
@Override // java.util.SortedMap
public final SortedMap<K, Collection<V>> subMap(K k, K k2) {
return new SortedAsMap(((SortedMap) this.submap).subMap(k, k2));
}
@Override // java.util.SortedMap
public final SortedMap<K, Collection<V>> tailMap(K k) {
return new SortedAsMap(((SortedMap) this.submap).tailMap(k));
}
/* JADX INFO: Access modifiers changed from: private */
@Override // com.squareup.haha.guava.collect.Maps.ImprovedAbstractMap
/* renamed from: createKeySet, reason: merged with bridge method [inline-methods] */
public SortedSet<K> mo16createKeySet() {
return new SortedKeySet((SortedMap) this.submap);
}
}
class SortedKeySet extends KeySet implements SortedSet {
SortedKeySet(SortedMap<K, Collection<V>> sortedMap) {
super(sortedMap);
}
private SortedMap<K, Collection<V>> sortedMap() {
return (SortedMap) this.map;
}
@Override // java.util.SortedSet
public final Comparator<? super K> comparator() {
return sortedMap().comparator();
}
@Override // java.util.SortedSet
public final K first() {
return sortedMap().firstKey();
}
@Override // java.util.SortedSet
public final SortedSet<K> headSet(K k) {
return new SortedKeySet(sortedMap().headMap(k));
}
@Override // java.util.SortedSet
public final K last() {
return sortedMap().lastKey();
}
@Override // java.util.SortedSet
public final SortedSet<K> subSet(K k, K k2) {
return new SortedKeySet(sortedMap().subMap(k, k2));
}
@Override // java.util.SortedSet
public final SortedSet<K> tailSet(K k) {
return new SortedKeySet(sortedMap().tailMap(k));
}
}
class WrappedSet extends WrappedCollection implements Set {
WrappedSet(K k, Set<V> set) {
super(k, set, null);
}
@Override // com.squareup.haha.guava.collect.AbstractMapBasedMultimap.WrappedCollection, java.util.AbstractCollection, java.util.Collection
public final boolean removeAll(Collection<?> collection) {
if (collection.isEmpty()) {
return false;
}
int size = size();
boolean removeAllImpl = Joiner.removeAllImpl((Set<?>) this.delegate, collection);
if (removeAllImpl) {
AbstractMapBasedMultimap.access$212(AbstractMapBasedMultimap.this, this.delegate.size() - size);
removeIfEmpty();
}
return removeAllImpl;
}
}
class WrappedSortedSet extends WrappedCollection implements SortedSet {
WrappedSortedSet(Object obj, SortedSet sortedSet, WrappedCollection wrappedCollection) {
super(obj, sortedSet, wrappedCollection);
}
private SortedSet<V> getSortedSetDelegate() {
return (SortedSet) this.delegate;
}
@Override // java.util.SortedSet
public final Comparator<? super V> comparator() {
return getSortedSetDelegate().comparator();
}
@Override // java.util.SortedSet
public final V first() {
refreshIfEmpty();
return getSortedSetDelegate().first();
}
@Override // java.util.SortedSet
public final SortedSet<V> headSet(V v) {
refreshIfEmpty();
AbstractMapBasedMultimap abstractMapBasedMultimap = AbstractMapBasedMultimap.this;
K k = this.key;
SortedSet<V> headSet = getSortedSetDelegate().headSet(v);
WrappedCollection wrappedCollection = this.ancestor;
if (wrappedCollection == null) {
wrappedCollection = this;
}
return new WrappedSortedSet(k, headSet, wrappedCollection);
}
@Override // java.util.SortedSet
public final V last() {
refreshIfEmpty();
return getSortedSetDelegate().last();
}
@Override // java.util.SortedSet
public final SortedSet<V> subSet(V v, V v2) {
refreshIfEmpty();
AbstractMapBasedMultimap abstractMapBasedMultimap = AbstractMapBasedMultimap.this;
K k = this.key;
SortedSet<V> subSet = getSortedSetDelegate().subSet(v, v2);
WrappedCollection wrappedCollection = this.ancestor;
if (wrappedCollection == null) {
wrappedCollection = this;
}
return new WrappedSortedSet(k, subSet, wrappedCollection);
}
@Override // java.util.SortedSet
public final SortedSet<V> tailSet(V v) {
refreshIfEmpty();
AbstractMapBasedMultimap abstractMapBasedMultimap = AbstractMapBasedMultimap.this;
K k = this.key;
SortedSet<V> tailSet = getSortedSetDelegate().tailSet(v);
WrappedCollection wrappedCollection = this.ancestor;
if (wrappedCollection == null) {
wrappedCollection = this;
}
return new WrappedSortedSet(k, tailSet, wrappedCollection);
}
}
protected AbstractMapBasedMultimap(Map<K, Collection<V>> map) {
Joiner.checkArgument(map.isEmpty());
this.map = map;
}
static /* synthetic */ Iterator access$100(AbstractMapBasedMultimap abstractMapBasedMultimap, Collection collection) {
return collection instanceof List ? ((List) collection).listIterator() : collection.iterator();
}
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;
}
static /* synthetic */ int access$400(AbstractMapBasedMultimap abstractMapBasedMultimap, Object obj) {
Collection collection = (Collection) Maps.safeRemove(abstractMapBasedMultimap.map, obj);
if (collection == null) {
return 0;
}
int size = collection.size();
collection.clear();
abstractMapBasedMultimap.totalSize -= size;
return size;
}
/* JADX INFO: Access modifiers changed from: private */
public List wrapList(Object obj, List list, WrappedCollection wrappedCollection) {
return list instanceof RandomAccess ? new RandomAccessWrappedList(this, obj, list, wrappedCollection) : new WrappedList(obj, list, wrappedCollection);
}
@Override // com.squareup.haha.guava.collect.Multimap
public void clear() {
Iterator<Collection<V>> it = this.map.values().iterator();
while (it.hasNext()) {
it.next().clear();
}
this.map.clear();
this.totalSize = 0;
}
@Override // com.squareup.haha.guava.collect.AbstractMultimap
final Map<K, Collection<V>> createAsMap() {
Map<K, Collection<V>> map = this.map;
return map instanceof SortedMap ? new SortedAsMap((SortedMap) map) : new AsMap(map);
}
abstract Collection<V> createCollection();
@Override // com.squareup.haha.guava.collect.AbstractMultimap
final Set<K> createKeySet() {
Map<K, Collection<V>> map = this.map;
return map instanceof SortedMap ? new SortedKeySet((SortedMap) map) : new KeySet(map);
}
@Override // com.squareup.haha.guava.collect.AbstractMultimap
public Collection<Map.Entry<K, V>> entries() {
return super.entries();
}
@Override // com.squareup.haha.guava.collect.AbstractMultimap
final Iterator<Map.Entry<K, V>> entryIterator() {
return new Itr(this) { // from class: com.squareup.haha.guava.collect.AbstractMapBasedMultimap.2
@Override // com.squareup.haha.guava.collect.AbstractMapBasedMultimap.Itr
final /* bridge */ /* synthetic */ Object output(Object obj, Object obj2) {
return Maps.immutableEntry(obj, obj2);
}
};
}
@Override // com.squareup.haha.guava.collect.Multimap
public Collection<V> get(K k) {
Collection<V> collection = this.map.get(k);
if (collection == null) {
collection = createCollection();
}
return wrapCollection(k, collection);
}
@Override // com.squareup.haha.guava.collect.AbstractMultimap, com.squareup.haha.guava.collect.Multimap
public boolean put(K k, V v) {
Collection<V> collection = this.map.get(k);
if (collection != null) {
if (!collection.add(v)) {
return false;
}
this.totalSize++;
return true;
}
Collection<V> createCollection = createCollection();
if (!createCollection.add(v)) {
throw new AssertionError("New Collection violated the Collection spec");
}
this.totalSize++;
this.map.put(k, createCollection);
return true;
}
@Override // com.squareup.haha.guava.collect.Multimap
public int size() {
return this.totalSize;
}
@Override // com.squareup.haha.guava.collect.AbstractMultimap
final Iterator<V> valueIterator() {
return new Itr(this) { // from class: com.squareup.haha.guava.collect.AbstractMapBasedMultimap.1
@Override // com.squareup.haha.guava.collect.AbstractMapBasedMultimap.Itr
final V output(K k, V v) {
return v;
}
};
}
@Override // com.squareup.haha.guava.collect.AbstractMultimap, com.squareup.haha.guava.collect.Multimap
public Collection<V> values() {
return super.values();
}
final Collection<V> wrapCollection(K k, Collection<V> collection) {
return collection instanceof SortedSet ? new WrappedSortedSet(k, (SortedSet) collection, null) : collection instanceof Set ? new WrappedSet(k, (Set) collection) : collection instanceof List ? wrapList(k, (List) collection, null) : new WrappedCollection(k, collection, null);
}
class WrappedCollection extends AbstractCollection<V> {
final WrappedCollection ancestor;
private Collection<V> ancestorDelegate;
Collection<V> delegate;
final K key;
/* JADX WARN: Multi-variable type inference failed */
WrappedCollection(Object obj, Collection collection, WrappedCollection wrappedCollection) {
this.key = obj;
this.delegate = collection;
this.ancestor = wrappedCollection;
this.ancestorDelegate = wrappedCollection == null ? null : wrappedCollection.delegate;
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean add(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<? extends V> 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;
}
final void addToMap() {
WrappedCollection wrappedCollection = this.ancestor;
if (wrappedCollection != null) {
wrappedCollection.addToMap();
} else {
AbstractMapBasedMultimap.this.map.put(this.key, this.delegate);
}
}
@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 contains(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.Collection
public boolean equals(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, java.util.Collection, java.lang.Iterable
public Iterator<V> iterator() {
refreshIfEmpty();
return new WrappedIterator();
}
final void refreshIfEmpty() {
Collection<V> collection;
WrappedCollection wrappedCollection = this.ancestor;
if (wrappedCollection != null) {
wrappedCollection.refreshIfEmpty();
if (this.ancestor.delegate != this.ancestorDelegate) {
throw new ConcurrentModificationException();
}
} else {
if (!this.delegate.isEmpty() || (collection = (Collection) AbstractMapBasedMultimap.this.map.get(this.key)) == null) {
return;
}
this.delegate = collection;
}
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean remove(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;
}
final void removeIfEmpty() {
WrappedCollection wrappedCollection = this.ancestor;
if (wrappedCollection != null) {
wrappedCollection.removeIfEmpty();
} else if (this.delegate.isEmpty()) {
AbstractMapBasedMultimap.this.map.remove(this.key);
}
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean retainAll(Collection<?> collection) {
Joiner.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;
}
@Override // java.util.AbstractCollection, java.util.Collection
public int size() {
refreshIfEmpty();
return this.delegate.size();
}
@Override // java.util.AbstractCollection
public String toString() {
refreshIfEmpty();
return this.delegate.toString();
}
class WrappedIterator implements Iterator<V> {
final Iterator<V> delegateIterator;
private Collection<V> originalDelegate;
WrappedIterator() {
this.originalDelegate = WrappedCollection.this.delegate;
this.delegateIterator = AbstractMapBasedMultimap.access$100(AbstractMapBasedMultimap.this, WrappedCollection.this.delegate);
}
@Override // java.util.Iterator
public boolean hasNext() {
validateIterator();
return this.delegateIterator.hasNext();
}
@Override // java.util.Iterator
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();
}
final void validateIterator() {
WrappedCollection.this.refreshIfEmpty();
if (WrappedCollection.this.delegate != this.originalDelegate) {
throw new ConcurrentModificationException();
}
}
WrappedIterator(Iterator<V> it) {
this.originalDelegate = WrappedCollection.this.delegate;
this.delegateIterator = it;
}
}
}
class WrappedList extends WrappedCollection implements List {
class WrappedListIterator extends WrappedCollection.WrappedIterator implements ListIterator {
WrappedListIterator() {
super();
}
private ListIterator<V> getDelegateListIterator() {
validateIterator();
return (ListIterator) this.delegateIterator;
}
@Override // java.util.ListIterator
public final void add(V v) {
boolean isEmpty = WrappedList.this.isEmpty();
getDelegateListIterator().add(v);
AbstractMapBasedMultimap.access$208(AbstractMapBasedMultimap.this);
if (isEmpty) {
WrappedList.this.addToMap();
}
}
@Override // java.util.ListIterator
public final boolean hasPrevious() {
return getDelegateListIterator().hasPrevious();
}
@Override // java.util.ListIterator
public final int nextIndex() {
return getDelegateListIterator().nextIndex();
}
@Override // java.util.ListIterator
public final V previous() {
return getDelegateListIterator().previous();
}
@Override // java.util.ListIterator
public final int previousIndex() {
return getDelegateListIterator().previousIndex();
}
@Override // java.util.ListIterator
public final void set(V v) {
getDelegateListIterator().set(v);
}
public WrappedListIterator(int i) {
super(WrappedList.this.getListDelegate().listIterator(i));
}
}
WrappedList(Object obj, List list, WrappedCollection wrappedCollection) {
super(obj, list, wrappedCollection);
}
@Override // java.util.List
public void add(int i, V v) {
refreshIfEmpty();
boolean isEmpty = this.delegate.isEmpty();
getListDelegate().add(i, v);
AbstractMapBasedMultimap.access$208(AbstractMapBasedMultimap.this);
if (isEmpty) {
addToMap();
}
}
@Override // java.util.List
public boolean addAll(int i, Collection<? extends V> collection) {
if (collection.isEmpty()) {
return false;
}
int size = size();
boolean addAll = getListDelegate().addAll(i, collection);
if (addAll) {
AbstractMapBasedMultimap.access$212(AbstractMapBasedMultimap.this, this.delegate.size() - size);
if (size == 0) {
addToMap();
}
}
return addAll;
}
@Override // java.util.List
public V get(int i) {
refreshIfEmpty();
return getListDelegate().get(i);
}
final List<V> getListDelegate() {
return (List) this.delegate;
}
@Override // java.util.List
public int indexOf(Object obj) {
refreshIfEmpty();
return getListDelegate().indexOf(obj);
}
@Override // java.util.List
public int lastIndexOf(Object obj) {
refreshIfEmpty();
return getListDelegate().lastIndexOf(obj);
}
@Override // java.util.List
public ListIterator<V> listIterator() {
refreshIfEmpty();
return new WrappedListIterator();
}
@Override // java.util.List
public V remove(int i) {
refreshIfEmpty();
V remove = getListDelegate().remove(i);
AbstractMapBasedMultimap.access$210(AbstractMapBasedMultimap.this);
removeIfEmpty();
return remove;
}
@Override // java.util.List
public V set(int i, V v) {
refreshIfEmpty();
return getListDelegate().set(i, v);
}
@Override // java.util.List
public List<V> subList(int i, int i2) {
refreshIfEmpty();
AbstractMapBasedMultimap abstractMapBasedMultimap = AbstractMapBasedMultimap.this;
K k = this.key;
List<V> subList = getListDelegate().subList(i, i2);
WrappedCollection wrappedCollection = this.ancestor;
if (wrappedCollection == null) {
wrappedCollection = this;
}
return abstractMapBasedMultimap.wrapList(k, subList, wrappedCollection);
}
@Override // java.util.List
public ListIterator<V> listIterator(int i) {
refreshIfEmpty();
return new WrappedListIterator(i);
}
}
}