package uk;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;

/* loaded from: classes3.dex */
public final class c {

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

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

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

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ Type f37256a;

        a(Type type) {
            this.f37256a = type;
        }

        @Override // uk.h
        public Object a() {
            Type type = this.f37256a;
            if (!(type instanceof ParameterizedType)) {
                throw new com.google.gson.j("Invalid EnumMap type: " + this.f37256a.toString());
            }
            Type type2 = ((ParameterizedType) type).getActualTypeArguments()[0];
            if (type2 instanceof Class) {
                return new EnumMap((Class) type2);
            }
            throw new com.google.gson.j("Invalid EnumMap type: " + this.f37256a.toString());
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class b implements uk.h {
        b() {
        }

        @Override // uk.h
        public Object a() {
            return new ConcurrentSkipListMap();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: uk.c$c, reason: collision with other inner class name */
    /* loaded from: classes3.dex */
    public class C0897c implements uk.h {
        C0897c() {
        }

        @Override // uk.h
        public Object a() {
            return new ConcurrentHashMap();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class d implements uk.h {
        d() {
        }

        @Override // uk.h
        public Object a() {
            return new TreeMap();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class e implements uk.h {
        e() {
        }

        @Override // uk.h
        public Object a() {
            return new LinkedHashMap();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class f implements uk.h {
        f() {
        }

        @Override // uk.h
        public Object a() {
            return new uk.g();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class g implements uk.h {

        /* renamed from: a, reason: collision with root package name */
        private final uk.l f37263a = uk.l.b();

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ Class f37264b;

        g(Class cls) {
            this.f37264b = cls;
        }

        @Override // uk.h
        public Object a() {
            try {
                return this.f37263a.c(this.f37264b);
            } catch (Exception e10) {
                throw new RuntimeException("Unable to create instance of " + this.f37264b + ". Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.", e10);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class h implements uk.h {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f37266a;

        h(String str) {
            this.f37266a = str;
        }

        @Override // uk.h
        public Object a() {
            throw new com.google.gson.j(this.f37266a);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class i implements uk.h {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f37268a;

        i(String str) {
            this.f37268a = str;
        }

        @Override // uk.h
        public Object a() {
            throw new com.google.gson.j(this.f37268a);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class j implements uk.h {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ Constructor f37270a;

        j(Constructor constructor) {
            this.f37270a = constructor;
        }

        @Override // uk.h
        public Object a() {
            try {
                return this.f37270a.newInstance(new Object[0]);
            } catch (IllegalAccessException e10) {
                throw new AssertionError(e10);
            } catch (InstantiationException e11) {
                throw new RuntimeException("Failed to invoke " + this.f37270a + " with no args", e11);
            } catch (InvocationTargetException e12) {
                throw new RuntimeException("Failed to invoke " + this.f37270a + " with no args", e12.getTargetException());
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class k implements uk.h {
        k() {
        }

        @Override // uk.h
        public Object a() {
            return new TreeSet();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class l implements uk.h {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ Type f37273a;

        l(Type type) {
            this.f37273a = type;
        }

        @Override // uk.h
        public Object a() {
            Type type = this.f37273a;
            if (!(type instanceof ParameterizedType)) {
                throw new com.google.gson.j("Invalid EnumSet type: " + this.f37273a.toString());
            }
            Type type2 = ((ParameterizedType) type).getActualTypeArguments()[0];
            if (type2 instanceof Class) {
                return EnumSet.noneOf((Class) type2);
            }
            throw new com.google.gson.j("Invalid EnumSet type: " + this.f37273a.toString());
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class m implements uk.h {
        m() {
        }

        @Override // uk.h
        public Object a() {
            return new LinkedHashSet();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class n implements uk.h {
        n() {
        }

        @Override // uk.h
        public Object a() {
            return new ArrayDeque();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class o implements uk.h {
        o() {
        }

        @Override // uk.h
        public Object a() {
            return new ArrayList();
        }
    }

    public c(Map map, boolean z10) {
        this.f37254a = map;
        this.f37255b = z10;
    }

    private uk.h b(Class cls) {
        if (Modifier.isAbstract(cls.getModifiers())) {
            return null;
        }
        try {
            Constructor declaredConstructor = cls.getDeclaredConstructor(new Class[0]);
            String c10 = wk.a.c(declaredConstructor);
            return c10 != null ? new i(c10) : new j(declaredConstructor);
        } catch (NoSuchMethodException unused) {
            return null;
        }
    }

    private uk.h c(Type type, Class cls) {
        if (Collection.class.isAssignableFrom(cls)) {
            return SortedSet.class.isAssignableFrom(cls) ? new k() : EnumSet.class.isAssignableFrom(cls) ? new l(type) : Set.class.isAssignableFrom(cls) ? new m() : Queue.class.isAssignableFrom(cls) ? new n() : new o();
        }
        if (Map.class.isAssignableFrom(cls)) {
            return cls == EnumMap.class ? new a(type) : ConcurrentNavigableMap.class.isAssignableFrom(cls) ? new b() : ConcurrentMap.class.isAssignableFrom(cls) ? new C0897c() : SortedMap.class.isAssignableFrom(cls) ? new d() : (!(type instanceof ParameterizedType) || String.class.isAssignableFrom(com.google.gson.reflect.a.get(((ParameterizedType) type).getActualTypeArguments()[0]).getRawType())) ? new f() : new e();
        }
        return null;
    }

    private uk.h d(Class cls) {
        if (this.f37255b) {
            return new g(cls);
        }
        return new h("Unable to create instance of " + cls + "; usage of JDK Unsafe is disabled. Registering an InstanceCreator or a TypeAdapter for this type, adding a no-args constructor, or enabling usage of JDK Unsafe may fix this problem.");
    }

    public uk.h a(com.google.gson.reflect.a aVar) {
        Type type = aVar.getType();
        Class<Object> rawType = aVar.getRawType();
        android.support.v4.media.session.b.a(this.f37254a.get(type));
        android.support.v4.media.session.b.a(this.f37254a.get(rawType));
        uk.h b10 = b(rawType);
        if (b10 != null) {
            return b10;
        }
        uk.h c10 = c(type, rawType);
        return c10 != null ? c10 : d(rawType);
    }

    public String toString() {
        return this.f37254a.toString();
    }
}
