package o;

import java.io.Serializable;
import java.util.Iterator;
import java.util.Locale;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public class Ws0 implements Iterable, Serializable {
    public static final Ws0 n = new Ws0(Et0.b);
    public int l = 0;
    public final byte[] m;

    static {
        int i = Qs0.a;
    }

    public Ws0(byte[] bArr) {
        bArr.getClass();
        this.m = bArr;
    }

    public static Ws0 d(byte[] bArr, int i, int i2) {
        e(i, i + i2, bArr.length);
        byte[] bArr2 = new byte[i2];
        System.arraycopy(bArr, i, bArr2, 0, i2);
        return new Ws0(bArr2);
    }

    public static int e(int i, int i2, int i3) {
        int i4 = i2 - i;
        if ((i | i2 | i4 | (i3 - i2)) >= 0) {
            return i4;
        }
        if (i < 0) {
            StringBuilder sb = new StringBuilder(String.valueOf(i).length() + 21);
            sb.append("Beginning index: ");
            sb.append(i);
            sb.append(" < 0");
            throw new IndexOutOfBoundsException(sb.toString());
        }
        if (i2 < i) {
            StringBuilder sb2 = new StringBuilder(String.valueOf(i).length() + 44 + String.valueOf(i2).length());
            sb2.append("Beginning index larger than ending index: ");
            sb2.append(i);
            sb2.append(", ");
            sb2.append(i2);
            throw new IndexOutOfBoundsException(sb2.toString());
        }
        StringBuilder sb3 = new StringBuilder(String.valueOf(i2).length() + 15 + String.valueOf(i3).length());
        sb3.append("End index: ");
        sb3.append(i2);
        sb3.append(" >= ");
        sb3.append(i3);
        throw new IndexOutOfBoundsException(sb3.toString());
    }

    public byte a(int i) {
        return this.m[i];
    }

    public byte b(int i) {
        return this.m[i];
    }

    public int c() {
        return this.m.length;
    }

    public final boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if ((obj instanceof Ws0) && c() == ((Ws0) obj).c()) {
            if (c() == 0) {
                return true;
            }
            if (!(obj instanceof Ws0)) {
                return obj.equals(this);
            }
            Ws0 ws0 = (Ws0) obj;
            int i = this.l;
            int i2 = ws0.l;
            if (i == 0 || i2 == 0 || i == i2) {
                int iC = c();
                if (iC > ws0.c()) {
                    int iC2 = c();
                    StringBuilder sb = new StringBuilder(String.valueOf(iC).length() + 18 + String.valueOf(iC2).length());
                    sb.append("Length too large: ");
                    sb.append(iC);
                    sb.append(iC2);
                    throw new IllegalArgumentException(sb.toString());
                }
                if (iC <= ws0.c()) {
                    byte[] bArr = ws0.m;
                    int i3 = 0;
                    int i4 = 0;
                    while (i3 < iC) {
                        if (this.m[i3] == bArr[i4]) {
                            i3++;
                            i4++;
                        }
                    }
                    return true;
                }
                int iC3 = ws0.c();
                StringBuilder sb2 = new StringBuilder(String.valueOf(iC).length() + 27 + String.valueOf(iC3).length());
                sb2.append("Ran off end of other: 0, ");
                sb2.append(iC);
                sb2.append(", ");
                sb2.append(iC3);
                throw new IllegalArgumentException(sb2.toString());
            }
        }
        return false;
    }

    public final int hashCode() {
        int i = this.l;
        if (i != 0) {
            return i;
        }
        int iC = c();
        int i2 = iC;
        for (int i3 = 0; i3 < iC; i3++) {
            i2 = (i2 * 31) + this.m[i3];
        }
        if (i2 == 0) {
            i2 = 1;
        }
        this.l = i2;
        return i2;
    }

    @Override // java.lang.Iterable
    public final /* synthetic */ Iterator iterator() {
        return new C0031Bf(this);
    }

    public final String toString() {
        String strConcat;
        Locale locale = Locale.ROOT;
        String hexString = Integer.toHexString(System.identityHashCode(this));
        int iC = c();
        if (c() <= 50) {
            strConcat = AbstractC0752ap.m0(this);
        } else {
            int iE = e(0, 47, c());
            strConcat = AbstractC0752ap.m0(iE == 0 ? n : new Us0(iE, this.m)).concat("...");
        }
        StringBuilder sb = new StringBuilder("<ByteString@");
        sb.append(hexString);
        sb.append(" size=");
        sb.append(iC);
        sb.append(" contents=\"");
        return AbstractC2462sn.n(sb, strConcat, "\">");
    }
}
