package h;

import d.C0424d;
import e.InterfaceC0451b;
import g.C0474a;
import g.EnumC0475b;
import g.InterfaceC0476c;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
public class h implements t {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    protected final Class f4135a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    protected final Enum[] f4136b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    protected final Enum[] f4137c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    protected long[] f4138d;

    public h(Class cls) {
        InterfaceC0451b interfaceC0451b;
        this.f4135a = cls;
        this.f4137c = (Enum[]) cls.getEnumConstants();
        HashMap map = new HashMap();
        int i2 = 0;
        while (true) {
            Enum[] enumArr = this.f4137c;
            if (i2 >= enumArr.length) {
                break;
            }
            Enum r5 = enumArr[i2];
            String strName = r5.name();
            InterfaceC0451b interfaceC0451b2 = null;
            try {
                interfaceC0451b = (InterfaceC0451b) l.l.N(cls.getField(strName), InterfaceC0451b.class);
                if (interfaceC0451b != null) {
                    try {
                        String strName2 = interfaceC0451b.name();
                        if (strName2 != null && strName2.length() > 0) {
                            strName = strName2;
                        }
                    } catch (Exception unused) {
                        interfaceC0451b2 = interfaceC0451b;
                        interfaceC0451b = interfaceC0451b2;
                    }
                }
            } catch (Exception unused2) {
            }
            int i3 = 0;
            long j2 = -3750763034362895579L;
            long j3 = -3750763034362895579L;
            while (i3 < strName.length()) {
                int iCharAt = strName.charAt(i3);
                long j4 = ((long) iCharAt) ^ j2;
                if (iCharAt >= 65 && iCharAt <= 90) {
                    iCharAt += 32;
                }
                j3 = (((long) iCharAt) ^ j3) * 1099511628211L;
                i3++;
                j2 = j4 * 1099511628211L;
            }
            map.put(Long.valueOf(j2), r5);
            if (j2 != j3) {
                map.put(Long.valueOf(j3), r5);
            }
            if (interfaceC0451b != null) {
                String[] strArrAlternateNames = interfaceC0451b.alternateNames();
                int length = strArrAlternateNames.length;
                int i4 = 0;
                while (i4 < length) {
                    String str = strArrAlternateNames[i4];
                    int i5 = 0;
                    long jCharAt = -3750763034362895579L;
                    while (i5 < str.length()) {
                        jCharAt = (jCharAt ^ ((long) str.charAt(i5))) * 1099511628211L;
                        i5++;
                        i2 = i2;
                    }
                    int i6 = i2;
                    if (jCharAt != j2 && jCharAt != j3) {
                        map.put(Long.valueOf(jCharAt), r5);
                    }
                    i4++;
                    i2 = i6;
                }
            }
            i2++;
        }
        this.f4138d = new long[map.size()];
        Iterator it = map.keySet().iterator();
        int i7 = 0;
        while (it.hasNext()) {
            this.f4138d[i7] = ((Long) it.next()).longValue();
            i7++;
        }
        Arrays.sort(this.f4138d);
        this.f4136b = new Enum[this.f4138d.length];
        int i8 = 0;
        while (true) {
            long[] jArr = this.f4138d;
            if (i8 >= jArr.length) {
                return;
            }
            this.f4136b[i8] = (Enum) map.get(Long.valueOf(jArr[i8]));
            i8++;
        }
    }

    public Enum a(long j2) {
        int iBinarySearch;
        if (this.f4136b != null && (iBinarySearch = Arrays.binarySearch(this.f4138d, j2)) >= 0) {
            return this.f4136b[iBinarySearch];
        }
        return null;
    }

    @Override // h.t
    public Object b(C0474a c0474a, Type type, Object obj) {
        try {
            InterfaceC0476c interfaceC0476c = c0474a.f3944H;
            int iF = interfaceC0476c.F();
            if (iF == 2) {
                int iN = interfaceC0476c.n();
                interfaceC0476c.s(16);
                if (iN >= 0) {
                    Enum[] enumArr = this.f4137c;
                    if (iN < enumArr.length) {
                        return enumArr[iN];
                    }
                }
                throw new C0424d("parse enum " + this.f4135a.getName() + " error, value : " + iN);
            }
            if (iF != 4) {
                if (iF == 8) {
                    interfaceC0476c.s(16);
                    return null;
                }
                throw new C0424d("parse enum " + this.f4135a.getName() + " error, value : " + c0474a.A());
            }
            String strA = interfaceC0476c.A();
            interfaceC0476c.s(16);
            if (strA.length() == 0) {
                return null;
            }
            long j2 = -3750763034362895579L;
            long j3 = -3750763034362895579L;
            for (int i2 = 0; i2 < strA.length(); i2++) {
                int iCharAt = strA.charAt(i2);
                long j4 = j2 ^ ((long) iCharAt);
                if (iCharAt >= 65 && iCharAt <= 90) {
                    iCharAt += 32;
                }
                j2 = j4 * 1099511628211L;
                j3 = (j3 ^ ((long) iCharAt)) * 1099511628211L;
            }
            Enum enumA = a(j2);
            if (enumA == null && j3 != j2) {
                enumA = a(j3);
            }
            if (enumA == null && interfaceC0476c.j(EnumC0475b.ErrorOnEnumNotMatch)) {
                throw new C0424d("not match enum value, " + this.f4135a.getName() + " : " + strA);
            }
            return enumA;
        } catch (C0424d e2) {
            throw e2;
        } catch (Exception e3) {
            throw new C0424d(e3.getMessage(), e3);
        }
    }

    public Enum c(int i2) {
        return this.f4137c[i2];
    }

    @Override // h.t
    public int d() {
        return 2;
    }
}
