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 { private final Pools$Pool> a = new Pools$SimplePool(10); private final SimpleArrayMap> b = new SimpleArrayMap<>(); private final ArrayList c = new ArrayList<>(); private final HashSet 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 d(T t) { int size = this.b.size(); ArrayList arrayList = null; for (int i = 0; i < size; i++) { ArrayList 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 d = this.b.d(i); if (d != null && d.contains(t)) { return true; } } return false; } private ArrayList c() { ArrayList a = this.a.a(); return a == null ? new ArrayList<>() : a; } public ArrayList 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 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 d = this.b.d(i); if (d != null) { a((ArrayList) d); } } this.b.clear(); } private void a(T t, ArrayList arrayList, HashSet hashSet) { if (arrayList.contains(t)) { return; } if (!hashSet.contains(t)) { hashSet.add(t); ArrayList 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 arrayList) { arrayList.clear(); this.a.a(arrayList); } }