package o;

import com.google.android.gms.common.api.Api;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public abstract class DD extends U {
    private static final int MEMOIZED_SERIALIZED_SIZE_MASK = Integer.MAX_VALUE;
    private static final int MUTABLE_FLAG_MASK = Integer.MIN_VALUE;
    static final int UNINITIALIZED_HASH_CODE = 0;
    static final int UNINITIALIZED_SERIALIZED_SIZE = Integer.MAX_VALUE;
    private static Map<Object, DD> defaultInstanceMap = new ConcurrentHashMap();
    private int memoizedSerializedSize;
    protected Ph0 unknownFields;

    public DD() {
        this.memoizedHashCode = 0;
        this.memoizedSerializedSize = -1;
        this.unknownFields = Ph0.f;
    }

    public static DD d(Class cls) throws ClassNotFoundException {
        DD dd = defaultInstanceMap.get(cls);
        if (dd == null) {
            try {
                Class.forName(cls.getName(), true, cls.getClassLoader());
                dd = defaultInstanceMap.get(cls);
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException("Class initialization cannot fail.", e);
            }
        }
        if (dd != null) {
            return dd;
        }
        DD dd2 = (DD) ((DD) AbstractC0835bi0.d(cls)).c(6);
        if (dd2 == null) {
            throw new IllegalStateException();
        }
        defaultInstanceMap.put(cls, dd2);
        return dd2;
    }

    public static Object e(Method method, DD dd, Object... objArr) {
        try {
            return method.invoke(dd, objArr);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Couldn't use Java reflection to implement protocol message reflection.", e);
        } catch (InvocationTargetException e2) {
            Throwable cause = e2.getCause();
            if (cause instanceof RuntimeException) {
                throw ((RuntimeException) cause);
            }
            if (cause instanceof Error) {
                throw ((Error) cause);
            }
            throw new RuntimeException("Unexpected exception thrown by generated accessor method.", cause);
        }
    }

    public static final boolean f(DD dd, boolean z) {
        byte bByteValue = ((Byte) dd.c(1)).byteValue();
        if (bByteValue == 1) {
            return true;
        }
        if (bByteValue == 0) {
            return false;
        }
        C2530tZ c2530tZ = C2530tZ.c;
        c2530tZ.getClass();
        boolean zD = c2530tZ.a(dd.getClass()).d(dd);
        if (z) {
            dd.c(2);
        }
        return zD;
    }

    public static void j(Class cls, DD dd) {
        dd.h();
        defaultInstanceMap.put(cls, dd);
    }

    @Override // o.U
    public final int a(I40 i40) {
        int iG;
        int iG2;
        if (g()) {
            if (i40 == null) {
                C2530tZ c2530tZ = C2530tZ.c;
                c2530tZ.getClass();
                iG2 = c2530tZ.a(getClass()).g(this);
            } else {
                iG2 = i40.g(this);
            }
            if (iG2 >= 0) {
                return iG2;
            }
            throw new IllegalStateException(AbstractC0126Ew.j(iG2, "serialized size must be non-negative, was "));
        }
        int i = this.memoizedSerializedSize;
        if ((i & Api.BaseClientBuilder.API_PRIORITY_OTHER) != Integer.MAX_VALUE) {
            return i & Api.BaseClientBuilder.API_PRIORITY_OTHER;
        }
        if (i40 == null) {
            C2530tZ c2530tZ2 = C2530tZ.c;
            c2530tZ2.getClass();
            iG = c2530tZ2.a(getClass()).g(this);
        } else {
            iG = i40.g(this);
        }
        k(iG);
        return iG;
    }

    @Override // o.U
    public final void b(C2832wi c2832wi) {
        C2530tZ c2530tZ = C2530tZ.c;
        c2530tZ.getClass();
        I40 i40A = c2530tZ.a(getClass());
        OD od = c2832wi.j;
        if (od == null) {
            od = new OD(c2832wi);
        }
        i40A.e(this, od);
    }

    public abstract Object c(int i);

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        C2530tZ c2530tZ = C2530tZ.c;
        c2530tZ.getClass();
        return c2530tZ.a(getClass()).b(this, (DD) obj);
    }

    public final boolean g() {
        return (this.memoizedSerializedSize & MUTABLE_FLAG_MASK) != 0;
    }

    public final void h() {
        this.memoizedSerializedSize &= Api.BaseClientBuilder.API_PRIORITY_OTHER;
    }

    public final int hashCode() {
        if (g()) {
            C2530tZ c2530tZ = C2530tZ.c;
            c2530tZ.getClass();
            return c2530tZ.a(getClass()).i(this);
        }
        if (this.memoizedHashCode == 0) {
            C2530tZ c2530tZ2 = C2530tZ.c;
            c2530tZ2.getClass();
            this.memoizedHashCode = c2530tZ2.a(getClass()).i(this);
        }
        return this.memoizedHashCode;
    }

    public final DD i() {
        return (DD) c(4);
    }

    public final void k(int i) {
        if (i < 0) {
            throw new IllegalStateException(AbstractC0126Ew.j(i, "serialized size must be non-negative, was "));
        }
        this.memoizedSerializedSize = (i & Api.BaseClientBuilder.API_PRIORITY_OTHER) | (this.memoizedSerializedSize & MUTABLE_FLAG_MASK);
    }

    public final String toString() {
        String string = super.toString();
        char[] cArr = AbstractC1856mP.a;
        StringBuilder sb = new StringBuilder();
        sb.append("# ");
        sb.append(string);
        AbstractC1856mP.c(this, sb, 0);
        return sb.toString();
    }
}
