package X6FRs_4.IFxWkV_5.Mqv2r_3;

import X6FRs_4.IMuAHx_6.KNBe_11.IFxWkV_5;
import X6FRs_4.IMuAHx_6.KNBe_11.X6FRs_4;
import X6FRs_4.Mqv2r_3.IMuAHx_6;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/* compiled from: DirectedAcyclicGraph.java */
/* loaded from: classes.dex */
public final class KQgRr5e_0<T> {
    public final X6FRs_4<ArrayList<T>> KQgRr5e_0 = new IFxWkV_5(10);

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final IMuAHx_6<T, ArrayList<T>> f366KQgRr5e_0 = new IMuAHx_6<>();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final ArrayList<T> f367KQgRr5e_0 = new ArrayList<>();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final HashSet<T> f368KQgRr5e_0 = new HashSet<>();

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public void m213KQgRr5e_0(T t) {
        if (this.f366KQgRr5e_0.containsKey(t)) {
            return;
        }
        this.f366KQgRr5e_0.put(t, null);
    }

    public List<T> QxJ9d_1(T t) {
        int size = this.f366KQgRr5e_0.size();
        ArrayList arrayList = null;
        for (int i = 0; i < size; i++) {
            ArrayList<T> PGPF6hQ_2 = this.f366KQgRr5e_0.PGPF6hQ_2(i);
            if (PGPF6hQ_2 != null && PGPF6hQ_2.contains(t)) {
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                arrayList.add(this.f366KQgRr5e_0.KQgRr5e_0(i));
            }
        }
        return arrayList;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public boolean m214KQgRr5e_0(T t) {
        return this.f366KQgRr5e_0.containsKey(t);
    }

    public void KQgRr5e_0(T t, T t2) {
        if (this.f366KQgRr5e_0.containsKey(t) && this.f366KQgRr5e_0.containsKey(t2)) {
            ArrayList<T> arrayList = this.f366KQgRr5e_0.get(t);
            if (arrayList == null) {
                arrayList = KQgRr5e_0();
                this.f366KQgRr5e_0.put(t, arrayList);
            }
            arrayList.add(t2);
            return;
        }
        throw new IllegalArgumentException("All nodes must be present in the graph before being added as an edge");
    }

    /* renamed from: QxJ9d_1  reason: collision with other method in class */
    public boolean m215QxJ9d_1(T t) {
        int size = this.f366KQgRr5e_0.size();
        for (int i = 0; i < size; i++) {
            ArrayList<T> PGPF6hQ_2 = this.f366KQgRr5e_0.PGPF6hQ_2(i);
            if (PGPF6hQ_2 != null && PGPF6hQ_2.contains(t)) {
                return true;
            }
        }
        return false;
    }

    public ArrayList<T> QxJ9d_1() {
        this.f367KQgRr5e_0.clear();
        this.f368KQgRr5e_0.clear();
        int size = this.f366KQgRr5e_0.size();
        for (int i = 0; i < size; i++) {
            KQgRr5e_0(this.f366KQgRr5e_0.KQgRr5e_0(i), this.f367KQgRr5e_0, this.f368KQgRr5e_0);
        }
        return this.f367KQgRr5e_0;
    }

    public List KQgRr5e_0(T t) {
        return this.f366KQgRr5e_0.get(t);
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public void m212KQgRr5e_0() {
        int size = this.f366KQgRr5e_0.size();
        for (int i = 0; i < size; i++) {
            ArrayList<T> PGPF6hQ_2 = this.f366KQgRr5e_0.PGPF6hQ_2(i);
            if (PGPF6hQ_2 != null) {
                KQgRr5e_0((ArrayList) PGPF6hQ_2);
            }
        }
        this.f366KQgRr5e_0.clear();
    }

    public final void KQgRr5e_0(T t, ArrayList<T> arrayList, HashSet<T> hashSet) {
        if (arrayList.contains(t)) {
            return;
        }
        if (!hashSet.contains(t)) {
            hashSet.add(t);
            ArrayList<T> arrayList2 = this.f366KQgRr5e_0.get(t);
            if (arrayList2 != null) {
                int size = arrayList2.size();
                for (int i = 0; i < size; i++) {
                    KQgRr5e_0(arrayList2.get(i), arrayList, hashSet);
                }
            }
            hashSet.remove(t);
            arrayList.add(t);
            return;
        }
        throw new RuntimeException("This graph contains cyclic dependencies");
    }

    public final ArrayList<T> KQgRr5e_0() {
        ArrayList<T> KQgRr5e_0 = this.KQgRr5e_0.KQgRr5e_0();
        return KQgRr5e_0 == null ? new ArrayList<>() : KQgRr5e_0;
    }

    public final void KQgRr5e_0(ArrayList<T> arrayList) {
        arrayList.clear();
        this.KQgRr5e_0.KQgRr5e_0(arrayList);
    }
}
