package E1;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import java.util.ArrayList;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
public final class D extends A implements Iterable, Q6.a {
    public static final /* synthetic */ int D = 0;

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final q.j f1990A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public int f1991B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public String f1992C;

    public D(E e8) {
        super(e8);
        this.f1990A = new q.j(0);
    }

    @Override // E1.A
    public final boolean equals(Object obj) {
        if (obj == null || !(obj instanceof D)) {
            return false;
        }
        q.j jVar = this.f1990A;
        W6.h hVarE = W6.j.E(q.h.d(jVar));
        ArrayList arrayList = new ArrayList();
        Iterator it = hVarE.iterator();
        while (it.hasNext()) {
            arrayList.add(it.next());
        }
        D d8 = (D) obj;
        q.j jVar2 = d8.f1990A;
        B6.b bVarD = q.h.d(jVar2);
        while (bVarD.hasNext()) {
            arrayList.remove((A) bVarD.next());
        }
        return super.equals(obj) && jVar.k() == jVar2.k() && this.f1991B == d8.f1991B && arrayList.isEmpty();
    }

    @Override // E1.A
    public final z f(A1.y yVar) {
        z zVarF = super.f(yVar);
        ArrayList arrayList = new ArrayList();
        C c3 = new C(this);
        while (c3.hasNext()) {
            z zVarF2 = ((A) c3.next()).f(yVar);
            if (zVarF2 != null) {
                arrayList.add(zVarF2);
            }
        }
        return (z) B6.k.p0(B6.j.N(new z[]{zVarF, (z) B6.k.p0(arrayList)}));
    }

    @Override // E1.A
    public final void g(Context context, AttributeSet attributeSet) {
        String strValueOf;
        super.g(context, attributeSet);
        TypedArray typedArrayObtainAttributes = context.getResources().obtainAttributes(attributeSet, F1.a.f2435d);
        P6.g.d(typedArrayObtainAttributes, "context.resources.obtain…vGraphNavigator\n        )");
        int resourceId = typedArrayObtainAttributes.getResourceId(0, 0);
        if (resourceId == this.f1985x) {
            throw new IllegalArgumentException(("Start destination " + resourceId + " cannot use the same id as the graph " + this).toString());
        }
        this.f1991B = resourceId;
        this.f1992C = null;
        if (resourceId <= 16777215) {
            strValueOf = String.valueOf(resourceId);
        } else {
            try {
                strValueOf = context.getResources().getResourceName(resourceId);
            } catch (Resources.NotFoundException unused) {
                strValueOf = String.valueOf(resourceId);
            }
            P6.g.d(strValueOf, "try {\n                co….toString()\n            }");
        }
        this.f1992C = strValueOf;
        typedArrayObtainAttributes.recycle();
    }

    public final void h(A a3) {
        P6.g.e(a3, "node");
        int i = a3.f1985x;
        String str = a3.f1986y;
        if (i == 0 && str == null) {
            throw new IllegalArgumentException("Destinations must have an id or route. Call setId(), setRoute(), or include an android:id or app:route in your navigation XML.");
        }
        String str2 = this.f1986y;
        if (str2 != null && P6.g.a(str, str2)) {
            throw new IllegalArgumentException(("Destination " + a3 + " cannot have the same route as graph " + this).toString());
        }
        if (i == this.f1985x) {
            throw new IllegalArgumentException(("Destination " + a3 + " cannot have the same id as graph " + this).toString());
        }
        q.j jVar = this.f1990A;
        A a8 = (A) jVar.f(i);
        if (a8 == a3) {
            return;
        }
        if (a3.f1979r != null) {
            throw new IllegalStateException("Destination already has a parent set. Call NavGraph.remove() to remove the previous parent.");
        }
        if (a8 != null) {
            a8.f1979r = null;
        }
        a3.f1979r = this;
        jVar.i(a3.f1985x, a3);
    }

    @Override // E1.A
    public final int hashCode() {
        int iH = this.f1991B;
        q.j jVar = this.f1990A;
        int iK = jVar.k();
        for (int i = 0; i < iK; i++) {
            iH = (((iH * 31) + jVar.h(i)) * 31) + ((A) jVar.l(i)).hashCode();
        }
        return iH;
    }

    public final A i(int i, boolean z8) {
        D d8;
        A a3 = (A) this.f1990A.f(i);
        if (a3 != null) {
            return a3;
        }
        if (!z8 || (d8 = this.f1979r) == null) {
            return null;
        }
        return d8.i(i, true);
    }

    @Override // java.lang.Iterable
    public final Iterator iterator() {
        return new C(this);
    }

    @Override // E1.A
    public final String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        A aI = i(this.f1991B, true);
        sb.append(" startDestination=");
        if (aI == null) {
            String str = this.f1992C;
            if (str != null) {
                sb.append(str);
            } else {
                sb.append("0x" + Integer.toHexString(this.f1991B));
            }
        } else {
            sb.append("{");
            sb.append(aI.toString());
            sb.append("}");
        }
        String string = sb.toString();
        P6.g.d(string, "sb.toString()");
        return string;
    }
}
