package androidx.compose.runtime.snapshots;

import E3.v;
import androidx.compose.runtime.PreconditionsKt;
import androidx.compose.runtime.internal.StabilityInferred;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import kotlin.jvm.internal.A;
import kotlin.jvm.internal.n;
import kotlin.jvm.internal.o;
import x4.AbstractC3226C;

/* JADX INFO: loaded from: classes.dex */
@StabilityInferred(parameters = 0)
public final class SubList<T> implements List<T>, K4.c {
    public static final int $stable = 8;
    private final int offset;
    private final SnapshotStateList<T> parentList;
    private int size;
    private int structure;

    /* JADX INFO: renamed from: androidx.compose.runtime.snapshots.SubList$listIterator$1, reason: invalid class name */
    public static final class AnonymousClass1 implements ListIterator<T>, K4.a {
        final /* synthetic */ A $current;
        final /* synthetic */ SubList<T> this$0;

        public AnonymousClass1(A a6, SubList<T> subList) {
            this.$current = a6;
            this.this$0 = subList;
        }

        @Override // java.util.ListIterator, java.util.Iterator
        public boolean hasNext() {
            return this.$current.f20113a < this.this$0.size() - 1;
        }

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

        @Override // java.util.ListIterator, java.util.Iterator
        public T next() {
            int i6 = this.$current.f20113a + 1;
            SnapshotStateListKt.validateRange(i6, this.this$0.size());
            this.$current.f20113a = i6;
            return this.this$0.get(i6);
        }

        @Override // java.util.ListIterator
        public int nextIndex() {
            return this.$current.f20113a + 1;
        }

        @Override // java.util.ListIterator
        public T previous() {
            int i6 = this.$current.f20113a;
            SnapshotStateListKt.validateRange(i6, this.this$0.size());
            this.$current.f20113a = i6 - 1;
            return this.this$0.get(i6);
        }

        @Override // java.util.ListIterator
        public int previousIndex() {
            return this.$current.f20113a;
        }

        @Override // java.util.ListIterator
        public Void add(T t6) {
            SnapshotStateListKt.modificationError();
            throw new v();
        }

        @Override // java.util.ListIterator, java.util.Iterator
        public Void remove() {
            SnapshotStateListKt.modificationError();
            throw new v();
        }

        @Override // java.util.ListIterator
        public Void set(T t6) {
            SnapshotStateListKt.modificationError();
            throw new v();
        }
    }

    public SubList(SnapshotStateList<T> snapshotStateList, int i6, int i7) {
        this.parentList = snapshotStateList;
        this.offset = i6;
        this.structure = SnapshotStateListKt.getStructure(snapshotStateList);
        this.size = i7 - i6;
    }

    private final void validateModification() {
        if (SnapshotStateListKt.getStructure(this.parentList) != this.structure) {
            throw new ConcurrentModificationException();
        }
    }

    @Override // java.util.List, java.util.Collection
    public boolean add(T t6) {
        validateModification();
        this.parentList.add(size() + this.offset, t6);
        this.size = size() + 1;
        this.structure = SnapshotStateListKt.getStructure(this.parentList);
        return true;
    }

    @Override // java.util.List
    public boolean addAll(int i6, Collection<? extends T> collection) {
        validateModification();
        boolean zAddAll = this.parentList.addAll(i6 + this.offset, collection);
        if (zAddAll) {
            this.size = collection.size() + size();
            this.structure = SnapshotStateListKt.getStructure(this.parentList);
        }
        return zAddAll;
    }

    @Override // java.util.List, java.util.Collection
    public void clear() {
        if (size() > 0) {
            validateModification();
            SnapshotStateList<T> snapshotStateList = this.parentList;
            int i6 = this.offset;
            snapshotStateList.removeRange(i6, size() + i6);
            this.size = 0;
            this.structure = SnapshotStateListKt.getStructure(this.parentList);
        }
    }

    @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<T> it = collection2.iterator();
        while (it.hasNext()) {
            if (!contains(it.next())) {
                return false;
            }
        }
        return true;
    }

    @Override // java.util.List
    public T get(int i6) {
        validateModification();
        SnapshotStateListKt.validateRange(i6, size());
        return this.parentList.get(this.offset + i6);
    }

    public final SnapshotStateList<T> getParentList() {
        return this.parentList;
    }

    public int getSize() {
        return this.size;
    }

    @Override // java.util.List
    public int indexOf(Object obj) {
        validateModification();
        int i6 = this.offset;
        Iterator<T> it = L4.a.l0(i6, size() + i6).iterator();
        while (it.hasNext()) {
            int iA = ((AbstractC3226C) it).a();
            if (o.c(obj, this.parentList.get(iA))) {
                return iA - this.offset;
            }
        }
        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<T> iterator() {
        return listIterator();
    }

    @Override // java.util.List
    public int lastIndexOf(Object obj) {
        validateModification();
        int size = size() + this.offset;
        do {
            size--;
            if (size < this.offset) {
                return -1;
            }
        } while (!o.c(obj, this.parentList.get(size)));
        return size - this.offset;
    }

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

    @Override // java.util.List
    public final /* bridge */ T remove(int i6) {
        return removeAt(i6);
    }

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

    public T removeAt(int i6) {
        validateModification();
        T tRemove = this.parentList.remove(this.offset + i6);
        this.size = size() - 1;
        this.structure = SnapshotStateListKt.getStructure(this.parentList);
        return tRemove;
    }

    @Override // java.util.List, java.util.Collection
    public boolean retainAll(Collection<?> collection) {
        validateModification();
        SnapshotStateList<T> snapshotStateList = this.parentList;
        int i6 = this.offset;
        int iRetainAllInRange$runtime = snapshotStateList.retainAllInRange$runtime(collection, i6, size() + i6);
        if (iRetainAllInRange$runtime > 0) {
            this.structure = SnapshotStateListKt.getStructure(this.parentList);
            this.size = size() - iRetainAllInRange$runtime;
        }
        return iRetainAllInRange$runtime > 0;
    }

    @Override // java.util.List
    public T set(int i6, T t6) {
        SnapshotStateListKt.validateRange(i6, size());
        validateModification();
        T t7 = this.parentList.set(i6 + this.offset, t6);
        this.structure = SnapshotStateListKt.getStructure(this.parentList);
        return t7;
    }

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

    @Override // java.util.List
    public List<T> subList(int i6, int i7) {
        if (!(i6 >= 0 && i6 <= i7 && i7 <= size())) {
            PreconditionsKt.throwIllegalArgumentException("fromIndex or toIndex are out of bounds");
        }
        validateModification();
        SnapshotStateList<T> snapshotStateList = this.parentList;
        int i8 = this.offset;
        return new SubList(snapshotStateList, i6 + i8, i7 + i8);
    }

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

    @Override // java.util.List
    public ListIterator<T> listIterator(int i6) {
        validateModification();
        A a6 = new A();
        a6.f20113a = i6 - 1;
        return new AnonymousClass1(a6, this);
    }

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

    @Override // java.util.List, java.util.Collection
    public <T> T[] toArray(T[] tArr) {
        return (T[]) n.b(this, tArr);
    }

    @Override // java.util.List
    public void add(int i6, T t6) {
        validateModification();
        this.parentList.add(this.offset + i6, t6);
        this.size = size() + 1;
        this.structure = SnapshotStateListKt.getStructure(this.parentList);
    }

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