package g5;

import com.bumptech.glide.Registry$NoModelLoaderAvailableException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final androidx.window.core.h f26196e = new androidx.window.core.h(12);

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final h0 f26197f = new h0();

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ArrayList f26198a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final androidx.window.core.h f26199b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final HashSet f26200c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final p0.e f26201d;

    public j0(xyz.stream.utils.t tVar) {
        androidx.window.core.h hVar = f26196e;
        this.f26198a = new ArrayList();
        this.f26200c = new HashSet();
        this.f26201d = tVar;
        this.f26199b = hVar;
    }

    public final synchronized void a(Class cls, Class cls2, c0 c0Var) {
        i0 i0Var = new i0(cls, cls2, c0Var);
        ArrayList arrayList = this.f26198a;
        arrayList.add(arrayList.size(), i0Var);
    }

    public final b0 b(i0 i0Var) {
        return (b0) t5.n.checkNotNull(i0Var.f26191c.a(this));
    }

    public final synchronized b0 c(Class cls, Class cls2) {
        try {
            ArrayList arrayList = new ArrayList();
            boolean z10 = false;
            for (i0 i0Var : this.f26198a) {
                if (this.f26200c.contains(i0Var)) {
                    z10 = true;
                } else if (i0Var.f26189a.isAssignableFrom(cls) && i0Var.f26190b.isAssignableFrom(cls2)) {
                    this.f26200c.add(i0Var);
                    arrayList.add(b(i0Var));
                    this.f26200c.remove(i0Var);
                }
            }
            if (arrayList.size() > 1) {
                androidx.window.core.h hVar = this.f26199b;
                p0.e eVar = this.f26201d;
                hVar.getClass();
                return new g0(arrayList, eVar);
            }
            if (arrayList.size() == 1) {
                return (b0) arrayList.get(0);
            }
            if (z10) {
                return f26197f;
            }
            throw new Registry$NoModelLoaderAvailableException("Failed to find any ModelLoaders for model: " + cls + " and data: " + cls2);
        } catch (Throwable th) {
            this.f26200c.clear();
            throw th;
        }
    }

    public final synchronized ArrayList d(Class cls) {
        ArrayList arrayList;
        try {
            arrayList = new ArrayList();
            for (i0 i0Var : this.f26198a) {
                if (!this.f26200c.contains(i0Var) && i0Var.f26189a.isAssignableFrom(cls)) {
                    this.f26200c.add(i0Var);
                    arrayList.add(b(i0Var));
                    this.f26200c.remove(i0Var);
                }
            }
        } catch (Throwable th) {
            this.f26200c.clear();
            throw th;
        }
        return arrayList;
    }

    public final synchronized ArrayList e(Class cls) {
        ArrayList arrayList;
        arrayList = new ArrayList();
        for (i0 i0Var : this.f26198a) {
            if (!arrayList.contains(i0Var.f26190b) && i0Var.f26189a.isAssignableFrom(cls)) {
                arrayList.add(i0Var.f26190b);
            }
        }
        return arrayList;
    }

    public final synchronized ArrayList f() {
        ArrayList arrayList;
        arrayList = new ArrayList();
        Iterator it = this.f26198a.iterator();
        while (it.hasNext()) {
            i0 i0Var = (i0) it.next();
            if (i0Var.f26189a.isAssignableFrom(o.class) && i0Var.f26190b.isAssignableFrom(InputStream.class)) {
                it.remove();
                arrayList.add(i0Var.f26191c);
            }
        }
        return arrayList;
    }
}
