package nm;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import nm.b;
import pm.g;

/* loaded from: classes3.dex */
public final class c implements b {

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

    /* loaded from: classes3.dex */
    public static final class a extends RuntimeException {
        a(String str, ClassCastException classCastException) {
            super(str, classCastException);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public c(Map map, Map map2) {
        this.f30128a = d(map, map2);
    }

    private String b(Object obj) {
        ArrayList arrayList = new ArrayList();
        for (Class<?> cls = obj.getClass(); cls != null; cls = cls.getSuperclass()) {
            if (this.f30128a.containsKey(cls.getCanonicalName())) {
                arrayList.add(cls.getCanonicalName());
            }
        }
        return arrayList.isEmpty() ? String.format("No injector factory bound for Class<%s>", obj.getClass().getCanonicalName()) : String.format("No injector factory bound for Class<%1$s>. Injector factories were bound for supertypes of %1$s: %2$s. Did you mean to bind an injector factory for the subtype?", obj.getClass().getCanonicalName(), arrayList);
    }

    private static Map d(Map map, Map map2) {
        if (map.isEmpty()) {
            return map2;
        }
        LinkedHashMap b10 = pm.b.b(map.size() + map2.size());
        b10.putAll(map2);
        for (Map.Entry entry : map.entrySet()) {
            b10.put(((Class) entry.getKey()).getName(), entry.getValue());
        }
        return Collections.unmodifiableMap(b10);
    }

    @Override // nm.b
    public void a(Object obj) {
        if (!c(obj)) {
            throw new IllegalArgumentException(b(obj));
        }
    }

    public boolean c(Object obj) {
        qm.a aVar = (qm.a) this.f30128a.get(obj.getClass().getName());
        if (aVar == null) {
            return false;
        }
        b.a aVar2 = (b.a) aVar.get();
        try {
            ((b) g.d(aVar2.a(obj), "%s.create(I) should not return null.", aVar2.getClass())).a(obj);
            return true;
        } catch (ClassCastException e10) {
            throw new a(String.format("%s does not implement AndroidInjector.Factory<%s>", aVar2.getClass().getCanonicalName(), obj.getClass().getCanonicalName()), e10);
        }
    }
}
