package com.google.protobuf;

import com.google.protobuf.d0;
import com.google.protobuf.r0;
import com.google.protobuf.u1;
import com.google.protobuf.z;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/* loaded from: classes3.dex */
final class t {

    /* renamed from: d, reason: collision with root package name */
    private static final t f15193d = new t(true);

    /* renamed from: a, reason: collision with root package name */
    private final k1 f15194a;

    /* renamed from: b, reason: collision with root package name */
    private boolean f15195b;

    /* renamed from: c, reason: collision with root package name */
    private boolean f15196c;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public static /* synthetic */ class a {

        /* renamed from: a, reason: collision with root package name */
        static final /* synthetic */ int[] f15197a;

        /* renamed from: b, reason: collision with root package name */
        static final /* synthetic */ int[] f15198b;

        static {
            int[] iArr = new int[u1.b.values().length];
            f15198b = iArr;
            try {
                iArr[u1.b.DOUBLE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f15198b[u1.b.FLOAT.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f15198b[u1.b.INT64.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                f15198b[u1.b.UINT64.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                f15198b[u1.b.INT32.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                f15198b[u1.b.FIXED64.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                f15198b[u1.b.FIXED32.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                f15198b[u1.b.BOOL.ordinal()] = 8;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                f15198b[u1.b.GROUP.ordinal()] = 9;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                f15198b[u1.b.MESSAGE.ordinal()] = 10;
            } catch (NoSuchFieldError unused10) {
            }
            try {
                f15198b[u1.b.STRING.ordinal()] = 11;
            } catch (NoSuchFieldError unused11) {
            }
            try {
                f15198b[u1.b.BYTES.ordinal()] = 12;
            } catch (NoSuchFieldError unused12) {
            }
            try {
                f15198b[u1.b.UINT32.ordinal()] = 13;
            } catch (NoSuchFieldError unused13) {
            }
            try {
                f15198b[u1.b.SFIXED32.ordinal()] = 14;
            } catch (NoSuchFieldError unused14) {
            }
            try {
                f15198b[u1.b.SFIXED64.ordinal()] = 15;
            } catch (NoSuchFieldError unused15) {
            }
            try {
                f15198b[u1.b.SINT32.ordinal()] = 16;
            } catch (NoSuchFieldError unused16) {
            }
            try {
                f15198b[u1.b.SINT64.ordinal()] = 17;
            } catch (NoSuchFieldError unused17) {
            }
            try {
                f15198b[u1.b.ENUM.ordinal()] = 18;
            } catch (NoSuchFieldError unused18) {
            }
            int[] iArr2 = new int[u1.c.values().length];
            f15197a = iArr2;
            try {
                iArr2[u1.c.INT.ordinal()] = 1;
            } catch (NoSuchFieldError unused19) {
            }
            try {
                f15197a[u1.c.LONG.ordinal()] = 2;
            } catch (NoSuchFieldError unused20) {
            }
            try {
                f15197a[u1.c.FLOAT.ordinal()] = 3;
            } catch (NoSuchFieldError unused21) {
            }
            try {
                f15197a[u1.c.DOUBLE.ordinal()] = 4;
            } catch (NoSuchFieldError unused22) {
            }
            try {
                f15197a[u1.c.BOOLEAN.ordinal()] = 5;
            } catch (NoSuchFieldError unused23) {
            }
            try {
                f15197a[u1.c.STRING.ordinal()] = 6;
            } catch (NoSuchFieldError unused24) {
            }
            try {
                f15197a[u1.c.BYTE_STRING.ordinal()] = 7;
            } catch (NoSuchFieldError unused25) {
            }
            try {
                f15197a[u1.c.ENUM.ordinal()] = 8;
            } catch (NoSuchFieldError unused26) {
            }
            try {
                f15197a[u1.c.MESSAGE.ordinal()] = 9;
            } catch (NoSuchFieldError unused27) {
            }
        }
    }

    /* loaded from: classes3.dex */
    public interface b extends Comparable {
        boolean b();

        u1.b c();

        int getNumber();

        u1.c h();

        boolean isPacked();

        r0.a k(r0.a aVar, r0 r0Var);
    }

    private t() {
        this.f15194a = k1.A(16);
    }

    private static Object c(Object obj) {
        if (!(obj instanceof byte[])) {
            return obj;
        }
        byte[] bArr = (byte[]) obj;
        byte[] bArr2 = new byte[bArr.length];
        System.arraycopy(bArr, 0, bArr2, 0, bArr.length);
        return bArr2;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static int d(u1.b bVar, int i10, Object obj) {
        int S = k.S(i10);
        if (bVar == u1.b.GROUP) {
            S *= 2;
        }
        return S + e(bVar, obj);
    }

    static int e(u1.b bVar, Object obj) {
        switch (a.f15198b[bVar.ordinal()]) {
            case 1:
                return k.k(((Double) obj).doubleValue());
            case 2:
                return k.s(((Float) obj).floatValue());
            case 3:
                return k.z(((Long) obj).longValue());
            case 4:
                return k.W(((Long) obj).longValue());
            case 5:
                return k.x(((Integer) obj).intValue());
            case 6:
                return k.q(((Long) obj).longValue());
            case 7:
                return k.o(((Integer) obj).intValue());
            case 8:
                return k.f(((Boolean) obj).booleanValue());
            case 9:
                return k.u((r0) obj);
            case 10:
                return k.E((r0) obj);
            case 11:
                return obj instanceof h ? k.i((h) obj) : k.R((String) obj);
            case 12:
                return obj instanceof h ? k.i((h) obj) : k.g((byte[]) obj);
            case 13:
                return k.U(((Integer) obj).intValue());
            case 14:
                return k.J(((Integer) obj).intValue());
            case 15:
                return k.L(((Long) obj).longValue());
            case 16:
                return k.N(((Integer) obj).intValue());
            case 17:
                return k.P(((Long) obj).longValue());
            case 18:
                return obj instanceof z.c ? k.m(((z.c) obj).getNumber()) : k.m(((Integer) obj).intValue());
            default:
                throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
        }
    }

    public static int f(b bVar, Object obj) {
        u1.b c10 = bVar.c();
        int number = bVar.getNumber();
        if (!bVar.b()) {
            return d(c10, number, obj);
        }
        List list = (List) obj;
        int i10 = 0;
        if (!bVar.isPacked()) {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                i10 += d(c10, number, it.next());
            }
            return i10;
        }
        if (list.isEmpty()) {
            return 0;
        }
        Iterator it2 = list.iterator();
        while (it2.hasNext()) {
            i10 += e(c10, it2.next());
        }
        return k.S(number) + i10 + k.U(i10);
    }

    private int j(Map.Entry entry) {
        b bVar = (b) entry.getKey();
        Object value = entry.getValue();
        return (bVar.h() != u1.c.MESSAGE || bVar.b() || bVar.isPacked()) ? f(bVar, value) : k.B(((b) entry.getKey()).getNumber(), (r0) value);
    }

    static int l(u1.b bVar, boolean z10) {
        if (z10) {
            return 2;
        }
        return bVar.getWireType();
    }

    private static boolean o(Map.Entry entry) {
        b bVar = (b) entry.getKey();
        if (bVar.h() != u1.c.MESSAGE) {
            return true;
        }
        if (!bVar.b()) {
            return p(entry.getValue());
        }
        Iterator it = ((List) entry.getValue()).iterator();
        while (it.hasNext()) {
            if (!p(it.next())) {
                return false;
            }
        }
        return true;
    }

    private static boolean p(Object obj) {
        if (obj instanceof s0) {
            return ((s0) obj).isInitialized();
        }
        throw new IllegalArgumentException("Wrong object type used with protocol message reflection.");
    }

    private static boolean q(u1.b bVar, Object obj) {
        z.a(obj);
        switch (a.f15197a[bVar.getJavaType().ordinal()]) {
            case 1:
                return obj instanceof Integer;
            case 2:
                return obj instanceof Long;
            case 3:
                return obj instanceof Float;
            case 4:
                return obj instanceof Double;
            case 5:
                return obj instanceof Boolean;
            case 6:
                return obj instanceof String;
            case 7:
                return (obj instanceof h) || (obj instanceof byte[]);
            case 8:
                return (obj instanceof Integer) || (obj instanceof z.c);
            case 9:
                return obj instanceof r0;
            default:
                return false;
        }
    }

    private void u(Map.Entry entry) {
        b bVar = (b) entry.getKey();
        Object value = entry.getValue();
        if (bVar.b()) {
            Object h10 = h(bVar);
            if (h10 == null) {
                h10 = new ArrayList();
            }
            Iterator it = ((List) value).iterator();
            while (it.hasNext()) {
                ((List) h10).add(c(it.next()));
            }
            this.f15194a.B(bVar, h10);
            return;
        }
        if (bVar.h() != u1.c.MESSAGE) {
            this.f15194a.B(bVar, c(value));
            return;
        }
        Object h11 = h(bVar);
        if (h11 == null) {
            this.f15194a.B(bVar, c(value));
        } else {
            this.f15194a.B(bVar, bVar.k(((r0) h11).toBuilder(), (r0) value).build());
        }
    }

    public static t v() {
        return new t();
    }

    private void x(b bVar, Object obj) {
        if (!q(bVar.c(), obj)) {
            throw new IllegalArgumentException(String.format("Wrong object type used with protocol message reflection.\nField number: %d, field java type: %s, value type: %s\n", Integer.valueOf(bVar.getNumber()), bVar.c().getJavaType(), obj.getClass().getName()));
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void y(k kVar, u1.b bVar, int i10, Object obj) {
        if (bVar == u1.b.GROUP) {
            kVar.x0(i10, (r0) obj);
        } else {
            kVar.T0(i10, l(bVar, false));
            z(kVar, bVar, obj);
        }
    }

    static void z(k kVar, u1.b bVar, Object obj) {
        switch (a.f15198b[bVar.ordinal()]) {
            case 1:
                kVar.o0(((Double) obj).doubleValue());
                return;
            case 2:
                kVar.w0(((Float) obj).floatValue());
                return;
            case 3:
                kVar.E0(((Long) obj).longValue());
                return;
            case 4:
                kVar.X0(((Long) obj).longValue());
                return;
            case 5:
                kVar.C0(((Integer) obj).intValue());
                return;
            case 6:
                kVar.u0(((Long) obj).longValue());
                return;
            case 7:
                kVar.s0(((Integer) obj).intValue());
                return;
            case 8:
                kVar.i0(((Boolean) obj).booleanValue());
                return;
            case 9:
                kVar.z0((r0) obj);
                return;
            case 10:
                kVar.G0((r0) obj);
                return;
            case 11:
                if (obj instanceof h) {
                    kVar.m0((h) obj);
                    return;
                } else {
                    kVar.S0((String) obj);
                    return;
                }
            case 12:
                if (obj instanceof h) {
                    kVar.m0((h) obj);
                    return;
                } else {
                    kVar.j0((byte[]) obj);
                    return;
                }
            case 13:
                kVar.V0(((Integer) obj).intValue());
                return;
            case 14:
                kVar.K0(((Integer) obj).intValue());
                return;
            case 15:
                kVar.M0(((Long) obj).longValue());
                return;
            case 16:
                kVar.O0(((Integer) obj).intValue());
                return;
            case 17:
                kVar.Q0(((Long) obj).longValue());
                return;
            case 18:
                if (obj instanceof z.c) {
                    kVar.q0(((z.c) obj).getNumber());
                    return;
                } else {
                    kVar.q0(((Integer) obj).intValue());
                    return;
                }
            default:
                return;
        }
    }

    public void a(b bVar, Object obj) {
        List list;
        if (!bVar.b()) {
            throw new IllegalArgumentException("addRepeatedField() can only be called on repeated fields.");
        }
        x(bVar, obj);
        Object h10 = h(bVar);
        if (h10 == null) {
            list = new ArrayList();
            this.f15194a.B(bVar, list);
        } else {
            list = (List) h10;
        }
        list.add(obj);
    }

    /* renamed from: b, reason: merged with bridge method [inline-methods] */
    public t clone() {
        t v10 = v();
        for (int i10 = 0; i10 < this.f15194a.p(); i10++) {
            Map.Entry m10 = this.f15194a.m(i10);
            v10.w((b) m10.getKey(), m10.getValue());
        }
        for (Map.Entry entry : this.f15194a.t()) {
            v10.w((b) entry.getKey(), entry.getValue());
        }
        v10.f15196c = this.f15196c;
        return v10;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof t) {
            return this.f15194a.equals(((t) obj).f15194a);
        }
        return false;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Iterator g() {
        return this.f15196c ? new d0.b(this.f15194a.h().iterator()) : this.f15194a.h().iterator();
    }

    public Object h(b bVar) {
        return this.f15194a.get(bVar);
    }

    public int hashCode() {
        return this.f15194a.hashCode();
    }

    public int i() {
        int i10 = 0;
        for (int i11 = 0; i11 < this.f15194a.p(); i11++) {
            i10 += j(this.f15194a.m(i11));
        }
        Iterator it = this.f15194a.t().iterator();
        while (it.hasNext()) {
            i10 += j((Map.Entry) it.next());
        }
        return i10;
    }

    public int k() {
        int i10 = 0;
        for (int i11 = 0; i11 < this.f15194a.p(); i11++) {
            Map.Entry m10 = this.f15194a.m(i11);
            i10 += f((b) m10.getKey(), m10.getValue());
        }
        for (Map.Entry entry : this.f15194a.t()) {
            i10 += f((b) entry.getKey(), entry.getValue());
        }
        return i10;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean m() {
        return this.f15194a.isEmpty();
    }

    public boolean n() {
        for (int i10 = 0; i10 < this.f15194a.p(); i10++) {
            if (!o(this.f15194a.m(i10))) {
                return false;
            }
        }
        Iterator it = this.f15194a.t().iterator();
        while (it.hasNext()) {
            if (!o((Map.Entry) it.next())) {
                return false;
            }
        }
        return true;
    }

    public Iterator r() {
        return this.f15196c ? new d0.b(this.f15194a.entrySet().iterator()) : this.f15194a.entrySet().iterator();
    }

    public void s() {
        if (this.f15195b) {
            return;
        }
        for (int i10 = 0; i10 < this.f15194a.p(); i10++) {
            Map.Entry m10 = this.f15194a.m(i10);
            if (m10.getValue() instanceof x) {
                ((x) m10.getValue()).makeImmutable();
            }
        }
        this.f15194a.z();
        this.f15195b = true;
    }

    public void t(t tVar) {
        for (int i10 = 0; i10 < tVar.f15194a.p(); i10++) {
            u(tVar.f15194a.m(i10));
        }
        Iterator it = tVar.f15194a.t().iterator();
        while (it.hasNext()) {
            u((Map.Entry) it.next());
        }
    }

    public void w(b bVar, Object obj) {
        if (!bVar.b()) {
            x(bVar, obj);
        } else {
            if (!(obj instanceof List)) {
                throw new IllegalArgumentException("Wrong object type used with protocol message reflection.");
            }
            ArrayList arrayList = new ArrayList();
            arrayList.addAll((List) obj);
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                x(bVar, it.next());
            }
            obj = arrayList;
        }
        this.f15194a.B(bVar, obj);
    }

    private t(boolean z10) {
        this(k1.A(0));
        s();
    }

    private t(k1 k1Var) {
        this.f15194a = k1Var;
        s();
    }
}
