package defpackage;

import com.bumptech.glide.integration.okhttp3.b;
import defpackage.ex7;
import defpackage.vc7;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class b86 {
    public final ac6 a;
    public final a b;

    public static class a {
        public final HashMap a = new HashMap();

        /* JADX INFO: renamed from: b86$a$a, reason: collision with other inner class name */
        public static class C0070a<Model> {
            public final List a;

            public C0070a(List list) {
                this.a = list;
            }
        }
    }

    public b86(vc7.a aVar) {
        ac6 ac6Var = new ac6(aVar);
        this.b = new a();
        this.a = ac6Var;
    }

    public final synchronized void a(Class cls, Class cls2, a86 a86Var) {
        this.a.a(cls, cls2, a86Var);
        this.b.a.clear();
    }

    public final List b(Object obj) {
        List listUnmodifiableList;
        Class<?> cls = obj.getClass();
        synchronized (this) {
            a.C0070a c0070a = (a.C0070a) this.b.a.get(cls);
            listUnmodifiableList = c0070a == null ? null : c0070a.a;
            if (listUnmodifiableList == null) {
                listUnmodifiableList = Collections.unmodifiableList(this.a.c(cls));
                if (((a.C0070a) this.b.a.put(cls, new a.C0070a(listUnmodifiableList))) != null) {
                    throw new IllegalStateException("Already cached loaders for model: " + cls);
                }
            }
        }
        if (listUnmodifiableList.isEmpty()) {
            throw new ex7.c("Failed to find any ModelLoaders registered for model class: " + obj.getClass());
        }
        int size = listUnmodifiableList.size();
        List arrayList = Collections.EMPTY_LIST;
        boolean z = true;
        for (int i = 0; i < size; i++) {
            z76 z76Var = (z76) listUnmodifiableList.get(i);
            if (z76Var.a(obj)) {
                if (z) {
                    arrayList = new ArrayList(size - i);
                    z = false;
                }
                arrayList.add(z76Var);
            }
        }
        if (!arrayList.isEmpty()) {
            return arrayList;
        }
        throw new ex7.c("Found ModelLoaders for model class: " + listUnmodifiableList + ", but none that handle this specific model instance: " + obj);
    }

    public final synchronized void c(b.a aVar) {
        ArrayList arrayListE;
        ac6 ac6Var = this.a;
        synchronized (ac6Var) {
            arrayListE = ac6Var.e();
            ac6Var.a(wv3.class, InputStream.class, aVar);
        }
        Iterator it = arrayListE.iterator();
        while (it.hasNext()) {
            ((a86) it.next()).getClass();
        }
        this.b.a.clear();
    }
}
