package com.google.firebase.components; import android.content.Context; import android.util.Log; import com.google.android.gms.common.internal.Preconditions; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; /* compiled from: com.google.firebase:firebase-common@@16.0.2 */ /* loaded from: classes.dex */ public final class Component { private final Set> a; private final Set b; private final int c; private final ComponentFactory d; private final Set> e; /* compiled from: com.google.firebase:firebase-common@@16.0.2 */ /* renamed from: com.google.firebase.components.Component$1, reason: invalid class name */ public static /* synthetic */ class AnonymousClass1 { private final T a; private final zze b; private AnonymousClass1(T t, zze zzeVar) { this.a = t; this.b = zzeVar; } public static AnonymousClass1 a(Context context) { return new AnonymousClass1<>(context, new zzd((byte) 0)); } private static List b(List list) { ArrayList arrayList = new ArrayList(); for (String str : list) { try { Class cls = Class.forName(str); if (ComponentRegistrar.class.isAssignableFrom(cls)) { arrayList.add((ComponentRegistrar) cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0])); } else { Log.w("ComponentDiscovery", String.format("Class %s is not an instance of %s", str, "com.google.firebase.components.ComponentRegistrar")); } } catch (ClassNotFoundException e) { Log.w("ComponentDiscovery", String.format("Class %s is not an found.", str), e); } catch (IllegalAccessException e2) { Log.w("ComponentDiscovery", String.format("Could not instantiate %s.", str), e2); } catch (InstantiationException e3) { Log.w("ComponentDiscovery", String.format("Could not instantiate %s.", str), e3); } catch (NoSuchMethodException e4) { Log.w("ComponentDiscovery", String.format("Could not instantiate %s", str), e4); } catch (InvocationTargetException e5) { Log.w("ComponentDiscovery", String.format("Could not instantiate %s", str), e5); } } return arrayList; } public List a() { return b(this.b.a(this.a)); } static List> a(List> list) { zzg zzgVar; HashMap hashMap = new HashMap(list.size()); for (Component component : list) { zzg zzgVar2 = new zzg(component); for (Class cls : component.a()) { if (hashMap.put(cls, zzgVar2) != null) { throw new IllegalArgumentException(String.format("Multiple components provide %s.", cls)); } } } for (zzg zzgVar3 : hashMap.values()) { for (Dependency dependency : zzgVar3.b().b()) { if (dependency.c() && (zzgVar = (zzg) hashMap.get(dependency.a())) != null) { zzgVar3.a(zzgVar); zzgVar.b(zzgVar3); } } } HashSet hashSet = new HashSet(hashMap.values()); Set a = a(hashSet); ArrayList arrayList = new ArrayList(); while (!a.isEmpty()) { zzg next = a.iterator().next(); a.remove(next); arrayList.add(next.b()); for (zzg zzgVar4 : next.a()) { zzgVar4.c(next); if (zzgVar4.c()) { a.add(zzgVar4); } } } if (arrayList.size() == list.size()) { Collections.reverse(arrayList); return arrayList; } ArrayList arrayList2 = new ArrayList(); for (zzg zzgVar5 : hashSet) { if (!zzgVar5.c() && !zzgVar5.d()) { arrayList2.add(zzgVar5.b()); } } throw new DependencyCycleException(arrayList2); } private static Set a(Set set) { HashSet hashSet = new HashSet(); for (zzg zzgVar : set) { if (zzgVar.c()) { hashSet.add(zzgVar); } } return hashSet; } } /* compiled from: com.google.firebase:firebase-common@@16.0.2 */ public static class Builder { private final Set> a; private final Set b; private int c; private ComponentFactory d; private Set> e; /* synthetic */ Builder(Class cls, Class[] clsArr, byte b) { this(cls, clsArr); } public Builder a(Dependency dependency) { Preconditions.a(dependency, "Null dependency"); Preconditions.a(!this.a.contains(dependency.a()), "Components are not allowed to depend on interfaces they themselves provide."); this.b.add(dependency); return this; } public Component b() { Preconditions.b(this.d != null, "Missing required property: factory."); return new Component<>(new HashSet(this.a), new HashSet(this.b), this.c, this.d, this.e, (byte) 0); } public Builder c() { a(2); return this; } private Builder(Class cls, Class... clsArr) { this.a = new HashSet(); this.b = new HashSet(); this.c = 0; this.e = new HashSet(); Preconditions.a(cls, "Null interface"); this.a.add(cls); for (Class cls2 : clsArr) { Preconditions.a(cls2, "Null interface"); } Collections.addAll(this.a, clsArr); } public Builder a() { a(1); return this; } private Builder a(int i) { Preconditions.b(this.c == 0, "Instantiation type has already been set."); this.c = i; return this; } public Builder a(ComponentFactory componentFactory) { Preconditions.a(componentFactory, "Null factory"); this.d = componentFactory; return this; } } /* synthetic */ Component(Set set, Set set2, int i, ComponentFactory componentFactory, Set set3, byte b) { this(set, set2, i, componentFactory, set3); } static /* synthetic */ Object a(Object obj) { return obj; } public final Set> a() { return this.a; } public final Set b() { return this.b; } public final ComponentFactory c() { return this.d; } public final Set> d() { return this.e; } public final boolean e() { return this.c == 1; } public final boolean f() { return this.c == 2; } public final String toString() { return "Component<" + Arrays.toString(this.a.toArray()) + ">{" + this.c + ", deps=" + Arrays.toString(this.b.toArray()) + "}"; } private Component(Set> set, Set set2, int i, ComponentFactory componentFactory, Set> set3) { this.a = Collections.unmodifiableSet(set); this.b = Collections.unmodifiableSet(set2); this.c = i; this.d = componentFactory; this.e = Collections.unmodifiableSet(set3); } public static Builder a(Class cls) { return new Builder<>(cls, new Class[0], (byte) 0); } public static Builder a(Class cls, Class... clsArr) { return new Builder<>(cls, clsArr, (byte) 0); } @SafeVarargs public static Component a(T t, Class cls, Class... clsArr) { Builder a = a(cls, clsArr); a.a(zzc.a(t)); return a.b(); } }