package c.l;

import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcelable;
import android.util.Size;
import android.util.SizeF;
import android.util.SparseArray;
import c.o.b;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/* JADX INFO: compiled from: SavedStateHandle.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class y {
    public static final a a = null;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Class<? extends Object>[] f1799b = {Boolean.TYPE, boolean[].class, Double.TYPE, double[].class, Integer.TYPE, int[].class, Long.TYPE, long[].class, String.class, String[].class, Binder.class, Bundle.class, Byte.TYPE, byte[].class, Character.TYPE, char[].class, CharSequence.class, CharSequence[].class, ArrayList.class, Float.TYPE, float[].class, Parcelable.class, Parcelable[].class, Serializable.class, Short.TYPE, short[].class, SparseArray.class, Size.class, SizeF.class};

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Map<String, Object> f1800c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Map<String, b.InterfaceC0024b> f1801d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Map<String, ?> f1802e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Map<String, h.a.j1.a<Object>> f1803f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final b.InterfaceC0024b f1804g;

    /* JADX INFO: compiled from: SavedStateHandle.kt */
    @g.i
    public static final class a {
        public static final y a(Bundle bundle, Bundle bundle2) {
            if (bundle == null) {
                if (bundle2 == null) {
                    return new y();
                }
                HashMap map = new HashMap();
                for (String str : bundle2.keySet()) {
                    g.h0.c.l.e(str, "key");
                    map.put(str, bundle2.get(str));
                }
                return new y(map);
            }
            ArrayList parcelableArrayList = bundle.getParcelableArrayList("keys");
            ArrayList parcelableArrayList2 = bundle.getParcelableArrayList("values");
            if (!((parcelableArrayList == null || parcelableArrayList2 == null || parcelableArrayList.size() != parcelableArrayList2.size()) ? false : true)) {
                throw new IllegalStateException("Invalid bundle passed as restored state".toString());
            }
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            int size = parcelableArrayList.size();
            for (int i2 = 0; i2 < size; i2++) {
                Object obj = parcelableArrayList.get(i2);
                Objects.requireNonNull(obj, "null cannot be cast to non-null type kotlin.String");
                linkedHashMap.put((String) obj, parcelableArrayList2.get(i2));
            }
            return new y(linkedHashMap);
        }
    }

    public y(Map<String, ? extends Object> map) {
        g.h0.c.l.f(map, "initialState");
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        this.f1800c = linkedHashMap;
        this.f1801d = new LinkedHashMap();
        this.f1802e = new LinkedHashMap();
        this.f1803f = new LinkedHashMap();
        this.f1804g = new b.InterfaceC0024b() { // from class: c.l.a
            /* JADX WARN: Multi-variable type inference failed */
            @Override // c.o.b.InterfaceC0024b
            public final Bundle a() {
                y yVar = this.a;
                g.h0.c.l.f(yVar, "this$0");
                Iterator it = g.c0.g.I(yVar.f1801d).entrySet().iterator();
                while (true) {
                    int i2 = 0;
                    if (!it.hasNext()) {
                        Set<String> setKeySet = yVar.f1800c.keySet();
                        ArrayList arrayList = new ArrayList(setKeySet.size());
                        ArrayList arrayList2 = new ArrayList(arrayList.size());
                        for (String str : setKeySet) {
                            arrayList.add(str);
                            arrayList2.add(yVar.f1800c.get(str));
                        }
                        g.k[] kVarArr = {new g.k("keys", arrayList), new g.k("values", arrayList2)};
                        g.h0.c.l.f(kVarArr, "pairs");
                        Bundle bundle = new Bundle(2);
                        while (i2 < 2) {
                            g.k kVar = kVarArr[i2];
                            String str2 = (String) kVar.f4139b;
                            B b2 = kVar.f4140e;
                            if (b2 == 0) {
                                bundle.putString(str2, null);
                            } else if (b2 instanceof Boolean) {
                                bundle.putBoolean(str2, ((Boolean) b2).booleanValue());
                            } else if (b2 instanceof Byte) {
                                bundle.putByte(str2, ((Number) b2).byteValue());
                            } else if (b2 instanceof Character) {
                                bundle.putChar(str2, ((Character) b2).charValue());
                            } else if (b2 instanceof Double) {
                                bundle.putDouble(str2, ((Number) b2).doubleValue());
                            } else if (b2 instanceof Float) {
                                bundle.putFloat(str2, ((Number) b2).floatValue());
                            } else if (b2 instanceof Integer) {
                                bundle.putInt(str2, ((Number) b2).intValue());
                            } else if (b2 instanceof Long) {
                                bundle.putLong(str2, ((Number) b2).longValue());
                            } else if (b2 instanceof Short) {
                                bundle.putShort(str2, ((Number) b2).shortValue());
                            } else if (b2 instanceof Bundle) {
                                bundle.putBundle(str2, (Bundle) b2);
                            } else if (b2 instanceof CharSequence) {
                                bundle.putCharSequence(str2, (CharSequence) b2);
                            } else if (b2 instanceof Parcelable) {
                                bundle.putParcelable(str2, (Parcelable) b2);
                            } else if (b2 instanceof boolean[]) {
                                bundle.putBooleanArray(str2, (boolean[]) b2);
                            } else if (b2 instanceof byte[]) {
                                bundle.putByteArray(str2, (byte[]) b2);
                            } else if (b2 instanceof char[]) {
                                bundle.putCharArray(str2, (char[]) b2);
                            } else if (b2 instanceof double[]) {
                                bundle.putDoubleArray(str2, (double[]) b2);
                            } else if (b2 instanceof float[]) {
                                bundle.putFloatArray(str2, (float[]) b2);
                            } else if (b2 instanceof int[]) {
                                bundle.putIntArray(str2, (int[]) b2);
                            } else if (b2 instanceof long[]) {
                                bundle.putLongArray(str2, (long[]) b2);
                            } else if (b2 instanceof short[]) {
                                bundle.putShortArray(str2, (short[]) b2);
                            } else if (b2 instanceof Object[]) {
                                Class<?> componentType = b2.getClass().getComponentType();
                                g.h0.c.l.c(componentType);
                                if (Parcelable.class.isAssignableFrom(componentType)) {
                                    g.h0.c.l.d(b2, "null cannot be cast to non-null type kotlin.Array<android.os.Parcelable>");
                                    bundle.putParcelableArray(str2, (Parcelable[]) b2);
                                } else if (String.class.isAssignableFrom(componentType)) {
                                    g.h0.c.l.d(b2, "null cannot be cast to non-null type kotlin.Array<kotlin.String>");
                                    bundle.putStringArray(str2, (String[]) b2);
                                } else if (CharSequence.class.isAssignableFrom(componentType)) {
                                    g.h0.c.l.d(b2, "null cannot be cast to non-null type kotlin.Array<kotlin.CharSequence>");
                                    bundle.putCharSequenceArray(str2, (CharSequence[]) b2);
                                } else {
                                    if (!Serializable.class.isAssignableFrom(componentType)) {
                                        throw new IllegalArgumentException("Illegal value array type " + componentType.getCanonicalName() + " for key \"" + str2 + '\"');
                                    }
                                    bundle.putSerializable(str2, (Serializable) b2);
                                }
                            } else if (b2 instanceof Serializable) {
                                bundle.putSerializable(str2, (Serializable) b2);
                            } else if (b2 instanceof IBinder) {
                                c.f.f.a.a(bundle, str2, (IBinder) b2);
                            } else if (b2 instanceof Size) {
                                c.f.f.b.a(bundle, str2, (Size) b2);
                            } else {
                                if (!(b2 instanceof SizeF)) {
                                    throw new IllegalArgumentException("Illegal value type " + b2.getClass().getCanonicalName() + " for key \"" + str2 + '\"');
                                }
                                c.f.f.b.b(bundle, str2, (SizeF) b2);
                            }
                            i2++;
                        }
                        return bundle;
                    }
                    Map.Entry entry = (Map.Entry) it.next();
                    String str3 = (String) entry.getKey();
                    Bundle bundleA = ((b.InterfaceC0024b) entry.getValue()).a();
                    g.h0.c.l.f(str3, "key");
                    if (bundleA == null) {
                        i2 = 1;
                        break;
                    }
                    for (Class<? extends Object> cls : y.f1799b) {
                        g.h0.c.l.c(cls);
                        if (cls.isInstance(bundleA)) {
                            i2 = 1;
                            break;
                        }
                    }
                    if (i2 == 0) {
                        StringBuilder sb = new StringBuilder();
                        sb.append("Can't put value with type ");
                        g.h0.c.l.c(bundleA);
                        sb.append(bundleA.getClass());
                        sb.append(" into saved state");
                        throw new IllegalArgumentException(sb.toString());
                    }
                    Object obj = yVar.f1802e.get(str3);
                    s sVar = obj instanceof s ? (s) obj : null;
                    if (sVar != null) {
                        sVar.i(bundleA);
                    } else {
                        yVar.f1800c.put(str3, bundleA);
                    }
                    h.a.j1.a<Object> aVar = yVar.f1803f.get(str3);
                    if (aVar != null) {
                        aVar.setValue(bundleA);
                    }
                }
            }
        };
        linkedHashMap.putAll(map);
    }

    public y() {
        this.f1800c = new LinkedHashMap();
        this.f1801d = new LinkedHashMap();
        this.f1802e = new LinkedHashMap();
        this.f1803f = new LinkedHashMap();
        this.f1804g = new b.InterfaceC0024b() { // from class: c.l.a
            /* JADX WARN: Multi-variable type inference failed */
            @Override // c.o.b.InterfaceC0024b
            public final Bundle a() {
                y yVar = this.a;
                g.h0.c.l.f(yVar, "this$0");
                Iterator it = g.c0.g.I(yVar.f1801d).entrySet().iterator();
                while (true) {
                    int i2 = 0;
                    if (!it.hasNext()) {
                        Set<String> setKeySet = yVar.f1800c.keySet();
                        ArrayList arrayList = new ArrayList(setKeySet.size());
                        ArrayList arrayList2 = new ArrayList(arrayList.size());
                        for (String str : setKeySet) {
                            arrayList.add(str);
                            arrayList2.add(yVar.f1800c.get(str));
                        }
                        g.k[] kVarArr = {new g.k("keys", arrayList), new g.k("values", arrayList2)};
                        g.h0.c.l.f(kVarArr, "pairs");
                        Bundle bundle = new Bundle(2);
                        while (i2 < 2) {
                            g.k kVar = kVarArr[i2];
                            String str2 = (String) kVar.f4139b;
                            B b2 = kVar.f4140e;
                            if (b2 == 0) {
                                bundle.putString(str2, null);
                            } else if (b2 instanceof Boolean) {
                                bundle.putBoolean(str2, ((Boolean) b2).booleanValue());
                            } else if (b2 instanceof Byte) {
                                bundle.putByte(str2, ((Number) b2).byteValue());
                            } else if (b2 instanceof Character) {
                                bundle.putChar(str2, ((Character) b2).charValue());
                            } else if (b2 instanceof Double) {
                                bundle.putDouble(str2, ((Number) b2).doubleValue());
                            } else if (b2 instanceof Float) {
                                bundle.putFloat(str2, ((Number) b2).floatValue());
                            } else if (b2 instanceof Integer) {
                                bundle.putInt(str2, ((Number) b2).intValue());
                            } else if (b2 instanceof Long) {
                                bundle.putLong(str2, ((Number) b2).longValue());
                            } else if (b2 instanceof Short) {
                                bundle.putShort(str2, ((Number) b2).shortValue());
                            } else if (b2 instanceof Bundle) {
                                bundle.putBundle(str2, (Bundle) b2);
                            } else if (b2 instanceof CharSequence) {
                                bundle.putCharSequence(str2, (CharSequence) b2);
                            } else if (b2 instanceof Parcelable) {
                                bundle.putParcelable(str2, (Parcelable) b2);
                            } else if (b2 instanceof boolean[]) {
                                bundle.putBooleanArray(str2, (boolean[]) b2);
                            } else if (b2 instanceof byte[]) {
                                bundle.putByteArray(str2, (byte[]) b2);
                            } else if (b2 instanceof char[]) {
                                bundle.putCharArray(str2, (char[]) b2);
                            } else if (b2 instanceof double[]) {
                                bundle.putDoubleArray(str2, (double[]) b2);
                            } else if (b2 instanceof float[]) {
                                bundle.putFloatArray(str2, (float[]) b2);
                            } else if (b2 instanceof int[]) {
                                bundle.putIntArray(str2, (int[]) b2);
                            } else if (b2 instanceof long[]) {
                                bundle.putLongArray(str2, (long[]) b2);
                            } else if (b2 instanceof short[]) {
                                bundle.putShortArray(str2, (short[]) b2);
                            } else if (b2 instanceof Object[]) {
                                Class<?> componentType = b2.getClass().getComponentType();
                                g.h0.c.l.c(componentType);
                                if (Parcelable.class.isAssignableFrom(componentType)) {
                                    g.h0.c.l.d(b2, "null cannot be cast to non-null type kotlin.Array<android.os.Parcelable>");
                                    bundle.putParcelableArray(str2, (Parcelable[]) b2);
                                } else if (String.class.isAssignableFrom(componentType)) {
                                    g.h0.c.l.d(b2, "null cannot be cast to non-null type kotlin.Array<kotlin.String>");
                                    bundle.putStringArray(str2, (String[]) b2);
                                } else if (CharSequence.class.isAssignableFrom(componentType)) {
                                    g.h0.c.l.d(b2, "null cannot be cast to non-null type kotlin.Array<kotlin.CharSequence>");
                                    bundle.putCharSequenceArray(str2, (CharSequence[]) b2);
                                } else {
                                    if (!Serializable.class.isAssignableFrom(componentType)) {
                                        throw new IllegalArgumentException("Illegal value array type " + componentType.getCanonicalName() + " for key \"" + str2 + '\"');
                                    }
                                    bundle.putSerializable(str2, (Serializable) b2);
                                }
                            } else if (b2 instanceof Serializable) {
                                bundle.putSerializable(str2, (Serializable) b2);
                            } else if (b2 instanceof IBinder) {
                                c.f.f.a.a(bundle, str2, (IBinder) b2);
                            } else if (b2 instanceof Size) {
                                c.f.f.b.a(bundle, str2, (Size) b2);
                            } else {
                                if (!(b2 instanceof SizeF)) {
                                    throw new IllegalArgumentException("Illegal value type " + b2.getClass().getCanonicalName() + " for key \"" + str2 + '\"');
                                }
                                c.f.f.b.b(bundle, str2, (SizeF) b2);
                            }
                            i2++;
                        }
                        return bundle;
                    }
                    Map.Entry entry = (Map.Entry) it.next();
                    String str3 = (String) entry.getKey();
                    Bundle bundleA = ((b.InterfaceC0024b) entry.getValue()).a();
                    g.h0.c.l.f(str3, "key");
                    if (bundleA == null) {
                        i2 = 1;
                        break;
                    }
                    for (Class<? extends Object> cls : y.f1799b) {
                        g.h0.c.l.c(cls);
                        if (cls.isInstance(bundleA)) {
                            i2 = 1;
                            break;
                        }
                    }
                    if (i2 == 0) {
                        StringBuilder sb = new StringBuilder();
                        sb.append("Can't put value with type ");
                        g.h0.c.l.c(bundleA);
                        sb.append(bundleA.getClass());
                        sb.append(" into saved state");
                        throw new IllegalArgumentException(sb.toString());
                    }
                    Object obj = yVar.f1802e.get(str3);
                    s sVar = obj instanceof s ? (s) obj : null;
                    if (sVar != null) {
                        sVar.i(bundleA);
                    } else {
                        yVar.f1800c.put(str3, bundleA);
                    }
                    h.a.j1.a<Object> aVar = yVar.f1803f.get(str3);
                    if (aVar != null) {
                        aVar.setValue(bundleA);
                    }
                }
            }
        };
    }
}
