package com.google.android.gms.internal.measurement;

import androidx.datastore.preferences.protobuf.C0426d;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Locale;

/* JADX INFO: loaded from: classes.dex */
public class S1 implements Iterable, Serializable {

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public static final S1 f9671s = new S1(AbstractC0644h2.f9869b);

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

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final byte[] f9673r;

    static {
        int i = O1.f9656a;
    }

    public S1(byte[] bArr) {
        bArr.getClass();
        this.f9673r = bArr;
    }

    public static int f(int i, int i5, int i8) {
        int i9 = i5 - i;
        if ((i | i5 | i9 | (i8 - i5)) >= 0) {
            return i9;
        }
        if (i < 0) {
            throw new IndexOutOfBoundsException(I1.a.k(i, "Beginning index: ", " < 0"));
        }
        if (i5 < i) {
            throw new IndexOutOfBoundsException(I1.a.o("Beginning index larger than ending index: ", i, i5, ", "));
        }
        throw new IndexOutOfBoundsException(I1.a.o("End index: ", i5, i8, " >= "));
    }

    public static S1 g(byte[] bArr, int i, int i5) {
        f(i, i + i5, bArr.length);
        byte[] bArr2 = new byte[i5];
        System.arraycopy(bArr, i, bArr2, 0, i5);
        return new S1(bArr2);
    }

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

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

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

    public final boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if ((obj instanceof S1) && c() == ((S1) obj).c()) {
            if (c() == 0) {
                return true;
            }
            if (!(obj instanceof S1)) {
                return obj.equals(this);
            }
            S1 s12 = (S1) obj;
            int i = this.f9672q;
            int i5 = s12.f9672q;
            if (i == 0 || i5 == 0 || i == i5) {
                int iC = c();
                if (iC > s12.c()) {
                    throw new IllegalArgumentException("Length too large: " + iC + c());
                }
                if (iC > s12.c()) {
                    throw new IllegalArgumentException(I1.a.o("Ran off end of other: 0, ", iC, s12.c(), ", "));
                }
                int i8 = 0;
                int i9 = 0;
                while (i8 < iC) {
                    if (this.f9673r[i8] == s12.f9673r[i9]) {
                        i8++;
                        i9++;
                    }
                }
                return true;
            }
        }
        return false;
    }

    public final int hashCode() {
        int i = this.f9672q;
        if (i != 0) {
            return i;
        }
        int iC = c();
        int i5 = iC;
        for (int i8 = 0; i8 < iC; i8++) {
            i5 = (i5 * 31) + this.f9673r[i8];
        }
        if (i5 == 0) {
            i5 = 1;
        }
        this.f9672q = i5;
        return i5;
    }

    @Override // java.lang.Iterable
    public final /* synthetic */ Iterator iterator() {
        return new C0426d(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 = s7.l.C(this);
        } else {
            int iF = f(0, 47, c());
            strConcat = s7.l.C(iF == 0 ? f9671s : new Q1(iF, this.f9673r)).concat("...");
        }
        StringBuilder sb = new StringBuilder("<ByteString@");
        sb.append(hexString);
        sb.append(" size=");
        sb.append(iC);
        sb.append(" contents=\"");
        return I1.a.r(sb, strConcat, "\">");
    }
}
