package defpackage;

import defpackage.o0;
import defpackage.oo5;
import defpackage.qw4;
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;

/* JADX INFO: Access modifiers changed from: package-private */
/* JADX INFO: loaded from: classes2.dex */
@az3
@li2
public abstract class g0<K, V> extends o0<K, V> implements Serializable {
    public final transient Map e;
    public transient int f;

    public class a extends oo5.ae<K, Collection<V>> {
        public final transient Map d;

        /* JADX INFO: renamed from: g0$a$a, reason: collision with other inner class name */
        public class C0143a extends oo5.f<K, Collection<V>> {
            public C0143a() {
            }

            @Override // oo5.f, java.util.AbstractCollection, java.util.Collection, java.util.Set
            public final boolean contains(Object obj) {
                return v41.b(a.this.d.entrySet(), obj);
            }

            @Override // oo5.f
            public final Map d() {
                return a.this;
            }

            @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
            public final Iterator iterator() {
                return a.this.new b();
            }

            @Override // oo5.f, java.util.AbstractCollection, java.util.Collection, java.util.Set
            public final boolean remove(Object obj) {
                Object objRemove;
                if (!contains(obj)) {
                    return false;
                }
                Map.Entry entry = (Map.Entry) obj;
                Objects.requireNonNull(entry);
                g0 g0Var = g0.this;
                Object key = entry.getKey();
                Map map = g0Var.e;
                map.getClass();
                try {
                    objRemove = map.remove(key);
                } catch (ClassCastException | NullPointerException unused) {
                    objRemove = null;
                }
                Collection collection = (Collection) objRemove;
                if (collection == null) {
                    return true;
                }
                int size = collection.size();
                collection.clear();
                g0Var.f -= size;
                return true;
            }
        }

        public class b implements Iterator<Map.Entry<K, Collection<V>>> {
            public final Iterator a;
            public Collection b;

            public b() {
                this.a = a.this.d.entrySet().iterator();
            }

            @Override // java.util.Iterator
            public final boolean hasNext() {
                return this.a.hasNext();
            }

            @Override // java.util.Iterator
            public final Object next() {
                Map.Entry entry = (Map.Entry) this.a.next();
                this.b = (Collection) entry.getValue();
                return a.this.d(entry);
            }

            @Override // java.util.Iterator
            public final void remove() {
                if7.p(this.b != null, "no calls to next() since the last call to remove()");
                this.a.remove();
                g0.this.f -= this.b.size();
                this.b.clear();
                this.b = null;
            }
        }

        public a(Map map) {
            this.d = map;
        }

        @Override // oo5.ae
        public final Set a() {
            return new C0143a();
        }

        @Override // java.util.AbstractMap, java.util.Map
        public final void clear() {
            g0 g0Var = g0.this;
            if (this.d == g0Var.e) {
                g0Var.clear();
            } else {
                qw4.b(new b());
            }
        }

        @Override // java.util.AbstractMap, java.util.Map
        public final boolean containsKey(Object obj) {
            Map map = this.d;
            map.getClass();
            try {
                return map.containsKey(obj);
            } catch (ClassCastException | NullPointerException unused) {
                return false;
            }
        }

        public final Map.Entry d(Map.Entry entry) {
            Object key = entry.getKey();
            return new wi4(key, g0.this.p((Collection) entry.getValue(), key));
        }

        @Override // java.util.AbstractMap, java.util.Map
        public final boolean equals(Object obj) {
            return this == obj || this.d.equals(obj);
        }

        @Override // java.util.AbstractMap, java.util.Map
        public final Object get(Object obj) {
            Collection collection = (Collection) oo5.f(this.d, obj);
            if (collection == null) {
                return null;
            }
            return g0.this.p(collection, obj);
        }

        @Override // java.util.AbstractMap, java.util.Map
        public final int hashCode() {
            return this.d.hashCode();
        }

        @Override // oo5.ae, java.util.AbstractMap, java.util.Map
        public Set keySet() {
            return g0.this.keySet();
        }

        @Override // java.util.AbstractMap, java.util.Map
        public final Object remove(Object obj) {
            Collection collection = (Collection) this.d.remove(obj);
            if (collection == null) {
                return null;
            }
            g0 g0Var = g0.this;
            Collection collectionI = g0Var.i();
            collectionI.addAll(collection);
            g0Var.f -= collection.size();
            collection.clear();
            return collectionI;
        }

        @Override // java.util.AbstractMap, java.util.Map
        public final int size() {
            return this.d.size();
        }

        @Override // java.util.AbstractMap
        public final String toString() {
            return this.d.toString();
        }
    }

    public abstract class b<T> implements Iterator<T> {
        public final Iterator a;
        public Object b = null;
        public Collection c = null;
        public Iterator d = qw4.c.a;

        public b() {
            this.a = g0.this.e.entrySet().iterator();
        }

        public abstract Object a(Object obj, Object obj2);

        @Override // java.util.Iterator
        public final boolean hasNext() {
            return this.a.hasNext() || this.d.hasNext();
        }

        @Override // java.util.Iterator
        public final Object next() {
            if (!this.d.hasNext()) {
                Map.Entry entry = (Map.Entry) this.a.next();
                this.b = entry.getKey();
                Collection collection = (Collection) entry.getValue();
                this.c = collection;
                this.d = collection.iterator();
            }
            return a(this.b, this.d.next());
        }

        @Override // java.util.Iterator
        public final void remove() {
            this.d.remove();
            Collection collection = this.c;
            Objects.requireNonNull(collection);
            if (collection.isEmpty()) {
                this.a.remove();
            }
            g0 g0Var = g0.this;
            g0Var.f--;
        }
    }

    public class c extends oo5.o<K, Collection<V>> {
        public c(Map map) {
            super(map);
        }

        @Override // oo5.o, java.util.AbstractCollection, java.util.Collection, java.util.Set
        public final void clear() {
            qw4.b(iterator());
        }

        @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
        public final boolean containsAll(Collection collection) {
            return this.a.keySet().containsAll(collection);
        }

        @Override // java.util.AbstractSet, java.util.Collection, java.util.Set
        public final boolean equals(Object obj) {
            return this == obj || this.a.keySet().equals(obj);
        }

        @Override // java.util.AbstractSet, java.util.Collection, java.util.Set
        public final int hashCode() {
            return this.a.keySet().hashCode();
        }

        @Override // oo5.o, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
        public final Iterator iterator() {
            return new h0(this, this.a.entrySet().iterator());
        }

        @Override // oo5.o, java.util.AbstractCollection, java.util.Collection, java.util.Set
        public final boolean remove(Object obj) {
            int size;
            Collection collection = (Collection) this.a.remove(obj);
            if (collection != null) {
                size = collection.size();
                collection.clear();
                g0.this.f -= size;
            } else {
                size = 0;
            }
            return size > 0;
        }
    }

    public final class d extends g0<K, V>.g implements NavigableMap<K, Collection<V>> {
        public d(NavigableMap navigableMap) {
            super(navigableMap);
        }

        @Override // g0.g, oo5.ae
        public final Set b() {
            return new e(g());
        }

        @Override // java.util.NavigableMap
        public final Map.Entry ceilingEntry(Object obj) {
            Map.Entry<K, V> entryCeilingEntry = g().ceilingEntry(obj);
            if (entryCeilingEntry == null) {
                return null;
            }
            return d(entryCeilingEntry);
        }

        @Override // java.util.NavigableMap
        public final Object ceilingKey(Object obj) {
            return g().ceilingKey(obj);
        }

        @Override // java.util.NavigableMap
        public final NavigableSet descendingKeySet() {
            return (NavigableSet) super.keySet();
        }

        @Override // java.util.NavigableMap
        public final NavigableMap descendingMap() {
            return new d(g().descendingMap());
        }

        @Override // g0.g
        /* JADX INFO: renamed from: e */
        public final SortedSet b() {
            return new e(g());
        }

        @Override // g0.g
        /* JADX INFO: renamed from: f */
        public final SortedSet keySet() {
            return (NavigableSet) super.keySet();
        }

        @Override // java.util.NavigableMap
        public final Map.Entry firstEntry() {
            Map.Entry<K, V> entryFirstEntry = g().firstEntry();
            if (entryFirstEntry == null) {
                return null;
            }
            return d(entryFirstEntry);
        }

        @Override // java.util.NavigableMap
        public final Map.Entry floorEntry(Object obj) {
            Map.Entry<K, V> entryFloorEntry = g().floorEntry(obj);
            if (entryFloorEntry == null) {
                return null;
            }
            return d(entryFloorEntry);
        }

        @Override // java.util.NavigableMap
        public final Object floorKey(Object obj) {
            return g().floorKey(obj);
        }

        public final Map.Entry h(Iterator it) {
            if (!it.hasNext()) {
                return null;
            }
            Map.Entry entry = (Map.Entry) it.next();
            g0 g0Var = g0.this;
            Collection collectionI = g0Var.i();
            collectionI.addAll((Collection) entry.getValue());
            it.remove();
            return new wi4(entry.getKey(), g0Var.n(collectionI));
        }

        @Override // g0.g, java.util.SortedMap, java.util.NavigableMap
        public final SortedMap headMap(Object obj) {
            return headMap(obj, false);
        }

        @Override // java.util.NavigableMap
        public final Map.Entry higherEntry(Object obj) {
            Map.Entry<K, V> entryHigherEntry = g().higherEntry(obj);
            if (entryHigherEntry == null) {
                return null;
            }
            return d(entryHigherEntry);
        }

        @Override // java.util.NavigableMap
        public final Object higherKey(Object obj) {
            return g().higherKey(obj);
        }

        @Override // g0.g
        /* JADX INFO: renamed from: i, reason: merged with bridge method [inline-methods] */
        public final NavigableMap g() {
            return (NavigableMap) ((SortedMap) this.d);
        }

        @Override // g0.g, g0.a, oo5.ae, java.util.AbstractMap, java.util.Map
        public final Set keySet() {
            return (NavigableSet) super.keySet();
        }

        @Override // java.util.NavigableMap
        public final Map.Entry lastEntry() {
            Map.Entry<K, V> entryLastEntry = g().lastEntry();
            if (entryLastEntry == null) {
                return null;
            }
            return d(entryLastEntry);
        }

        @Override // java.util.NavigableMap
        public final Map.Entry lowerEntry(Object obj) {
            Map.Entry<K, V> entryLowerEntry = g().lowerEntry(obj);
            if (entryLowerEntry == null) {
                return null;
            }
            return d(entryLowerEntry);
        }

        @Override // java.util.NavigableMap
        public final Object lowerKey(Object obj) {
            return g().lowerKey(obj);
        }

        @Override // java.util.NavigableMap
        public final NavigableSet navigableKeySet() {
            return (NavigableSet) super.keySet();
        }

        @Override // java.util.NavigableMap
        public final Map.Entry pollFirstEntry() {
            return h(entrySet().iterator());
        }

        @Override // java.util.NavigableMap
        public final Map.Entry pollLastEntry() {
            return h(((oo5.ae) descendingMap()).entrySet().iterator());
        }

        @Override // g0.g, java.util.SortedMap, java.util.NavigableMap
        public final SortedMap subMap(Object obj, Object obj2) {
            return subMap(obj, true, obj2, false);
        }

        @Override // g0.g, java.util.SortedMap, java.util.NavigableMap
        public final SortedMap tailMap(Object obj) {
            return tailMap(obj, true);
        }

        @Override // java.util.NavigableMap
        public final NavigableMap headMap(Object obj, boolean z) {
            return new d(g().headMap(obj, z));
        }

        @Override // java.util.NavigableMap
        public final NavigableMap subMap(Object obj, boolean z, Object obj2, boolean z2) {
            return new d(g().subMap(obj, z, obj2, z2));
        }

        @Override // java.util.NavigableMap
        public final NavigableMap tailMap(Object obj, boolean z) {
            return new d(g().tailMap(obj, z));
        }
    }

    public final class e extends g0<K, V>.h implements NavigableSet<K> {
        public e(NavigableMap navigableMap) {
            super(navigableMap);
        }

        @Override // java.util.NavigableSet
        public final Object ceiling(Object obj) {
            return e().ceilingKey(obj);
        }

        @Override // java.util.NavigableSet
        public final Iterator descendingIterator() {
            return ((c) descendingSet()).iterator();
        }

        @Override // java.util.NavigableSet
        public final NavigableSet descendingSet() {
            return new e(e().descendingMap());
        }

        @Override // g0.h
        /* JADX INFO: renamed from: f, reason: merged with bridge method [inline-methods] */
        public final NavigableMap e() {
            return (NavigableMap) ((SortedMap) this.a);
        }

        @Override // java.util.NavigableSet
        public final Object floor(Object obj) {
            return e().floorKey(obj);
        }

        @Override // g0.h, java.util.SortedSet, java.util.NavigableSet
        public final SortedSet headSet(Object obj) {
            return headSet(obj, false);
        }

        @Override // java.util.NavigableSet
        public final Object higher(Object obj) {
            return e().higherKey(obj);
        }

        @Override // java.util.NavigableSet
        public final Object lower(Object obj) {
            return e().lowerKey(obj);
        }

        @Override // java.util.NavigableSet
        public final Object pollFirst() {
            return qw4.j(iterator());
        }

        @Override // java.util.NavigableSet
        public final Object pollLast() {
            return qw4.j(descendingIterator());
        }

        @Override // g0.h, java.util.SortedSet, java.util.NavigableSet
        public final SortedSet subSet(Object obj, Object obj2) {
            return subSet(obj, true, obj2, false);
        }

        @Override // g0.h, java.util.SortedSet, java.util.NavigableSet
        public final SortedSet tailSet(Object obj) {
            return tailSet(obj, true);
        }

        @Override // java.util.NavigableSet
        public final NavigableSet headSet(Object obj, boolean z) {
            return new e(e().headMap(obj, z));
        }

        @Override // java.util.NavigableSet
        public final NavigableSet subSet(Object obj, boolean z, Object obj2, boolean z2) {
            return new e(e().subMap(obj, z, obj2, z2));
        }

        @Override // java.util.NavigableSet
        public final NavigableSet tailSet(Object obj, boolean z) {
            return new e(e().tailMap(obj, z));
        }
    }

    public class f extends g0<K, V>.j implements RandomAccess {
    }

    public class g extends g0<K, V>.a implements SortedMap<K, Collection<V>> {
        public SortedSet f;

        public g(SortedMap sortedMap) {
            super(sortedMap);
        }

        @Override // java.util.SortedMap
        public final Comparator comparator() {
            return g().comparator();
        }

        @Override // oo5.ae
        /* JADX INFO: renamed from: e, reason: merged with bridge method [inline-methods] */
        public SortedSet b() {
            return new h(g());
        }

        @Override // g0.a, oo5.ae, java.util.AbstractMap, java.util.Map
        /* JADX INFO: renamed from: f, reason: merged with bridge method [inline-methods] */
        public SortedSet keySet() {
            SortedSet sortedSet = this.f;
            if (sortedSet != null) {
                return sortedSet;
            }
            SortedSet sortedSetB = b();
            this.f = sortedSetB;
            return sortedSetB;
        }

        @Override // java.util.SortedMap
        public final Object firstKey() {
            return g().firstKey();
        }

        public SortedMap g() {
            return (SortedMap) this.d;
        }

        public SortedMap headMap(Object obj) {
            return new g(g().headMap(obj));
        }

        @Override // java.util.SortedMap
        public final Object lastKey() {
            return g().lastKey();
        }

        public SortedMap subMap(Object obj, Object obj2) {
            return new g(g().subMap(obj, obj2));
        }

        public SortedMap tailMap(Object obj) {
            return new g(g().tailMap(obj));
        }
    }

    public class h extends g0<K, V>.c implements SortedSet<K> {
        public h(SortedMap sortedMap) {
            super(sortedMap);
        }

        @Override // java.util.SortedSet
        public final Comparator comparator() {
            return e().comparator();
        }

        public SortedMap e() {
            return (SortedMap) this.a;
        }

        @Override // java.util.SortedSet
        public final Object first() {
            return e().firstKey();
        }

        public SortedSet headSet(Object obj) {
            return new h(e().headMap(obj));
        }

        @Override // java.util.SortedSet
        public final Object last() {
            return e().lastKey();
        }

        public SortedSet subSet(Object obj, Object obj2) {
            return new h(e().subMap(obj, obj2));
        }

        public SortedSet tailSet(Object obj) {
            return new h(e().tailMap(obj));
        }
    }

    public class k extends g0<K, V>.m implements NavigableSet<V> {
        public k(Object obj, NavigableSet navigableSet, i iVar) {
            super(obj, navigableSet, iVar);
        }

        @Override // java.util.NavigableSet
        public final Object ceiling(Object obj) {
            return d().ceiling(obj);
        }

        @Override // java.util.NavigableSet
        public final Iterator descendingIterator() {
            return new i.a(d().descendingIterator());
        }

        @Override // java.util.NavigableSet
        public final NavigableSet descendingSet() {
            return f(d().descendingSet());
        }

        @Override // g0.m
        /* JADX INFO: renamed from: e, reason: merged with bridge method [inline-methods] */
        public final NavigableSet d() {
            return (NavigableSet) ((SortedSet) this.b);
        }

        public final NavigableSet f(NavigableSet navigableSet) {
            i iVar = this.c;
            if (iVar == null) {
                iVar = this;
            }
            return new k(this.a, navigableSet, iVar);
        }

        @Override // java.util.NavigableSet
        public final Object floor(Object obj) {
            return d().floor(obj);
        }

        @Override // java.util.NavigableSet
        public final NavigableSet headSet(Object obj, boolean z) {
            return f(d().headSet(obj, z));
        }

        @Override // java.util.NavigableSet
        public final Object higher(Object obj) {
            return d().higher(obj);
        }

        @Override // java.util.NavigableSet
        public final Object lower(Object obj) {
            return d().lower(obj);
        }

        @Override // java.util.NavigableSet
        public final Object pollFirst() {
            return qw4.j(iterator());
        }

        @Override // java.util.NavigableSet
        public final Object pollLast() {
            return qw4.j(descendingIterator());
        }

        @Override // java.util.NavigableSet
        public final NavigableSet subSet(Object obj, boolean z, Object obj2, boolean z2) {
            return f(d().subSet(obj, z, obj2, z2));
        }

        @Override // java.util.NavigableSet
        public final NavigableSet tailSet(Object obj, boolean z) {
            return f(d().tailSet(obj, z));
        }
    }

    public class l extends g0<K, V>.i implements Set<V> {
        public l(Object obj, Set set) {
            super(obj, set, null);
        }

        @Override // g0.i, java.util.AbstractCollection, java.util.Collection
        public final boolean removeAll(Collection collection) {
            if (collection.isEmpty()) {
                return false;
            }
            int size = size();
            boolean zG = hm8.g((Set) this.b, collection);
            if (zG) {
                g0.this.f += this.b.size() - size;
                c();
            }
            return zG;
        }
    }

    public class m extends g0<K, V>.i implements SortedSet<V> {
        public m(Object obj, SortedSet sortedSet, i iVar) {
            super(obj, sortedSet, iVar);
        }

        @Override // java.util.SortedSet
        public final Comparator comparator() {
            return d().comparator();
        }

        public SortedSet d() {
            return (SortedSet) this.b;
        }

        @Override // java.util.SortedSet
        public final Object first() {
            b();
            return d().first();
        }

        @Override // java.util.SortedSet
        public final SortedSet headSet(Object obj) {
            b();
            SortedSet sortedSetHeadSet = d().headSet(obj);
            i iVar = this.c;
            if (iVar == null) {
                iVar = this;
            }
            return new m(this.a, sortedSetHeadSet, iVar);
        }

        @Override // java.util.SortedSet
        public final Object last() {
            b();
            return d().last();
        }

        @Override // java.util.SortedSet
        public final SortedSet subSet(Object obj, Object obj2) {
            b();
            SortedSet sortedSetSubSet = d().subSet(obj, obj2);
            i iVar = this.c;
            if (iVar == null) {
                iVar = this;
            }
            return new m(this.a, sortedSetSubSet, iVar);
        }

        @Override // java.util.SortedSet
        public final SortedSet tailSet(Object obj) {
            b();
            SortedSet sortedSetTailSet = d().tailSet(obj);
            i iVar = this.c;
            if (iVar == null) {
                iVar = this;
            }
            return new m(this.a, sortedSetTailSet, iVar);
        }
    }

    public g0(Map map) {
        if7.e(map.isEmpty());
        this.e = map;
    }

    @Override // defpackage.hc6, defpackage.ql8, defpackage.ox8
    public Collection a(Object obj) {
        Collection collection = (Collection) this.e.remove(obj);
        if (collection == null) {
            return m();
        }
        Collection collectionI = i();
        collectionI.addAll(collection);
        this.f -= collection.size();
        collection.clear();
        return n(collectionI);
    }

    @Override // defpackage.o0
    public Map c() {
        return new a(this.e);
    }

    @Override // defpackage.hc6
    public void clear() {
        Map map = this.e;
        Iterator<V> it = map.values().iterator();
        while (it.hasNext()) {
            ((Collection) it.next()).clear();
        }
        map.clear();
        this.f = 0;
    }

    @Override // defpackage.hc6
    public boolean containsKey(Object obj) {
        return this.e.containsKey(obj);
    }

    @Override // defpackage.o0
    public final Collection d() {
        return this instanceof ql8 ? new o0.b() : new o0.a();
    }

    @Override // defpackage.o0
    public Set e() {
        return new c(this.e);
    }

    @Override // defpackage.o0
    public final Collection f() {
        return new o0.c(this);
    }

    @Override // defpackage.o0
    public Iterator g() {
        return new f0();
    }

    @Override // defpackage.hc6, defpackage.ql8, defpackage.ox8
    /* JADX INFO: renamed from: get */
    public Collection l(Object obj) {
        Collection collectionJ = (Collection) this.e.get(obj);
        if (collectionJ == null) {
            collectionJ = j(obj);
        }
        return p(collectionJ, obj);
    }

    public abstract Collection i();

    public Collection j(Object obj) {
        return i();
    }

    public final Map k() {
        Map map = this.e;
        return map instanceof NavigableMap ? new d((NavigableMap) map) : map instanceof SortedMap ? new g((SortedMap) map) : new a(map);
    }

    public final Set l() {
        Map map = this.e;
        return map instanceof NavigableMap ? new e((NavigableMap) map) : map instanceof SortedMap ? new h((SortedMap) map) : new c(map);
    }

    public Collection m() {
        return n(i());
    }

    public Collection n(Collection collection) {
        return Collections.unmodifiableCollection(collection);
    }

    public Iterator o() {
        return new e0();
    }

    public Collection p(Collection collection, Object obj) {
        return new i(obj, collection, null);
    }

    @Override // defpackage.o0, defpackage.hc6
    public boolean put(Object obj, Object obj2) {
        Map map = this.e;
        Collection collection = (Collection) map.get(obj);
        if (collection != null) {
            if (!collection.add(obj2)) {
                return false;
            }
            this.f++;
            return true;
        }
        Collection collectionJ = j(obj);
        if (!collectionJ.add(obj2)) {
            throw new AssertionError("New Collection violated the Collection spec");
        }
        this.f++;
        map.put(obj, collectionJ);
        return true;
    }

    @Override // defpackage.hc6
    public int size() {
        return this.f;
    }

    public class j extends g0<K, V>.i implements List<V> {

        public class a extends g0<K, V>.i.a implements ListIterator<V> {
            public a() {
                super();
            }

            @Override // java.util.ListIterator
            public final void add(Object obj) {
                j jVar = j.this;
                boolean zIsEmpty = jVar.isEmpty();
                b().add(obj);
                g0.this.f++;
                if (zIsEmpty) {
                    jVar.a();
                }
            }

            public final ListIterator b() {
                a();
                return (ListIterator) this.a;
            }

            @Override // java.util.ListIterator
            public final boolean hasPrevious() {
                return b().hasPrevious();
            }

            @Override // java.util.ListIterator
            public final int nextIndex() {
                return b().nextIndex();
            }

            @Override // java.util.ListIterator
            public final Object previous() {
                return b().previous();
            }

            @Override // java.util.ListIterator
            public final int previousIndex() {
                return b().previousIndex();
            }

            @Override // java.util.ListIterator
            public final void set(Object obj) {
                b().set(obj);
            }

            public a(int i) {
                super(((List) j.this.b).listIterator(i));
            }
        }

        public j(Object obj, List list, i iVar) {
            super(obj, list, iVar);
        }

        @Override // java.util.List
        public final void add(int i, Object obj) {
            b();
            boolean zIsEmpty = this.b.isEmpty();
            ((List) this.b).add(i, obj);
            g0.this.f++;
            if (zIsEmpty) {
                a();
            }
        }

        @Override // java.util.List
        public final boolean addAll(int i, Collection collection) {
            if (collection.isEmpty()) {
                return false;
            }
            int size = size();
            boolean zAddAll = ((List) this.b).addAll(i, collection);
            if (zAddAll) {
                g0.this.f += this.b.size() - size;
                if (size == 0) {
                    a();
                }
            }
            return zAddAll;
        }

        @Override // java.util.List
        public final Object get(int i) {
            b();
            return ((List) this.b).get(i);
        }

        @Override // java.util.List
        public final int indexOf(Object obj) {
            b();
            return ((List) this.b).indexOf(obj);
        }

        @Override // java.util.List
        public final int lastIndexOf(Object obj) {
            b();
            return ((List) this.b).lastIndexOf(obj);
        }

        @Override // java.util.List
        public final ListIterator listIterator() {
            b();
            return new a();
        }

        @Override // java.util.List
        public final Object remove(int i) {
            b();
            Object objRemove = ((List) this.b).remove(i);
            g0 g0Var = g0.this;
            g0Var.f--;
            c();
            return objRemove;
        }

        @Override // java.util.List
        public final Object set(int i, Object obj) {
            b();
            return ((List) this.b).set(i, obj);
        }

        @Override // java.util.List
        public final List subList(int i, int i2) {
            b();
            List listSubList = ((List) this.b).subList(i, i2);
            i iVar = this.c;
            if (iVar == null) {
                iVar = this;
            }
            boolean z = listSubList instanceof RandomAccess;
            g0 g0Var = g0.this;
            Object obj = this.a;
            return z ? new f(obj, listSubList, iVar) : new j(obj, listSubList, iVar);
        }

        @Override // java.util.List
        public final ListIterator listIterator(int i) {
            b();
            return new a(i);
        }
    }

    public class i extends AbstractCollection<V> {
        public final Object a;
        public Collection b;
        public final i c;
        public final Collection d;

        public i(Object obj, Collection collection, i iVar) {
            this.a = obj;
            this.b = collection;
            this.c = iVar;
            this.d = iVar == null ? null : iVar.b;
        }

        /* JADX WARN: Multi-variable type inference failed */
        public final void a() {
            i iVar = this.c;
            if (iVar != null) {
                iVar.a();
            } else {
                g0.this.e.put(this.a, this.b);
            }
        }

        @Override // java.util.AbstractCollection, java.util.Collection
        public final boolean add(Object obj) {
            b();
            boolean zIsEmpty = this.b.isEmpty();
            boolean zAdd = this.b.add(obj);
            if (zAdd) {
                g0.this.f++;
                if (zIsEmpty) {
                    a();
                }
            }
            return zAdd;
        }

        @Override // java.util.AbstractCollection, java.util.Collection
        public final boolean addAll(Collection collection) {
            if (collection.isEmpty()) {
                return false;
            }
            int size = size();
            boolean zAddAll = this.b.addAll(collection);
            if (zAddAll) {
                g0.this.f += this.b.size() - size;
                if (size == 0) {
                    a();
                }
            }
            return zAddAll;
        }

        public final void b() {
            Collection collection;
            i iVar = this.c;
            if (iVar != null) {
                iVar.b();
                if (iVar.b != this.d) {
                    throw new ConcurrentModificationException();
                }
            } else {
                if (!this.b.isEmpty() || (collection = (Collection) g0.this.e.get(this.a)) == null) {
                    return;
                }
                this.b = collection;
            }
        }

        public final void c() {
            i iVar = this.c;
            if (iVar != null) {
                iVar.c();
            } else if (this.b.isEmpty()) {
                g0.this.e.remove(this.a);
            }
        }

        @Override // java.util.AbstractCollection, java.util.Collection
        public final void clear() {
            int size = size();
            if (size == 0) {
                return;
            }
            this.b.clear();
            g0.this.f -= size;
            c();
        }

        @Override // java.util.AbstractCollection, java.util.Collection
        public final boolean contains(Object obj) {
            b();
            return this.b.contains(obj);
        }

        @Override // java.util.AbstractCollection, java.util.Collection
        public final boolean containsAll(Collection collection) {
            b();
            return this.b.containsAll(collection);
        }

        @Override // java.util.Collection
        public final boolean equals(Object obj) {
            if (obj == this) {
                return true;
            }
            b();
            return this.b.equals(obj);
        }

        @Override // java.util.Collection
        public final int hashCode() {
            b();
            return this.b.hashCode();
        }

        @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
        public final Iterator iterator() {
            b();
            return new a();
        }

        @Override // java.util.AbstractCollection, java.util.Collection
        public final boolean remove(Object obj) {
            b();
            boolean zRemove = this.b.remove(obj);
            if (zRemove) {
                g0 g0Var = g0.this;
                g0Var.f--;
                c();
            }
            return zRemove;
        }

        @Override // java.util.AbstractCollection, java.util.Collection
        public boolean removeAll(Collection collection) {
            if (collection.isEmpty()) {
                return false;
            }
            int size = size();
            boolean zRemoveAll = this.b.removeAll(collection);
            if (zRemoveAll) {
                g0.this.f += this.b.size() - size;
                c();
            }
            return zRemoveAll;
        }

        @Override // java.util.AbstractCollection, java.util.Collection
        public final boolean retainAll(Collection collection) {
            collection.getClass();
            int size = size();
            boolean zRetainAll = this.b.retainAll(collection);
            if (zRetainAll) {
                g0.this.f += this.b.size() - size;
                c();
            }
            return zRetainAll;
        }

        @Override // java.util.AbstractCollection, java.util.Collection
        public final int size() {
            b();
            return this.b.size();
        }

        @Override // java.util.AbstractCollection
        public final String toString() {
            b();
            return this.b.toString();
        }

        public class a implements Iterator<V> {
            public final Iterator a;
            public final Collection b;

            public a() {
                Collection collection = i.this.b;
                this.b = collection;
                this.a = collection instanceof List ? ((List) collection).listIterator() : collection.iterator();
            }

            public final void a() {
                i iVar = i.this;
                iVar.b();
                if (iVar.b != this.b) {
                    throw new ConcurrentModificationException();
                }
            }

            @Override // java.util.Iterator
            public final boolean hasNext() {
                a();
                return this.a.hasNext();
            }

            @Override // java.util.Iterator
            public final Object next() {
                a();
                return this.a.next();
            }

            @Override // java.util.Iterator
            public final void remove() {
                this.a.remove();
                i iVar = i.this;
                g0 g0Var = g0.this;
                g0Var.f--;
                iVar.c();
            }

            public a(Iterator it) {
                this.b = i.this.b;
                this.a = it;
            }
        }
    }
}
