package com.bumptech.glide.c.c;

import android.support.v4.f.k$a;
import com.bumptech.glide.h.c;
import com.bumptech.glide.h.i;
import com.tencent.matrix.trace.core.AppMethodBeat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public final class r {
    private static final n<Object, Object> aEA = new a();
    private static final c aEz = new c();
    private final List<b<?, ?>> aEB;
    private final c aEC;
    private final Set<b<?, ?>> aED;
    private final k$a<List<Throwable>> awV;

    static {
        AppMethodBeat.i(92125);
        AppMethodBeat.o(92125);
    }

    public r(k$a<List<Throwable>> k_a) {
        this(k_a, aEz);
    }

    private r(k$a<List<Throwable>> k_a, c cVar) {
        AppMethodBeat.i(92119);
        this.aEB = new ArrayList();
        this.aED = new HashSet();
        this.awV = k_a;
        this.aEC = cVar;
        AppMethodBeat.o(92119);
    }

    /* Access modifiers changed, original: final|declared_synchronized */
    public final synchronized <Model> List<n<Model, ?>> s(Class<Model> cls) {
        ArrayList arrayList;
        AppMethodBeat.i(92121);
        try {
            arrayList = new ArrayList();
            for (b bVar : this.aEB) {
                if (!this.aED.contains(bVar) && bVar.t(cls)) {
                    this.aED.add(bVar);
                    arrayList.add(a(bVar));
                    this.aED.remove(bVar);
                }
            }
            AppMethodBeat.o(92121);
        } catch (Throwable th) {
            this.aED.clear();
            AppMethodBeat.o(92121);
        }
        return arrayList;
    }

    /* Access modifiers changed, original: final|declared_synchronized */
    public final synchronized List<Class<?>> r(Class<?> cls) {
        ArrayList arrayList;
        AppMethodBeat.i(92122);
        arrayList = new ArrayList();
        for (b bVar : this.aEB) {
            if (!arrayList.contains(bVar.aBd) && bVar.t(cls)) {
                arrayList.add(bVar.aBd);
            }
        }
        AppMethodBeat.o(92122);
        return arrayList;
    }

    public final synchronized <Model, Data> n<Model, Data> b(Class<Model> cls, Class<Data> cls2) {
        n<Model, Data> qVar;
        AppMethodBeat.i(92123);
        try {
            ArrayList arrayList = new ArrayList();
            Object obj = null;
            for (b bVar : this.aEB) {
                if (this.aED.contains(bVar)) {
                    obj = 1;
                } else {
                    Object obj2;
                    if (bVar.t(cls) && bVar.aBd.isAssignableFrom(cls2)) {
                        obj2 = 1;
                    } else {
                        obj2 = null;
                    }
                    if (obj2 != null) {
                        this.aED.add(bVar);
                        arrayList.add(a(bVar));
                        this.aED.remove(bVar);
                    }
                }
            }
            if (arrayList.size() > 1) {
                qVar = new q(arrayList, this.awV);
                AppMethodBeat.o(92123);
            } else if (arrayList.size() == 1) {
                qVar = (n) arrayList.get(0);
                AppMethodBeat.o(92123);
            } else if (obj != null) {
                qVar = aEA;
                AppMethodBeat.o(92123);
            } else {
                c cVar = new c(cls, cls2);
                AppMethodBeat.o(92123);
                throw cVar;
            }
        } catch (Throwable th) {
            this.aED.clear();
            AppMethodBeat.o(92123);
        }
        return qVar;
    }

    private <Model, Data> n<Model, Data> a(b<?, ?> bVar) {
        AppMethodBeat.i(92124);
        n nVar = (n) i.d(bVar.aEF.a(this), "Argument must not be null");
        AppMethodBeat.o(92124);
        return nVar;
    }

    /* Access modifiers changed, original: final|declared_synchronized */
    public final synchronized <Model, Data> void b(Class<Model> cls, Class<Data> cls2, o<? extends Model, ? extends Data> oVar) {
        AppMethodBeat.i(92120);
        this.aEB.add(this.aEB.size(), new b(cls, cls2, oVar));
        AppMethodBeat.o(92120);
    }
}
