244 lines
8.4 KiB
Java
244 lines
8.4 KiB
Java
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<T> {
|
|
private final Set<Class<? super T>> a;
|
|
private final Set<Dependency> b;
|
|
private final int c;
|
|
private final ComponentFactory<T> d;
|
|
private final Set<Class<?>> 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<T> {
|
|
private final T a;
|
|
private final zze<T> b;
|
|
|
|
private AnonymousClass1(T t, zze<T> zzeVar) {
|
|
this.a = t;
|
|
this.b = zzeVar;
|
|
}
|
|
|
|
public static AnonymousClass1<Context> a(Context context) {
|
|
return new AnonymousClass1<>(context, new zzd((byte) 0));
|
|
}
|
|
|
|
private static List<ComponentRegistrar> b(List<String> 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<ComponentRegistrar> a() {
|
|
return b(this.b.a(this.a));
|
|
}
|
|
|
|
static List<Component<?>> a(List<Component<?>> list) {
|
|
zzg zzgVar;
|
|
HashMap hashMap = new HashMap(list.size());
|
|
for (Component<?> component : list) {
|
|
zzg zzgVar2 = new zzg(component);
|
|
for (Class<? super Object> 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<zzg> hashSet = new HashSet(hashMap.values());
|
|
Set<zzg> 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<zzg> a(Set<zzg> 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<T> {
|
|
private final Set<Class<? super T>> a;
|
|
private final Set<Dependency> b;
|
|
private int c;
|
|
private ComponentFactory<T> d;
|
|
private Set<Class<?>> e;
|
|
|
|
/* synthetic */ Builder(Class cls, Class[] clsArr, byte b) {
|
|
this(cls, clsArr);
|
|
}
|
|
|
|
public Builder<T> 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<T> 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<T> c() {
|
|
a(2);
|
|
return this;
|
|
}
|
|
|
|
private Builder(Class<T> cls, Class<? super T>... 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<? super T> cls2 : clsArr) {
|
|
Preconditions.a(cls2, "Null interface");
|
|
}
|
|
Collections.addAll(this.a, clsArr);
|
|
}
|
|
|
|
public Builder<T> a() {
|
|
a(1);
|
|
return this;
|
|
}
|
|
|
|
private Builder<T> a(int i) {
|
|
Preconditions.b(this.c == 0, "Instantiation type has already been set.");
|
|
this.c = i;
|
|
return this;
|
|
}
|
|
|
|
public Builder<T> a(ComponentFactory<T> 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<Class<? super T>> a() {
|
|
return this.a;
|
|
}
|
|
|
|
public final Set<Dependency> b() {
|
|
return this.b;
|
|
}
|
|
|
|
public final ComponentFactory<T> c() {
|
|
return this.d;
|
|
}
|
|
|
|
public final Set<Class<?>> 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<Class<? super T>> set, Set<Dependency> set2, int i, ComponentFactory<T> componentFactory, Set<Class<?>> set3) {
|
|
this.a = Collections.unmodifiableSet(set);
|
|
this.b = Collections.unmodifiableSet(set2);
|
|
this.c = i;
|
|
this.d = componentFactory;
|
|
this.e = Collections.unmodifiableSet(set3);
|
|
}
|
|
|
|
public static <T> Builder<T> a(Class<T> cls) {
|
|
return new Builder<>(cls, new Class[0], (byte) 0);
|
|
}
|
|
|
|
public static <T> Builder<T> a(Class<T> cls, Class<? super T>... clsArr) {
|
|
return new Builder<>(cls, clsArr, (byte) 0);
|
|
}
|
|
|
|
@SafeVarargs
|
|
public static <T> Component<T> a(T t, Class<T> cls, Class<? super T>... clsArr) {
|
|
Builder a = a(cls, clsArr);
|
|
a.a(zzc.a(t));
|
|
return a.b();
|
|
}
|
|
}
|