package n1;

import java.io.Serializable;
import n1.f;
import v1.p;
import w1.h;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final f f5673e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final f.b f5674f;

    /* JADX INFO: compiled from: CoroutineContextImpl.kt */
    static final class a extends h implements p<String, f.b, String> {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public static final a f5675e = new a();

        a() {
            super(2);
        }

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

    public c(f fVar, f.b bVar) {
        w1.g.e(fVar, "left");
        w1.g.e(bVar, "element");
        this.f5673e = fVar;
        this.f5674f = bVar;
    }

    private final boolean d(f.b bVar) {
        return w1.g.a(get(bVar.getKey()), bVar);
    }

    private final boolean g(c cVar) {
        while (d(cVar.f5674f)) {
            f fVar = cVar.f5673e;
            if (!(fVar instanceof c)) {
                w1.g.c(fVar, "null cannot be cast to non-null type kotlin.coroutines.CoroutineContext.Element");
                return d((f.b) fVar);
            }
            cVar = (c) fVar;
        }
        return false;
    }

    private final int j() {
        int i3 = 2;
        while (true) {
            f fVar = this.f5673e;
            this = fVar instanceof c ? (c) fVar : null;
            if (this == null) {
                return i3;
            }
            i3++;
        }
    }

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

    @Override // n1.f
    public <R> R fold(R r2, p<? super R, ? super f.b, ? extends R> pVar) {
        w1.g.e(pVar, "operation");
        return pVar.c((Object) this.f5673e.fold(r2, pVar), this.f5674f);
    }

    @Override // n1.f
    public <E extends f.b> E get(f.c<E> cVar) {
        w1.g.e(cVar, "key");
        while (true) {
            E e3 = (E) this.f5674f.get(cVar);
            if (e3 != null) {
                return e3;
            }
            f fVar = this.f5673e;
            if (!(fVar instanceof c)) {
                return (E) fVar.get(cVar);
            }
            this = (c) fVar;
        }
    }

    public int hashCode() {
        return this.f5673e.hashCode() + this.f5674f.hashCode();
    }

    @Override // n1.f
    public f minusKey(f.c<?> cVar) {
        w1.g.e(cVar, "key");
        if (this.f5674f.get(cVar) != null) {
            return this.f5673e;
        }
        f fVarMinusKey = this.f5673e.minusKey(cVar);
        return fVarMinusKey == this.f5673e ? this : fVarMinusKey == g.f5679e ? this.f5674f : new c(fVarMinusKey, this.f5674f);
    }

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