package k.a.p;

import java.util.Iterator;

/* JADX INFO: compiled from: CollectionSerializers.kt */
/* JADX INFO: loaded from: classes.dex */
public abstract class a<Element, Collection, Builder> implements k.a.b<Collection> {
    private a() {
    }

    public /* synthetic */ a(j.p0.d.j jVar) {
        this();
    }

    public static /* synthetic */ void n(a aVar, k.a.o.c cVar, int i2, Object obj, boolean z, int i3, Object obj2) {
        if (obj2 != null) {
            throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: readElement");
        }
        if ((i3 & 8) != 0) {
            z = true;
        }
        aVar.m(cVar, i2, obj, z);
    }

    private final int o(k.a.o.c cVar, Builder builder) {
        int iE = cVar.e(a());
        h(builder, iE);
        return iE;
    }

    @Override // k.a.a
    public Collection d(k.a.o.e eVar) {
        j.p0.d.r.f(eVar, "decoder");
        return k(eVar, null);
    }

    protected abstract Builder f();

    protected abstract int g(Builder builder);

    protected abstract void h(Builder builder, int i2);

    protected abstract Iterator<Element> i(Collection collection);

    protected abstract int j(Collection collection);

    public final Collection k(k.a.o.e eVar, Collection collection) {
        Builder builderF;
        j.p0.d.r.f(eVar, "decoder");
        if (collection == null || (builderF = p(collection)) == null) {
            builderF = f();
        }
        int iG = g(builderF);
        k.a.o.c cVarA = eVar.a(a());
        if (!cVarA.r()) {
            while (true) {
                int iQ = cVarA.q(a());
                if (iQ == -1) {
                    break;
                }
                n(this, cVarA, iG + iQ, builderF, false, 8, null);
            }
        } else {
            l(cVarA, builderF, iG, o(cVarA, builderF));
        }
        cVarA.b(a());
        return q(builderF);
    }

    protected abstract void l(k.a.o.c cVar, Builder builder, int i2, int i3);

    protected abstract void m(k.a.o.c cVar, int i2, Builder builder, boolean z);

    protected abstract Builder p(Collection collection);

    protected abstract Collection q(Builder builder);
}
