package e.a.q;

import java.util.Iterator;

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

    public /* synthetic */ a(d.n0.c.l lVar) {
        this();
    }

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

    private final int j(e.a.p.c cVar, Builder builder) {
        int iO = cVar.o(getDescriptor());
        c(builder, iO);
        return iO;
    }

    protected abstract Builder a();

    protected abstract int b(Builder builder);

    protected abstract void c(Builder builder, int i);

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

    @Override // e.a.a
    public Collection deserialize(e.a.p.e eVar) {
        d.n0.c.s.e(eVar, "decoder");
        return f(eVar, null);
    }

    protected abstract int e(Collection collection);

    public final Collection f(e.a.p.e eVar, Collection collection) {
        Builder builderA;
        d.n0.c.s.e(eVar, "decoder");
        if (collection == null || (builderA = k(collection)) == null) {
            builderA = a();
        }
        int iB = b(builderA);
        e.a.p.c cVarC = eVar.c(getDescriptor());
        if (!cVarC.x()) {
            while (true) {
                int iW = cVarC.w(getDescriptor());
                if (iW == -1) {
                    break;
                }
                i(this, cVarC, iB + iW, builderA, false, 8, null);
            }
        } else {
            g(cVarC, builderA, iB, j(cVarC, builderA));
        }
        cVarC.a(getDescriptor());
        return l(builderA);
    }

    protected abstract void g(e.a.p.c cVar, Builder builder, int i, int i2);

    protected abstract void h(e.a.p.c cVar, int i, Builder builder, boolean z);

    protected abstract Builder k(Collection collection);

    protected abstract Collection l(Builder builder);
}
