package h.b.o;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/* JADX INFO: compiled from: CollectionSerializers.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class j0<K, V> {
    public final h.b.b<Key> a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final h.b.b<Value> f4400b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final h.b.m.e f4401c;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    /* JADX WARN: Multi-variable type inference failed */
    public j0(h.b.b<K> bVar, h.b.b<V> bVar2) {
        super(null);
        g.h0.c.l.f(bVar, "kSerializer");
        g.h0.c.l.f(bVar2, "vSerializer");
        this.a = bVar;
        this.f4400b = bVar2;
        this.f4401c = new i0(bVar.a(), bVar2.a());
    }

    public h.b.m.e a() {
        return this.f4401c;
    }

    public void d(h.b.n.f fVar, Object obj) {
        g.h0.c.l.f(fVar, "encoder");
        int iJ = j(obj);
        h.b.m.e eVar = this.f4401c;
        h.b.n.d dVarU = fVar.u(eVar, iJ);
        Map map = (Map) obj;
        g.h0.c.l.f(map, "<this>");
        int i2 = 0;
        for (Map.Entry<K, V> entry : map.entrySet()) {
            K key = entry.getKey();
            V value = entry.getValue();
            int i3 = i2 + 1;
            dVarU.z(this.f4401c, i2, this.a, key);
            dVarU.z(this.f4401c, i3, this.f4400b, value);
            i2 = i3 + 1;
        }
        dVarU.a(eVar);
    }

    public Object f() {
        return new LinkedHashMap();
    }

    public int g(Object obj) {
        LinkedHashMap linkedHashMap = (LinkedHashMap) obj;
        g.h0.c.l.f(linkedHashMap, "<this>");
        return linkedHashMap.size() * 2;
    }

    public void h(Object obj, int i2) {
        g.h0.c.l.f((LinkedHashMap) obj, "<this>");
    }

    public Iterator i(Object obj) {
        Map map = (Map) obj;
        g.h0.c.l.f(map, "<this>");
        return map.entrySet().iterator();
    }

    public int j(Object obj) {
        Map map = (Map) obj;
        g.h0.c.l.f(map, "<this>");
        return map.size();
    }

    public void l(h.b.n.c cVar, Object obj, int i2, int i3) {
        Map map = (Map) obj;
        g.h0.c.l.f(cVar, "decoder");
        g.h0.c.l.f(map, "builder");
        if (!(i3 >= 0)) {
            throw new IllegalArgumentException("Size must be known in advance when using READ_ALL".toString());
        }
        g.j0.f fVarC = g.j0.l.c(g.j0.l.d(0, i3 * 2), 2);
        int i4 = fVarC.f4123b;
        int i5 = fVarC.f4124e;
        int i6 = fVarC.f4125f;
        if ((i6 <= 0 || i4 > i5) && (i6 >= 0 || i5 > i4)) {
            return;
        }
        while (true) {
            m(cVar, i2 + i4, map, false);
            if (i4 == i5) {
                return;
            } else {
                i4 += i6;
            }
        }
    }

    public Object n(Object obj) {
        Map map = (Map) obj;
        g.h0.c.l.f(map, "<this>");
        LinkedHashMap linkedHashMap = map instanceof LinkedHashMap ? (LinkedHashMap) map : null;
        return linkedHashMap == null ? new LinkedHashMap(map) : linkedHashMap;
    }

    public Object o(Object obj) {
        LinkedHashMap linkedHashMap = (LinkedHashMap) obj;
        g.h0.c.l.f(linkedHashMap, "<this>");
        return linkedHashMap;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX INFO: renamed from: p, reason: merged with bridge method [inline-methods] */
    public final void m(h.b.n.c cVar, int i2, Map map, boolean z) {
        int iX;
        g.h0.c.l.f(cVar, "decoder");
        g.h0.c.l.f(map, "builder");
        Object objN = f.a.y.a.N(cVar, this.f4401c, i2, this.a, null, 8, null);
        if (z) {
            iX = cVar.x(this.f4401c);
            if (!(iX == i2 + 1)) {
                throw new IllegalArgumentException(d.b.a.a.a.k("Value must follow key in a map, index for key: ", i2, ", returned index for value: ", iX).toString());
            }
        } else {
            iX = i2 + 1;
        }
        int i3 = iX;
        map.put(objN, (!map.containsKey(objN) || (this.f4400b.a().e() instanceof h.b.m.d)) ? f.a.y.a.N(cVar, this.f4401c, i3, this.f4400b, null, 8, null) : cVar.m(this.f4401c, i3, this.f4400b, g.c0.g.o(map, objN)));
    }
}
