package com.google.protobuf;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;

/* JADX INFO: renamed from: com.google.protobuf.n, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC1320n implements Iterable, Serializable {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final C1318m f14310b = new C1318m(Z.f14235b);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final C1314k f14311c;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f14312a = 0;

    static {
        f14311c = AbstractC1302e.a() ? new C1314k(1) : new C1314k(0);
    }

    public static AbstractC1320n g(Iterator it, int i6) {
        if (i6 < 1) {
            throw new IllegalArgumentException(Z0.o.j(i6, "length (", ") must be >= 1"));
        }
        if (i6 == 1) {
            return (AbstractC1320n) it.next();
        }
        int i7 = i6 >>> 1;
        AbstractC1320n abstractC1320nG = g(it, i7);
        AbstractC1320n abstractC1320nG2 = g(it, i6 - i7);
        if (Integer.MAX_VALUE - abstractC1320nG.size() < abstractC1320nG2.size()) {
            throw new IllegalArgumentException("ByteString would be too long: " + abstractC1320nG.size() + "+" + abstractC1320nG2.size());
        }
        if (abstractC1320nG2.size() == 0) {
            return abstractC1320nG;
        }
        if (abstractC1320nG.size() == 0) {
            return abstractC1320nG2;
        }
        int size = abstractC1320nG2.size() + abstractC1320nG.size();
        if (size < 128) {
            int size2 = abstractC1320nG.size();
            int size3 = abstractC1320nG2.size();
            int i8 = size2 + size3;
            byte[] bArr = new byte[i8];
            k(0, size2, abstractC1320nG.size());
            k(0, size2, i8);
            if (size2 > 0) {
                abstractC1320nG.n(0, 0, size2, bArr);
            }
            k(0, size3, abstractC1320nG2.size());
            k(size2, i8, i8);
            if (size3 > 0) {
                abstractC1320nG2.n(0, size2, size3, bArr);
            }
            return new C1318m(bArr);
        }
        if (abstractC1320nG instanceof I0) {
            I0 i02 = (I0) abstractC1320nG;
            AbstractC1320n abstractC1320n = i02.f14195f;
            int size4 = abstractC1320nG2.size() + abstractC1320n.size();
            AbstractC1320n abstractC1320n2 = i02.f14194e;
            if (size4 < 128) {
                int size5 = abstractC1320n.size();
                int size6 = abstractC1320nG2.size();
                int i9 = size5 + size6;
                byte[] bArr2 = new byte[i9];
                k(0, size5, abstractC1320n.size());
                k(0, size5, i9);
                if (size5 > 0) {
                    abstractC1320n.n(0, 0, size5, bArr2);
                }
                k(0, size6, abstractC1320nG2.size());
                k(size5, i9, i9);
                if (size6 > 0) {
                    abstractC1320nG2.n(0, size5, size6, bArr2);
                }
                return new I0(abstractC1320n2, new C1318m(bArr2));
            }
            if (abstractC1320n2.o() > abstractC1320n.o()) {
                if (i02.f14197k > abstractC1320nG2.o()) {
                    return new I0(abstractC1320n2, new I0(abstractC1320n, abstractC1320nG2));
                }
            }
        }
        if (size >= I0.B(Math.max(abstractC1320nG.o(), abstractC1320nG2.o()) + 1)) {
            return new I0(abstractC1320nG, abstractC1320nG2);
        }
        C1317l0 c1317l0 = new C1317l0(2);
        c1317l0.a(abstractC1320nG);
        c1317l0.a(abstractC1320nG2);
        ArrayDeque arrayDeque = (ArrayDeque) c1317l0.f14296a;
        AbstractC1320n i03 = (AbstractC1320n) arrayDeque.pop();
        while (!arrayDeque.isEmpty()) {
            i03 = new I0((AbstractC1320n) arrayDeque.pop(), i03);
        }
        return i03;
    }

    public static void j(int i6, int i7) {
        if (((i7 - (i6 + 1)) | i6) < 0) {
            if (i6 >= 0) {
                throw new ArrayIndexOutOfBoundsException(com.google.android.recaptcha.internal.a.i(i6, i7, "Index > length: ", ", "));
            }
            throw new ArrayIndexOutOfBoundsException(Z0.o.l("Index < 0: ", i6));
        }
    }

    public static int k(int i6, int i7, int i8) {
        int i9 = i7 - i6;
        if ((i6 | i7 | i9 | (i8 - i7)) >= 0) {
            return i9;
        }
        if (i6 < 0) {
            throw new IndexOutOfBoundsException(Z0.o.j(i6, "Beginning index: ", " < 0"));
        }
        if (i7 < i6) {
            throw new IndexOutOfBoundsException(com.google.android.recaptcha.internal.a.i(i6, i7, "Beginning index larger than ending index: ", ", "));
        }
        throw new IndexOutOfBoundsException(com.google.android.recaptcha.internal.a.i(i7, i8, "End index: ", " >= "));
    }

    public static C1318m l(byte[] bArr, int i6, int i7) {
        byte[] bArrCopyOfRange;
        k(i6, i6 + i7, bArr.length);
        switch (f14311c.f14285a) {
            case 0:
                bArrCopyOfRange = Arrays.copyOfRange(bArr, i6, i7 + i6);
                break;
            default:
                bArrCopyOfRange = new byte[i7];
                System.arraycopy(bArr, i6, bArrCopyOfRange, 0, i7);
                break;
        }
        return new C1318m(bArrCopyOfRange);
    }

    public static C1318m m(String str) {
        return new C1318m(str.getBytes(Z.f14234a));
    }

    public abstract void A(AbstractC1335v abstractC1335v);

    public abstract ByteBuffer e();

    public abstract boolean equals(Object obj);

    public abstract byte h(int i6);

    public final int hashCode() {
        int iU = this.f14312a;
        if (iU == 0) {
            int size = size();
            iU = u(size, 0, size);
            if (iU == 0) {
                iU = 1;
            }
            this.f14312a = iU;
        }
        return iU;
    }

    public final boolean isEmpty() {
        return size() == 0;
    }

    public abstract void n(int i6, int i7, int i8, byte[] bArr);

    public abstract int o();

    public abstract byte p(int i6);

    public abstract boolean q();

    public abstract boolean r();

    public abstract AbstractC1329s s();

    public abstract int size();

    public final String toString() {
        String strR;
        Locale locale = Locale.ROOT;
        String hexString = Integer.toHexString(System.identityHashCode(this));
        int size = size();
        if (size() <= 50) {
            strR = O0.r(this);
        } else {
            strR = O0.r(w(0, 47)) + "...";
        }
        return com.google.android.recaptcha.internal.a.n(Z0.o.s(size, "<ByteString@", hexString, " size=", " contents=\""), strR, "\">");
    }

    public abstract int u(int i6, int i7, int i8);

    public abstract int v(int i6, int i7, int i8);

    public abstract AbstractC1320n w(int i6, int i7);

    public final byte[] x() {
        int size = size();
        if (size == 0) {
            return Z.f14235b;
        }
        byte[] bArr = new byte[size];
        n(0, 0, size, bArr);
        return bArr;
    }

    public abstract String y(Charset charset);

    public final String z() {
        return size() == 0 ? "" : y(Z.f14234a);
    }
}
