package v0;

import C3.W;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import x0.AbstractC1709a;

/* JADX INFO: renamed from: v0.d, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1665d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final W f18011a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ArrayList f18012b = new ArrayList();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public ByteBuffer[] f18013c = new ByteBuffer[0];

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f18014d;

    public C1665d(W w4) {
        this.f18011a = w4;
        C1666e c1666e = C1666e.f18015e;
        this.f18014d = false;
    }

    public final C1666e a(C1666e c1666e) {
        if (c1666e.equals(C1666e.f18015e)) {
            throw new C1667f(c1666e);
        }
        int i = 0;
        while (true) {
            W w4 = this.f18011a;
            if (i >= w4.f1227t) {
                return c1666e;
            }
            InterfaceC1668g interfaceC1668g = (InterfaceC1668g) w4.get(i);
            C1666e c1666eF = interfaceC1668g.f(c1666e);
            if (interfaceC1668g.a()) {
                AbstractC1709a.j(!c1666eF.equals(C1666e.f18015e));
                c1666e = c1666eF;
            }
            i++;
        }
    }

    public final void b() {
        ArrayList arrayList = this.f18012b;
        arrayList.clear();
        this.f18014d = false;
        int i = 0;
        while (true) {
            W w4 = this.f18011a;
            if (i >= w4.f1227t) {
                break;
            }
            InterfaceC1668g interfaceC1668g = (InterfaceC1668g) w4.get(i);
            interfaceC1668g.flush();
            if (interfaceC1668g.a()) {
                arrayList.add(interfaceC1668g);
            }
            i++;
        }
        this.f18013c = new ByteBuffer[arrayList.size()];
        for (int i5 = 0; i5 <= c(); i5++) {
            this.f18013c[i5] = ((InterfaceC1668g) arrayList.get(i5)).b();
        }
    }

    public final int c() {
        return this.f18013c.length - 1;
    }

    public final boolean d() {
        return this.f18014d && ((InterfaceC1668g) this.f18012b.get(c())).d() && !this.f18013c[c()].hasRemaining();
    }

    public final boolean e() {
        return !this.f18012b.isEmpty();
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof C1665d) {
            C1665d c1665d = (C1665d) obj;
            W w4 = this.f18011a;
            if (w4.f1227t == c1665d.f18011a.f1227t) {
                for (int i = 0; i < w4.f1227t; i++) {
                    if (w4.get(i) == c1665d.f18011a.get(i)) {
                    }
                }
                return true;
            }
        }
        return false;
    }

    public final void f(ByteBuffer byteBuffer) {
        boolean z8;
        for (boolean z9 = true; z9; z9 = z8) {
            z8 = false;
            int i = 0;
            while (i <= c()) {
                if (!this.f18013c[i].hasRemaining()) {
                    ArrayList arrayList = this.f18012b;
                    InterfaceC1668g interfaceC1668g = (InterfaceC1668g) arrayList.get(i);
                    if (!interfaceC1668g.d()) {
                        ByteBuffer byteBuffer2 = i > 0 ? this.f18013c[i - 1] : byteBuffer.hasRemaining() ? byteBuffer : InterfaceC1668g.f18020a;
                        long jRemaining = byteBuffer2.remaining();
                        interfaceC1668g.e(byteBuffer2);
                        this.f18013c[i] = interfaceC1668g.b();
                        z8 |= jRemaining - ((long) byteBuffer2.remaining()) > 0 || this.f18013c[i].hasRemaining();
                    } else if (!this.f18013c[i].hasRemaining() && i < c()) {
                        ((InterfaceC1668g) arrayList.get(i + 1)).c();
                    }
                }
                i++;
            }
        }
    }

    public final int hashCode() {
        return this.f18011a.hashCode();
    }
}
