jimu-decompiled/sources/androidx/coordinatorlayout/widget/DirectedAcyclicGraph.java
2025-05-13 19:24:51 +02:00

122 lines
3.3 KiB
Java

package androidx.coordinatorlayout.widget;
import androidx.collection.SimpleArrayMap;
import androidx.core.util.Pools$Pool;
import androidx.core.util.Pools$SimplePool;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/* loaded from: classes.dex */
public final class DirectedAcyclicGraph<T> {
private final Pools$Pool<ArrayList<T>> a = new Pools$SimplePool(10);
private final SimpleArrayMap<T, ArrayList<T>> b = new SimpleArrayMap<>();
private final ArrayList<T> c = new ArrayList<>();
private final HashSet<T> d = new HashSet<>();
public void a(T t) {
if (this.b.containsKey(t)) {
return;
}
this.b.put(t, null);
}
public boolean b(T t) {
return this.b.containsKey(t);
}
public List c(T t) {
return this.b.get(t);
}
public List<T> d(T t) {
int size = this.b.size();
ArrayList arrayList = null;
for (int i = 0; i < size; i++) {
ArrayList<T> d = this.b.d(i);
if (d != null && d.contains(t)) {
if (arrayList == null) {
arrayList = new ArrayList();
}
arrayList.add(this.b.b(i));
}
}
return arrayList;
}
public boolean e(T t) {
int size = this.b.size();
for (int i = 0; i < size; i++) {
ArrayList<T> d = this.b.d(i);
if (d != null && d.contains(t)) {
return true;
}
}
return false;
}
private ArrayList<T> c() {
ArrayList<T> a = this.a.a();
return a == null ? new ArrayList<>() : a;
}
public ArrayList<T> b() {
this.c.clear();
this.d.clear();
int size = this.b.size();
for (int i = 0; i < size; i++) {
a(this.b.b(i), this.c, this.d);
}
return this.c;
}
public void a(T t, T t2) {
if (this.b.containsKey(t) && this.b.containsKey(t2)) {
ArrayList<T> arrayList = this.b.get(t);
if (arrayList == null) {
arrayList = c();
this.b.put(t, arrayList);
}
arrayList.add(t2);
return;
}
throw new IllegalArgumentException("All nodes must be present in the graph before being added as an edge");
}
public void a() {
int size = this.b.size();
for (int i = 0; i < size; i++) {
ArrayList<T> d = this.b.d(i);
if (d != null) {
a((ArrayList) d);
}
}
this.b.clear();
}
private void a(T t, ArrayList<T> arrayList, HashSet<T> hashSet) {
if (arrayList.contains(t)) {
return;
}
if (!hashSet.contains(t)) {
hashSet.add(t);
ArrayList<T> arrayList2 = this.b.get(t);
if (arrayList2 != null) {
int size = arrayList2.size();
for (int i = 0; i < size; i++) {
a(arrayList2.get(i), arrayList, hashSet);
}
}
hashSet.remove(t);
arrayList.add(t);
return;
}
throw new RuntimeException("This graph contains cyclic dependencies");
}
private void a(ArrayList<T> arrayList) {
arrayList.clear();
this.a.a(arrayList);
}
}