package j1;

import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import kotlin.jvm.internal.m0;
import sm.k0;
import y0.b2;

/* loaded from: classes.dex */
final class a0 implements List, en.c {

    /* renamed from: p, reason: collision with root package name */
    private final r f23452p;

    /* renamed from: q, reason: collision with root package name */
    private final int f23453q;

    /* renamed from: r, reason: collision with root package name */
    private int f23454r;

    /* renamed from: s, reason: collision with root package name */
    private int f23455s;

    /* loaded from: classes.dex */
    public static final class a implements ListIterator, en.a {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ m0 f23456p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ a0 f23457q;

        a(m0 m0Var, a0 a0Var) {
            this.f23456p = m0Var;
            this.f23457q = a0Var;
        }

        @Override // java.util.ListIterator
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public Void add(Object obj) {
            s.f();
            throw new rm.k();
        }

        @Override // java.util.ListIterator, java.util.Iterator
        /* renamed from: b, reason: merged with bridge method [inline-methods] */
        public Void remove() {
            s.f();
            throw new rm.k();
        }

        @Override // java.util.ListIterator
        /* renamed from: c, reason: merged with bridge method [inline-methods] */
        public Void set(Object obj) {
            s.f();
            throw new rm.k();
        }

        @Override // java.util.ListIterator, java.util.Iterator
        public boolean hasNext() {
            return this.f23456p.f26197p < this.f23457q.size() - 1;
        }

        @Override // java.util.ListIterator
        public boolean hasPrevious() {
            return this.f23456p.f26197p >= 0;
        }

        @Override // java.util.ListIterator, java.util.Iterator
        public Object next() {
            int i10 = this.f23456p.f26197p + 1;
            s.g(i10, this.f23457q.size());
            this.f23456p.f26197p = i10;
            return this.f23457q.get(i10);
        }

        @Override // java.util.ListIterator
        public int nextIndex() {
            return this.f23456p.f26197p + 1;
        }

        @Override // java.util.ListIterator
        public Object previous() {
            int i10 = this.f23456p.f26197p;
            s.g(i10, this.f23457q.size());
            this.f23456p.f26197p = i10 - 1;
            return this.f23457q.get(i10);
        }

        @Override // java.util.ListIterator
        public int previousIndex() {
            return this.f23456p.f26197p;
        }
    }

    public a0(r rVar, int i10, int i11) {
        this.f23452p = rVar;
        this.f23453q = i10;
        this.f23454r = rVar.x();
        this.f23455s = i11 - i10;
    }

    private final void i() {
        if (this.f23452p.x() != this.f23454r) {
            throw new ConcurrentModificationException();
        }
    }

    @Override // java.util.List, java.util.Collection
    public boolean add(Object obj) {
        i();
        this.f23452p.add(this.f23453q + size(), obj);
        this.f23455s = size() + 1;
        this.f23454r = this.f23452p.x();
        return true;
    }

    @Override // java.util.List
    public boolean addAll(int i10, Collection collection) {
        i();
        boolean addAll = this.f23452p.addAll(i10 + this.f23453q, collection);
        if (addAll) {
            this.f23455s = size() + collection.size();
            this.f23454r = this.f23452p.x();
        }
        return addAll;
    }

    @Override // java.util.List, java.util.Collection
    public void clear() {
        if (size() > 0) {
            i();
            r rVar = this.f23452p;
            int i10 = this.f23453q;
            rVar.C(i10, size() + i10);
            this.f23455s = 0;
            this.f23454r = this.f23452p.x();
        }
    }

    @Override // java.util.List, java.util.Collection
    public boolean contains(Object obj) {
        return indexOf(obj) >= 0;
    }

    @Override // java.util.List, java.util.Collection
    public boolean containsAll(Collection collection) {
        Collection collection2 = collection;
        if ((collection2 instanceof Collection) && collection2.isEmpty()) {
            return true;
        }
        Iterator it = collection2.iterator();
        while (it.hasNext()) {
            if (!contains(it.next())) {
                return false;
            }
        }
        return true;
    }

    public int e() {
        return this.f23455s;
    }

    public Object g(int i10) {
        i();
        Object remove = this.f23452p.remove(this.f23453q + i10);
        this.f23455s = size() - 1;
        this.f23454r = this.f23452p.x();
        return remove;
    }

    @Override // java.util.List
    public Object get(int i10) {
        i();
        s.g(i10, size());
        return this.f23452p.get(this.f23453q + i10);
    }

    @Override // java.util.List
    public int indexOf(Object obj) {
        jn.i q10;
        i();
        int i10 = this.f23453q;
        q10 = jn.o.q(i10, size() + i10);
        Iterator it = q10.iterator();
        while (it.hasNext()) {
            int a10 = ((k0) it).a();
            if (kotlin.jvm.internal.t.b(obj, this.f23452p.get(a10))) {
                return a10 - this.f23453q;
            }
        }
        return -1;
    }

    @Override // java.util.List, java.util.Collection
    public boolean isEmpty() {
        return size() == 0;
    }

    @Override // java.util.List, java.util.Collection, java.lang.Iterable
    public Iterator iterator() {
        return listIterator();
    }

    @Override // java.util.List
    public int lastIndexOf(Object obj) {
        i();
        int size = this.f23453q + size();
        do {
            size--;
            if (size < this.f23453q) {
                return -1;
            }
        } while (!kotlin.jvm.internal.t.b(obj, this.f23452p.get(size)));
        return size - this.f23453q;
    }

    @Override // java.util.List
    public ListIterator listIterator() {
        return listIterator(0);
    }

    @Override // java.util.List
    public final /* bridge */ Object remove(int i10) {
        return g(i10);
    }

    @Override // java.util.List, java.util.Collection
    public boolean removeAll(Collection collection) {
        Iterator it = collection.iterator();
        while (true) {
            boolean z10 = false;
            while (it.hasNext()) {
                if (remove(it.next()) || z10) {
                    z10 = true;
                }
            }
            return z10;
        }
    }

    @Override // java.util.List, java.util.Collection
    public boolean retainAll(Collection collection) {
        i();
        r rVar = this.f23452p;
        int i10 = this.f23453q;
        int D = rVar.D(collection, i10, size() + i10);
        if (D > 0) {
            this.f23454r = this.f23452p.x();
            this.f23455s = size() - D;
        }
        return D > 0;
    }

    @Override // java.util.List
    public Object set(int i10, Object obj) {
        s.g(i10, size());
        i();
        Object obj2 = this.f23452p.set(i10 + this.f23453q, obj);
        this.f23454r = this.f23452p.x();
        return obj2;
    }

    @Override // java.util.List, java.util.Collection
    public final /* bridge */ int size() {
        return e();
    }

    @Override // java.util.List
    public List subList(int i10, int i11) {
        if (!((i10 >= 0 && i10 <= i11) && i11 <= size())) {
            b2.a("fromIndex or toIndex are out of bounds");
        }
        i();
        r rVar = this.f23452p;
        int i12 = this.f23453q;
        return new a0(rVar, i10 + i12, i11 + i12);
    }

    @Override // java.util.List, java.util.Collection
    public Object[] toArray() {
        return kotlin.jvm.internal.j.a(this);
    }

    @Override // java.util.List
    public ListIterator listIterator(int i10) {
        i();
        m0 m0Var = new m0();
        m0Var.f26197p = i10 - 1;
        return new a(m0Var, this);
    }

    @Override // java.util.List, java.util.Collection
    public boolean remove(Object obj) {
        int indexOf = indexOf(obj);
        if (indexOf < 0) {
            return false;
        }
        remove(indexOf);
        return true;
    }

    @Override // java.util.List, java.util.Collection
    public Object[] toArray(Object[] objArr) {
        return kotlin.jvm.internal.j.b(this, objArr);
    }

    @Override // java.util.List
    public void add(int i10, Object obj) {
        i();
        this.f23452p.add(this.f23453q + i10, obj);
        this.f23455s = size() + 1;
        this.f23454r = this.f23452p.x();
    }

    @Override // java.util.List, java.util.Collection
    public boolean addAll(Collection collection) {
        return addAll(size(), collection);
    }
}
