package androidx.core.util;

import android.util.SparseArray;
import java.util.Iterator;
import kotlin.jvm.internal.l;
import o1.AbstractC0653A;
import y1.p;

/* JADX INFO: loaded from: classes.dex */
public final class SparseArrayKt {

    /* JADX INFO: Add missing generic type declarations: [T] */
    /* JADX INFO: renamed from: androidx.core.util.SparseArrayKt$valueIterator$1, reason: invalid class name and case insensitive filesystem */
    public static final class C01601<T> implements Iterator<T>, z1.a {
        final /* synthetic */ SparseArray<T> $this_valueIterator;
        private int index;

        C01601(SparseArray<T> sparseArray) {
            this.$this_valueIterator = sparseArray;
        }

        public final int getIndex() {
            return this.index;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            return this.index < this.$this_valueIterator.size();
        }

        @Override // java.util.Iterator
        public T next() {
            SparseArray<T> sparseArray = this.$this_valueIterator;
            int i2 = this.index;
            this.index = i2 + 1;
            return sparseArray.valueAt(i2);
        }

        @Override // java.util.Iterator
        public void remove() {
            throw new UnsupportedOperationException("Operation is not supported for read-only collection");
        }

        public final void setIndex(int i2) {
            this.index = i2;
        }
    }

    public static final <T> boolean contains(SparseArray<T> sparseArray, int i2) {
        l.e(sparseArray, "<this>");
        return sparseArray.indexOfKey(i2) >= 0;
    }

    public static final <T> boolean containsKey(SparseArray<T> sparseArray, int i2) {
        l.e(sparseArray, "<this>");
        return sparseArray.indexOfKey(i2) >= 0;
    }

    public static final <T> boolean containsValue(SparseArray<T> sparseArray, T t2) {
        l.e(sparseArray, "<this>");
        return sparseArray.indexOfValue(t2) >= 0;
    }

    public static final <T> void forEach(SparseArray<T> sparseArray, p action) {
        l.e(sparseArray, "<this>");
        l.e(action, "action");
        int size = sparseArray.size();
        for (int i2 = 0; i2 < size; i2++) {
            action.invoke(Integer.valueOf(sparseArray.keyAt(i2)), sparseArray.valueAt(i2));
        }
    }

    public static final <T> T getOrDefault(SparseArray<T> sparseArray, int i2, T t2) {
        l.e(sparseArray, "<this>");
        T t3 = sparseArray.get(i2);
        return t3 == null ? t2 : t3;
    }

    public static final <T> T getOrElse(SparseArray<T> sparseArray, int i2, y1.a defaultValue) {
        l.e(sparseArray, "<this>");
        l.e(defaultValue, "defaultValue");
        T t2 = sparseArray.get(i2);
        return t2 == null ? (T) defaultValue.invoke() : t2;
    }

    public static final <T> int getSize(SparseArray<T> sparseArray) {
        l.e(sparseArray, "<this>");
        return sparseArray.size();
    }

    public static final <T> boolean isEmpty(SparseArray<T> sparseArray) {
        l.e(sparseArray, "<this>");
        return sparseArray.size() == 0;
    }

    public static final <T> boolean isNotEmpty(SparseArray<T> sparseArray) {
        l.e(sparseArray, "<this>");
        return sparseArray.size() != 0;
    }

    public static final <T> AbstractC0653A keyIterator(final SparseArray<T> sparseArray) {
        l.e(sparseArray, "<this>");
        return new AbstractC0653A() { // from class: androidx.core.util.SparseArrayKt.keyIterator.1
            private int index;

            public final int getIndex() {
                return this.index;
            }

            @Override // java.util.Iterator
            public boolean hasNext() {
                return this.index < sparseArray.size();
            }

            @Override // o1.AbstractC0653A
            public int nextInt() {
                SparseArray<T> sparseArray2 = sparseArray;
                int i2 = this.index;
                this.index = i2 + 1;
                return sparseArray2.keyAt(i2);
            }

            public final void setIndex(int i2) {
                this.index = i2;
            }
        };
    }

    public static final <T> SparseArray<T> plus(SparseArray<T> sparseArray, SparseArray<T> other) {
        l.e(sparseArray, "<this>");
        l.e(other, "other");
        SparseArray<T> sparseArray2 = new SparseArray<>(sparseArray.size() + other.size());
        putAll(sparseArray2, sparseArray);
        putAll(sparseArray2, other);
        return sparseArray2;
    }

    public static final <T> void putAll(SparseArray<T> sparseArray, SparseArray<T> other) {
        l.e(sparseArray, "<this>");
        l.e(other, "other");
        int size = other.size();
        for (int i2 = 0; i2 < size; i2++) {
            sparseArray.put(other.keyAt(i2), other.valueAt(i2));
        }
    }

    public static final <T> boolean remove(SparseArray<T> sparseArray, int i2, T t2) {
        l.e(sparseArray, "<this>");
        int iIndexOfKey = sparseArray.indexOfKey(i2);
        if (iIndexOfKey < 0 || !l.a(t2, sparseArray.valueAt(iIndexOfKey))) {
            return false;
        }
        sparseArray.removeAt(iIndexOfKey);
        return true;
    }

    public static final <T> void set(SparseArray<T> sparseArray, int i2, T t2) {
        l.e(sparseArray, "<this>");
        sparseArray.put(i2, t2);
    }

    public static final <T> Iterator<T> valueIterator(SparseArray<T> sparseArray) {
        l.e(sparseArray, "<this>");
        return new C01601(sparseArray);
    }
}
