package com.bumptech.glide.load.model; import androidx.core.util.Pools$Pool; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /* loaded from: classes.dex */ public class ModelLoaderRegistry { private final MultiModelLoaderFactory a; private final ModelLoaderCache b; private static class ModelLoaderCache { private final Map, Entry> a = new HashMap(); private static class Entry { final List> a; public Entry(List> list) { this.a = list; } } ModelLoaderCache() { } public void a() { this.a.clear(); } public void a(Class cls, List> list) { if (this.a.put(cls, new Entry<>(list)) == null) { return; } throw new IllegalStateException("Already cached loaders for model: " + cls); } public List> a(Class cls) { Entry entry = this.a.get(cls); if (entry == null) { return null; } return (List>) entry.a; } } public ModelLoaderRegistry(Pools$Pool> pools$Pool) { this(new MultiModelLoaderFactory(pools$Pool)); } public synchronized void a(Class cls, Class cls2, ModelLoaderFactory modelLoaderFactory) { this.a.a(cls, cls2, modelLoaderFactory); this.b.a(); } public synchronized void b(Class cls, Class cls2, ModelLoaderFactory modelLoaderFactory) { a((List) this.a.b(cls, cls2, modelLoaderFactory)); this.b.a(); } private ModelLoaderRegistry(MultiModelLoaderFactory multiModelLoaderFactory) { this.b = new ModelLoaderCache(); this.a = multiModelLoaderFactory; } private void a(List> list) { Iterator> it = list.iterator(); while (it.hasNext()) { it.next().a(); } } private List> b(Class cls) { List> a = this.b.a(cls); if (a != null) { return a; } List> unmodifiableList = Collections.unmodifiableList(this.a.a(cls)); this.b.a(cls, unmodifiableList); return unmodifiableList; } public synchronized List> a(A a) { ArrayList arrayList; List> b = b((Class) b(a)); int size = b.size(); arrayList = new ArrayList(size); for (int i = 0; i < size; i++) { ModelLoader modelLoader = b.get(i); if (modelLoader.a(a)) { arrayList.add(modelLoader); } } return arrayList; } private static Class b(A a) { return (Class) a.getClass(); } public synchronized List> a(Class cls) { return this.a.b(cls); } }