package h.u;

import h.u.g;
import h.x.c.p;
import h.x.d.k;
import h.x.d.l;
import java.io.Serializable;

/* JADX INFO: compiled from: CoroutineContextImpl.kt */
/* JADX INFO: loaded from: classes.dex */
public final class c implements g, Serializable {
    private final g b;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final g.b f972e;

    /* JADX INFO: compiled from: CoroutineContextImpl.kt */
    static final class a extends l implements p<String, g.b, String> {
        public static final a b = new a();

        a() {
            super(2);
        }

        @Override // h.x.c.p
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public final String a(String str, g.b bVar) {
            k.d(str, "acc");
            k.d(bVar, "element");
            if (str.length() == 0) {
                return bVar.toString();
            }
            return str + ", " + bVar;
        }
    }

    public c(g gVar, g.b bVar) {
        k.d(gVar, "left");
        k.d(bVar, "element");
        this.b = gVar;
        this.f972e = bVar;
    }

    private final boolean c(g.b bVar) {
        return k.a(b(bVar.getKey()), bVar);
    }

    private final boolean e(c cVar) {
        while (c(cVar.f972e)) {
            g gVar = cVar.b;
            if (!(gVar instanceof c)) {
                return c((g.b) gVar);
            }
            cVar = (c) gVar;
        }
        return false;
    }

    private final int f() {
        int i2 = 2;
        c cVar = this;
        while (true) {
            g gVar = cVar.b;
            cVar = gVar instanceof c ? (c) gVar : null;
            if (cVar == null) {
                return i2;
            }
            i2++;
        }
    }

    @Override // h.u.g
    public g A(g.c<?> cVar) {
        k.d(cVar, "key");
        if (this.f972e.b(cVar) != null) {
            return this.b;
        }
        g gVarA = this.b.A(cVar);
        return gVarA == this.b ? this : gVarA == h.b ? this.f972e : new c(gVarA, this.f972e);
    }

    @Override // h.u.g
    public <E extends g.b> E b(g.c<E> cVar) {
        k.d(cVar, "key");
        c cVar2 = this;
        while (true) {
            E e2 = (E) cVar2.f972e.b(cVar);
            if (e2 != null) {
                return e2;
            }
            g gVar = cVar2.b;
            if (!(gVar instanceof c)) {
                return (E) gVar.b(cVar);
            }
            cVar2 = (c) gVar;
        }
    }

    public boolean equals(Object obj) {
        if (this != obj) {
            if (obj instanceof c) {
                c cVar = (c) obj;
                if (cVar.f() != f() || !cVar.e(this)) {
                }
            }
            return false;
        }
        return true;
    }

    public int hashCode() {
        return this.b.hashCode() + this.f972e.hashCode();
    }

    @Override // h.u.g
    public g j(g gVar) {
        return g.a.a(this, gVar);
    }

    @Override // h.u.g
    public <R> R t(R r, p<? super R, ? super g.b, ? extends R> pVar) {
        k.d(pVar, "operation");
        return pVar.a((Object) this.b.t(r, pVar), this.f972e);
    }

    public String toString() {
        return '[' + ((String) t("", a.b)) + ']';
    }
}
