- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
155 lines
5.3 KiB
Java
155 lines
5.3 KiB
Java
package com.google.firebase.components;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public abstract class CycleDetector {
|
|
|
|
public static class Dep {
|
|
public final Qualified anInterface;
|
|
public final boolean set;
|
|
|
|
public Dep(Qualified qualified, boolean z) {
|
|
this.anInterface = qualified;
|
|
this.set = z;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (!(obj instanceof Dep)) {
|
|
return false;
|
|
}
|
|
Dep dep = (Dep) obj;
|
|
return dep.anInterface.equals(this.anInterface) && dep.set == this.set;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return ((this.anInterface.hashCode() ^ 1000003) * 1000003) ^ Boolean.valueOf(this.set).hashCode();
|
|
}
|
|
}
|
|
|
|
public static class ComponentNode {
|
|
public final Component component;
|
|
public final Set dependencies = new HashSet();
|
|
public final Set dependents = new HashSet();
|
|
|
|
public Component getComponent() {
|
|
return this.component;
|
|
}
|
|
|
|
public Set getDependencies() {
|
|
return this.dependencies;
|
|
}
|
|
|
|
public ComponentNode(Component component) {
|
|
this.component = component;
|
|
}
|
|
|
|
public void addDependency(ComponentNode componentNode) {
|
|
this.dependencies.add(componentNode);
|
|
}
|
|
|
|
public void addDependent(ComponentNode componentNode) {
|
|
this.dependents.add(componentNode);
|
|
}
|
|
|
|
public void removeDependent(ComponentNode componentNode) {
|
|
this.dependents.remove(componentNode);
|
|
}
|
|
|
|
public boolean isRoot() {
|
|
return this.dependents.isEmpty();
|
|
}
|
|
|
|
public boolean isLeaf() {
|
|
return this.dependencies.isEmpty();
|
|
}
|
|
}
|
|
|
|
public static void detect(List list) {
|
|
Set<ComponentNode> graph = toGraph(list);
|
|
Set roots = getRoots(graph);
|
|
int i = 0;
|
|
while (!roots.isEmpty()) {
|
|
ComponentNode componentNode = (ComponentNode) roots.iterator().next();
|
|
roots.remove(componentNode);
|
|
i++;
|
|
for (ComponentNode componentNode2 : componentNode.getDependencies()) {
|
|
componentNode2.removeDependent(componentNode);
|
|
if (componentNode2.isRoot()) {
|
|
roots.add(componentNode2);
|
|
}
|
|
}
|
|
}
|
|
if (i == list.size()) {
|
|
return;
|
|
}
|
|
ArrayList arrayList = new ArrayList();
|
|
for (ComponentNode componentNode3 : graph) {
|
|
if (!componentNode3.isRoot() && !componentNode3.isLeaf()) {
|
|
arrayList.add(componentNode3.getComponent());
|
|
}
|
|
}
|
|
throw new DependencyCycleException(arrayList);
|
|
}
|
|
|
|
public static Set toGraph(List list) {
|
|
Set<ComponentNode> set;
|
|
HashMap hashMap = new HashMap(list.size());
|
|
Iterator it = list.iterator();
|
|
while (true) {
|
|
if (it.hasNext()) {
|
|
Component component = (Component) it.next();
|
|
ComponentNode componentNode = new ComponentNode(component);
|
|
for (Qualified qualified : component.getProvidedInterfaces()) {
|
|
Dep dep = new Dep(qualified, !component.isValue());
|
|
if (!hashMap.containsKey(dep)) {
|
|
hashMap.put(dep, new HashSet());
|
|
}
|
|
Set set2 = (Set) hashMap.get(dep);
|
|
if (!set2.isEmpty() && !dep.set) {
|
|
throw new IllegalArgumentException(String.format("Multiple components provide %s.", qualified));
|
|
}
|
|
set2.add(componentNode);
|
|
}
|
|
} else {
|
|
Iterator it2 = hashMap.values().iterator();
|
|
while (it2.hasNext()) {
|
|
for (ComponentNode componentNode2 : (Set) it2.next()) {
|
|
for (Dependency dependency : componentNode2.getComponent().getDependencies()) {
|
|
if (dependency.isDirectInjection() && (set = (Set) hashMap.get(new Dep(dependency.getInterface(), dependency.isSet()))) != null) {
|
|
for (ComponentNode componentNode3 : set) {
|
|
componentNode2.addDependency(componentNode3);
|
|
componentNode3.addDependent(componentNode2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
HashSet hashSet = new HashSet();
|
|
Iterator it3 = hashMap.values().iterator();
|
|
while (it3.hasNext()) {
|
|
hashSet.addAll((Set) it3.next());
|
|
}
|
|
return hashSet;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Set getRoots(Set set) {
|
|
HashSet hashSet = new HashSet();
|
|
Iterator it = set.iterator();
|
|
while (it.hasNext()) {
|
|
ComponentNode componentNode = (ComponentNode) it.next();
|
|
if (componentNode.isRoot()) {
|
|
hashSet.add(componentNode);
|
|
}
|
|
}
|
|
return hashSet;
|
|
}
|
|
}
|