package ph;

import com.bumptech.glide.i;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import ph.n;

/* loaded from: classes4.dex */
public class r {

    /* renamed from: e, reason: collision with root package name */
    private static final c f32722e = new c();

    /* renamed from: f, reason: collision with root package name */
    private static final n f32723f = new a();

    /* renamed from: a, reason: collision with root package name */
    private final List f32724a;

    /* renamed from: b, reason: collision with root package name */
    private final c f32725b;

    /* renamed from: c, reason: collision with root package name */
    private final Set f32726c;

    /* renamed from: d, reason: collision with root package name */
    private final s3.f f32727d;

    /* loaded from: classes4.dex */
    private static class a implements n {
        a() {
        }

        @Override // ph.n
        public boolean a(Object obj) {
            return false;
        }

        @Override // ph.n
        public n.a b(Object obj, int i10, int i11, jh.h hVar) {
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes4.dex */
    public static class b {

        /* renamed from: a, reason: collision with root package name */
        private final Class f32728a;

        /* renamed from: b, reason: collision with root package name */
        final Class f32729b;

        /* renamed from: c, reason: collision with root package name */
        final o f32730c;

        public b(Class cls, Class cls2, o oVar) {
            this.f32728a = cls;
            this.f32729b = cls2;
            this.f32730c = oVar;
        }

        public boolean a(Class cls) {
            return this.f32728a.isAssignableFrom(cls);
        }

        public boolean b(Class cls, Class cls2) {
            return a(cls) && this.f32729b.isAssignableFrom(cls2);
        }
    }

    /* loaded from: classes4.dex */
    static class c {
        c() {
        }

        public q a(List list, s3.f fVar) {
            return new q(list, fVar);
        }
    }

    public r(s3.f fVar) {
        this(fVar, f32722e);
    }

    private void a(Class cls, Class cls2, o oVar, boolean z10) {
        b bVar = new b(cls, cls2, oVar);
        List list = this.f32724a;
        list.add(z10 ? list.size() : 0, bVar);
    }

    private n e(b bVar) {
        return (n) ei.k.d(bVar.f32730c.e(this));
    }

    private static n f() {
        return f32723f;
    }

    private o h(b bVar) {
        return bVar.f32730c;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public synchronized void b(Class cls, Class cls2, o oVar) {
        a(cls, cls2, oVar, true);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public synchronized List c(Class cls) {
        ArrayList arrayList;
        try {
            arrayList = new ArrayList();
            for (b bVar : this.f32724a) {
                if (!this.f32726c.contains(bVar) && bVar.a(cls)) {
                    this.f32726c.add(bVar);
                    arrayList.add(e(bVar));
                    this.f32726c.remove(bVar);
                }
            }
        } catch (Throwable th2) {
            this.f32726c.clear();
            throw th2;
        }
        return arrayList;
    }

    public synchronized n d(Class cls, Class cls2) {
        try {
            ArrayList arrayList = new ArrayList();
            boolean z10 = false;
            for (b bVar : this.f32724a) {
                if (this.f32726c.contains(bVar)) {
                    z10 = true;
                } else if (bVar.b(cls, cls2)) {
                    this.f32726c.add(bVar);
                    arrayList.add(e(bVar));
                    this.f32726c.remove(bVar);
                }
            }
            if (arrayList.size() > 1) {
                return this.f32725b.a(arrayList, this.f32727d);
            }
            if (arrayList.size() == 1) {
                return (n) arrayList.get(0);
            }
            if (!z10) {
                throw new i.c(cls, cls2);
            }
            return f();
        } catch (Throwable th2) {
            this.f32726c.clear();
            throw th2;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public synchronized List g(Class cls) {
        ArrayList arrayList;
        arrayList = new ArrayList();
        for (b bVar : this.f32724a) {
            if (!arrayList.contains(bVar.f32729b) && bVar.a(cls)) {
                arrayList.add(bVar.f32729b);
            }
        }
        return arrayList;
    }

    synchronized List i(Class cls, Class cls2) {
        ArrayList arrayList;
        arrayList = new ArrayList();
        Iterator it = this.f32724a.iterator();
        while (it.hasNext()) {
            b bVar = (b) it.next();
            if (bVar.b(cls, cls2)) {
                it.remove();
                arrayList.add(h(bVar));
            }
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public synchronized List j(Class cls, Class cls2, o oVar) {
        List i10;
        i10 = i(cls, cls2);
        b(cls, cls2, oVar);
        return i10;
    }

    r(s3.f fVar, c cVar) {
        this.f32724a = new ArrayList();
        this.f32726c = new HashSet();
        this.f32727d = fVar;
        this.f32725b = cVar;
    }
}
