package com.bumptech.glide.load.model; import androidx.core.util.Pools$Pool; import com.bumptech.glide.Registry; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.model.ModelLoader; import com.bumptech.glide.util.Preconditions; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; /* loaded from: classes.dex */ public class MultiModelLoaderFactory { private static final Factory e = new Factory(); private static final ModelLoader f = new EmptyModelLoader(); private final List> a; private final Factory b; private final Set> c; private final Pools$Pool> d; private static class EmptyModelLoader implements ModelLoader { EmptyModelLoader() { } @Override // com.bumptech.glide.load.model.ModelLoader public ModelLoader.LoadData a(Object obj, int i, int i2, Options options) { return null; } @Override // com.bumptech.glide.load.model.ModelLoader public boolean a(Object obj) { return false; } } private static class Entry { private final Class a; final Class b; final ModelLoaderFactory c; public Entry(Class cls, Class cls2, ModelLoaderFactory modelLoaderFactory) { this.a = cls; this.b = cls2; this.c = modelLoaderFactory; } public boolean a(Class cls, Class cls2) { return a(cls) && this.b.isAssignableFrom(cls2); } public boolean a(Class cls) { return this.a.isAssignableFrom(cls); } } static class Factory { Factory() { } public MultiModelLoader a(List> list, Pools$Pool> pools$Pool) { return new MultiModelLoader<>(list, pools$Pool); } } public MultiModelLoaderFactory(Pools$Pool> pools$Pool) { this(pools$Pool, e); } synchronized void a(Class cls, Class cls2, ModelLoaderFactory modelLoaderFactory) { a(cls, cls2, modelLoaderFactory, true); } synchronized List> b(Class cls, Class cls2, ModelLoaderFactory modelLoaderFactory) { List> b; b = b(cls, cls2); a(cls, cls2, modelLoaderFactory); return b; } MultiModelLoaderFactory(Pools$Pool> pools$Pool, Factory factory) { this.a = new ArrayList(); this.c = new HashSet(); this.d = pools$Pool; this.b = factory; } private void a(Class cls, Class cls2, ModelLoaderFactory modelLoaderFactory, boolean z) { Entry entry = new Entry<>(cls, cls2, modelLoaderFactory); List> list = this.a; list.add(z ? list.size() : 0, entry); } synchronized List> b(Class cls, Class cls2) { ArrayList arrayList; arrayList = new ArrayList(); Iterator> it = this.a.iterator(); while (it.hasNext()) { Entry next = it.next(); if (next.a(cls, cls2)) { it.remove(); arrayList.add(b(next)); } } return arrayList; } synchronized List> a(Class cls) { ArrayList arrayList; try { arrayList = new ArrayList(); for (Entry entry : this.a) { if (!this.c.contains(entry) && entry.a(cls)) { this.c.add(entry); arrayList.add(a(entry)); this.c.remove(entry); } } } catch (Throwable th) { this.c.clear(); throw th; } return arrayList; } synchronized List> b(Class cls) { ArrayList arrayList; arrayList = new ArrayList(); for (Entry entry : this.a) { if (!arrayList.contains(entry.b) && entry.a(cls)) { arrayList.add(entry.b); } } return arrayList; } public synchronized ModelLoader a(Class cls, Class cls2) { try { ArrayList arrayList = new ArrayList(); boolean z = false; for (Entry entry : this.a) { if (this.c.contains(entry)) { z = true; } else if (entry.a(cls, cls2)) { this.c.add(entry); arrayList.add(a(entry)); this.c.remove(entry); } } if (arrayList.size() > 1) { return this.b.a(arrayList, this.d); } if (arrayList.size() == 1) { return (ModelLoader) arrayList.get(0); } if (z) { return a(); } throw new Registry.NoModelLoaderAvailableException(cls, cls2); } catch (Throwable th) { this.c.clear(); throw th; } } private ModelLoaderFactory b(Entry entry) { return (ModelLoaderFactory) entry.c; } private ModelLoader a(Entry entry) { Object a = entry.c.a(this); Preconditions.a(a); return (ModelLoader) a; } private static ModelLoader a() { return (ModelLoader) f; } }