package d;

import g.C0474a;
import g.EnumC0475b;
import h.v;
import i.C0516I;
import i.C0517J;
import i.InterfaceC0514G;
import i.U;
import i.b0;
import i.c0;
import i.e0;
import i.f0;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import l.AbstractC0613e;

/* JADX INFO: renamed from: d.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0421a implements InterfaceC0437j, InterfaceC0423c {

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    private static final ThreadLocal f3671M;

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    private static final ThreadLocal f3672Q;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static TimeZone f3673b = TimeZone.getDefault();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static Locale f3674g = Locale.getDefault();

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static String f3675r = "@type";

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    static final c0[] f3676x = new c0[0];

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public static String f3677y = "yyyy-MM-dd HH:mm:ss";

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    private static final ConcurrentHashMap f3670L = new ConcurrentHashMap(16);

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    public static int f3668H = ((((((EnumC0475b.AutoCloseSource.getMask() | EnumC0475b.InternFieldNames.getMask()) | EnumC0475b.UseBigDecimal.getMask()) | EnumC0475b.AllowUnQuotedFieldNames.getMask()) | EnumC0475b.AllowSingleQuotes.getMask()) | EnumC0475b.AllowArbitraryCommas.getMask()) | EnumC0475b.SortFeidFastMatch.getMask()) | EnumC0475b.IgnoreNotMatch.getMask();

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public static int f3669I = ((f0.QuoteFieldNames.getMask() | f0.SkipTransientField.getMask()) | f0.WriteEnumUsingName.getMask()) | f0.SortField.getMask();

    static {
        c(AbstractC0613e.f5266a);
        f3671M = new ThreadLocal();
        f3672Q = new ThreadLocal();
    }

    private static void c(Properties properties) {
        String property = properties.getProperty("fastjson.serializerFeatures.MapSortField");
        int mask = f0.MapSortField.getMask();
        if ("true".equals(property)) {
            f3669I |= mask;
        } else if ("false".equals(property)) {
            f3669I &= ~mask;
        }
        if ("true".equals(properties.getProperty("parser.features.NonStringKeyAsString"))) {
            f3668H |= EnumC0475b.NonStringKeyAsString.getMask();
        }
        if ("true".equals(properties.getProperty("parser.features.ErrorOnEnumNotMatch")) || "true".equals(properties.getProperty("fastjson.parser.features.ErrorOnEnumNotMatch"))) {
            f3668H |= EnumC0475b.ErrorOnEnumNotMatch.getMask();
        }
        if ("false".equals(properties.getProperty("fastjson.asmEnable"))) {
            g.i.r().x(false);
            b0.g().l(false);
        }
    }

    public static Type d(Type type) {
        if (type != null) {
            return (Type) f3670L.get(type);
        }
        return null;
    }

    public static Object e(String str) {
        return f(str, f3668H);
    }

    public static Object f(String str, int i2) {
        return g(str, g.i.r(), i2);
    }

    public static Object g(String str, g.i iVar, int i2) {
        if (str == null) {
            return null;
        }
        C0474a c0474a = new C0474a(str, iVar, i2);
        Object objA = c0474a.A();
        c0474a.w(objA);
        c0474a.close();
        return objA;
    }

    public static C0425e h(String str) {
        Object objE = e(str);
        if (objE instanceof C0425e) {
            return (C0425e) objE;
        }
        try {
            return (C0425e) l(objE);
        } catch (RuntimeException e2) {
            throw new C0424d("can not cast to JSONObject.", e2);
        }
    }

    public static Object i(String str, Class cls) {
        return j(str, cls, new EnumC0475b[0]);
    }

    public static Object j(String str, Class cls, EnumC0475b... enumC0475bArr) {
        return k(str, cls, g.i.f3999y, null, f3668H, enumC0475bArr);
    }

    public static Object k(String str, Type type, g.i iVar, v vVar, int i2, EnumC0475b... enumC0475bArr) {
        if (str == null || str.length() == 0) {
            return null;
        }
        if (enumC0475bArr != null) {
            for (EnumC0475b enumC0475b : enumC0475bArr) {
                i2 |= enumC0475b.mask;
            }
        }
        C0474a c0474a = new C0474a(str, iVar, i2);
        Object objP = c0474a.P(type, null);
        c0474a.w(objP);
        c0474a.close();
        return objP;
    }

    public static Object l(Object obj) {
        return m(obj, b0.f4302j);
    }

    public static Object m(Object obj, b0 b0Var) {
        if (obj == null) {
            return null;
        }
        if (obj instanceof AbstractC0421a) {
            return obj;
        }
        if (obj instanceof Map) {
            Map map = (Map) obj;
            int size = map.size();
            C0425e c0425e = new C0425e(map instanceof LinkedHashMap ? new LinkedHashMap(size) : map instanceof TreeMap ? new TreeMap() : new HashMap(size));
            for (Map.Entry entry : map.entrySet()) {
                c0425e.put(l.l.A(entry.getKey()), m(entry.getValue(), b0Var));
            }
            return c0425e;
        }
        if (obj instanceof Collection) {
            Collection collection = (Collection) obj;
            C0422b c0422b = new C0422b(collection.size());
            Iterator it = collection.iterator();
            while (it.hasNext()) {
                c0422b.add(m(it.next(), b0Var));
            }
            return c0422b;
        }
        if (obj instanceof InterfaceC0514G) {
            return e(n(obj));
        }
        Class<?> cls = obj.getClass();
        if (cls.isEnum()) {
            return ((Enum) obj).name();
        }
        if (cls.isArray()) {
            int length = Array.getLength(obj);
            C0422b c0422b2 = new C0422b(length);
            for (int i2 = 0; i2 < length; i2++) {
                c0422b2.add(l(Array.get(obj, i2)));
            }
            return c0422b2;
        }
        if (g.i.u(cls)) {
            return obj;
        }
        U uH = b0Var.h(cls);
        if (!(uH instanceof C0517J)) {
            return e(n(obj));
        }
        C0517J c0517j = (C0517J) uH;
        C0425e c0425e2 = new C0425e();
        try {
            for (Map.Entry entry2 : c0517j.n(obj).entrySet()) {
                c0425e2.put((String) entry2.getKey(), m(entry2.getValue(), b0Var));
            }
            return c0425e2;
        } catch (Exception e2) {
            throw new C0424d("toJSON error", e2);
        }
    }

    public static String n(Object obj) {
        return p(obj, f3676x, new f0[0]);
    }

    public static String o(Object obj, b0 b0Var, c0[] c0VarArr, String str, int i2, f0... f0VarArr) {
        e0 e0Var = new e0(null, i2, f0VarArr);
        try {
            C0516I c0516i = new C0516I(e0Var, b0Var);
            if (str != null && str.length() != 0) {
                c0516i.u(str);
                c0516i.h(f0.WriteDateUseDateFormat, true);
            }
            if (c0VarArr != null) {
                for (c0 c0Var : c0VarArr) {
                    c0516i.b(null);
                }
            }
            c0516i.v(obj);
            String string = e0Var.toString();
            e0Var.close();
            return string;
        } catch (Throwable th) {
            e0Var.close();
            throw th;
        }
    }

    public static String p(Object obj, c0[] c0VarArr, f0... f0VarArr) {
        return o(obj, b0.f4302j, c0VarArr, null, f3669I, f0VarArr);
    }

    @Override // d.InterfaceC0437j
    public void a(Appendable appendable) {
        e0 e0Var = new e0();
        try {
            try {
                new C0516I(e0Var).v(this);
                appendable.append(e0Var.toString());
            } catch (IOException e2) {
                throw new C0424d(e2.getMessage(), e2);
            }
        } finally {
            e0Var.close();
        }
    }

    @Override // d.InterfaceC0423c
    public String b() {
        e0 e0Var = new e0();
        try {
            new C0516I(e0Var).v(this);
            return e0Var.toString();
        } finally {
            e0Var.close();
        }
    }

    public Object q(Type type) {
        return l.l.h(this, type, g.i.r());
    }

    public String toString() {
        return b();
    }
}
