package defpackage;

import androidx.media3.exoplayer.rtsp.SessionDescription;
import defpackage.e95;
import defpackage.xw8;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
public class ft implements e95.a {
    public final a d;
    public xw8 a = null;
    public float b = 0.0f;
    public final ArrayList c = new ArrayList();
    public boolean e = false;

    public interface a {
        boolean a(xw8 xw8Var);

        xw8 b(int i);

        void c();

        void clear();

        float d(ft ftVar, boolean z);

        float e(xw8 xw8Var);

        int f();

        void g(xw8 xw8Var, float f, boolean z);

        float h(int i);

        float i(xw8 xw8Var, boolean z);

        void j(float f);

        void k(xw8 xw8Var, float f);
    }

    public ft(nq0 nq0Var) {
        this.d = new ns(this, nq0Var);
    }

    @Override // e95.a
    public xw8 a(boolean[] zArr) {
        return f(zArr, null);
    }

    public final void b(e95 e95Var, int i) {
        this.d.k(e95Var.j(i), 1.0f);
        this.d.k(e95Var.j(i), -1.0f);
    }

    public final void c(xw8 xw8Var, xw8 xw8Var2, xw8 xw8Var3, int i) {
        boolean z = false;
        if (i != 0) {
            if (i < 0) {
                i *= -1;
                z = true;
            }
            this.b = i;
        }
        if (z) {
            this.d.k(xw8Var, 1.0f);
            this.d.k(xw8Var2, -1.0f);
            this.d.k(xw8Var3, -1.0f);
        } else {
            this.d.k(xw8Var, -1.0f);
            this.d.k(xw8Var2, 1.0f);
            this.d.k(xw8Var3, 1.0f);
        }
    }

    public final void d(xw8 xw8Var, xw8 xw8Var2, xw8 xw8Var3, int i) {
        boolean z = false;
        if (i != 0) {
            if (i < 0) {
                i *= -1;
                z = true;
            }
            this.b = i;
        }
        if (z) {
            this.d.k(xw8Var, 1.0f);
            this.d.k(xw8Var2, -1.0f);
            this.d.k(xw8Var3, 1.0f);
        } else {
            this.d.k(xw8Var, -1.0f);
            this.d.k(xw8Var2, 1.0f);
            this.d.k(xw8Var3, -1.0f);
        }
    }

    public boolean e() {
        return this.a == null && this.b == 0.0f && this.d.f() == 0;
    }

    public final xw8 f(boolean[] zArr, xw8 xw8Var) {
        xw8.b bVar;
        int iF = this.d.f();
        xw8 xw8Var2 = null;
        float f = 0.0f;
        for (int i = 0; i < iF; i++) {
            float fH = this.d.h(i);
            if (fH < 0.0f) {
                xw8 xw8VarB = this.d.b(i);
                if ((zArr == null || !zArr[xw8VarB.b]) && xw8VarB != xw8Var && (((bVar = xw8VarB.k) == xw8.b.b || bVar == xw8.b.c) && fH < f)) {
                    f = fH;
                    xw8Var2 = xw8VarB;
                }
            }
        }
        return xw8Var2;
    }

    public final void g(xw8 xw8Var) {
        xw8 xw8Var2 = this.a;
        if (xw8Var2 != null) {
            this.d.k(xw8Var2, -1.0f);
            this.a.c = -1;
            this.a = null;
        }
        float fI = this.d.i(xw8Var, true) * (-1.0f);
        this.a = xw8Var;
        if (fI == 1.0f) {
            return;
        }
        this.b /= fI;
        this.d.j(fI);
    }

    @Override // e95.a
    public final xw8 getKey() {
        return this.a;
    }

    public final void h(e95 e95Var, xw8 xw8Var, boolean z) {
        if (xw8Var.f) {
            float fE = this.d.e(xw8Var);
            this.b = (xw8Var.e * fE) + this.b;
            this.d.i(xw8Var, z);
            if (z) {
                xw8Var.b(this);
            }
            if (this.d.f() == 0) {
                this.e = true;
                e95Var.a = true;
            }
        }
    }

    public void i(e95 e95Var, ft ftVar, boolean z) {
        float fD = this.d.d(ftVar, z);
        this.b = (ftVar.b * fD) + this.b;
        if (z) {
            ftVar.a.b(this);
        }
        if (this.a == null || this.d.f() != 0) {
            return;
        }
        this.e = true;
        e95Var.a = true;
    }

    /* JADX WARN: Removed duplicated region for block: B:29:0x007c  */
    /* JADX WARN: Removed duplicated region for block: B:30:0x0081  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public String toString() {
        boolean z;
        String strK = vw2.k(this.a == null ? SessionDescription.SUPPORTED_SDP_VERSION : "" + this.a, " = ");
        if (this.b != 0.0f) {
            StringBuilder sbQ = vw2.q(strK);
            sbQ.append(this.b);
            strK = sbQ.toString();
            z = true;
        } else {
            z = false;
        }
        int iF = this.d.f();
        for (int i = 0; i < iF; i++) {
            xw8 xw8VarB = this.d.b(i);
            if (xw8VarB != null) {
                float fH = this.d.h(i);
                if (fH != 0.0f) {
                    String string = xw8VarB.toString();
                    if (!z) {
                        if (fH < 0.0f) {
                            strK = vw2.k(strK, "- ");
                            fH *= -1.0f;
                        }
                        strK = fH == 1.0f ? vw2.k(strK, string) : strK + fH + " " + string;
                        z = true;
                    } else if (fH > 0.0f) {
                        strK = vw2.k(strK, " + ");
                        if (fH == 1.0f) {
                        }
                        z = true;
                    } else {
                        strK = vw2.k(strK, " - ");
                        fH *= -1.0f;
                        if (fH == 1.0f) {
                        }
                        z = true;
                    }
                }
            }
        }
        return !z ? vw2.k(strK, "0.0") : strK;
    }
}
