108 lines
3.3 KiB
Java
108 lines
3.3 KiB
Java
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<Class<?>, Entry<?>> a = new HashMap();
|
|
|
|
private static class Entry<Model> {
|
|
final List<ModelLoader<Model, ?>> a;
|
|
|
|
public Entry(List<ModelLoader<Model, ?>> list) {
|
|
this.a = list;
|
|
}
|
|
}
|
|
|
|
ModelLoaderCache() {
|
|
}
|
|
|
|
public void a() {
|
|
this.a.clear();
|
|
}
|
|
|
|
public <Model> void a(Class<Model> cls, List<ModelLoader<Model, ?>> list) {
|
|
if (this.a.put(cls, new Entry<>(list)) == null) {
|
|
return;
|
|
}
|
|
throw new IllegalStateException("Already cached loaders for model: " + cls);
|
|
}
|
|
|
|
public <Model> List<ModelLoader<Model, ?>> a(Class<Model> cls) {
|
|
Entry<?> entry = this.a.get(cls);
|
|
if (entry == null) {
|
|
return null;
|
|
}
|
|
return (List<ModelLoader<Model, ?>>) entry.a;
|
|
}
|
|
}
|
|
|
|
public ModelLoaderRegistry(Pools$Pool<List<Throwable>> pools$Pool) {
|
|
this(new MultiModelLoaderFactory(pools$Pool));
|
|
}
|
|
|
|
public synchronized <Model, Data> void a(Class<Model> cls, Class<Data> cls2, ModelLoaderFactory<? extends Model, ? extends Data> modelLoaderFactory) {
|
|
this.a.a(cls, cls2, modelLoaderFactory);
|
|
this.b.a();
|
|
}
|
|
|
|
public synchronized <Model, Data> void b(Class<Model> cls, Class<Data> cls2, ModelLoaderFactory<? extends Model, ? extends Data> modelLoaderFactory) {
|
|
a((List) this.a.b(cls, cls2, modelLoaderFactory));
|
|
this.b.a();
|
|
}
|
|
|
|
private ModelLoaderRegistry(MultiModelLoaderFactory multiModelLoaderFactory) {
|
|
this.b = new ModelLoaderCache();
|
|
this.a = multiModelLoaderFactory;
|
|
}
|
|
|
|
private <Model, Data> void a(List<ModelLoaderFactory<? extends Model, ? extends Data>> list) {
|
|
Iterator<ModelLoaderFactory<? extends Model, ? extends Data>> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().a();
|
|
}
|
|
}
|
|
|
|
private <A> List<ModelLoader<A, ?>> b(Class<A> cls) {
|
|
List<ModelLoader<A, ?>> a = this.b.a(cls);
|
|
if (a != null) {
|
|
return a;
|
|
}
|
|
List<ModelLoader<A, ?>> unmodifiableList = Collections.unmodifiableList(this.a.a(cls));
|
|
this.b.a(cls, unmodifiableList);
|
|
return unmodifiableList;
|
|
}
|
|
|
|
public synchronized <A> List<ModelLoader<A, ?>> a(A a) {
|
|
ArrayList arrayList;
|
|
List<ModelLoader<A, ?>> b = b((Class) b(a));
|
|
int size = b.size();
|
|
arrayList = new ArrayList(size);
|
|
for (int i = 0; i < size; i++) {
|
|
ModelLoader<A, ?> modelLoader = b.get(i);
|
|
if (modelLoader.a(a)) {
|
|
arrayList.add(modelLoader);
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
private static <A> Class<A> b(A a) {
|
|
return (Class<A>) a.getClass();
|
|
}
|
|
|
|
public synchronized List<Class<?>> a(Class<?> cls) {
|
|
return this.a.b(cls);
|
|
}
|
|
}
|