package g.e.b.g0.f0;

import g.e.b.d0;
import g.e.b.e0;
import g.e.b.g0.x;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
public final class b implements e0 {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final g.e.b.g0.l f4043f;

    public static final class a<E> extends d0<Collection<E>> {
        public final d0<E> a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final x<? extends Collection<E>> f4044b;

        public a(g.e.b.j jVar, Type type, d0<E> d0Var, x<? extends Collection<E>> xVar) {
            this.a = new p(jVar, d0Var, type);
            this.f4044b = xVar;
        }

        @Override // g.e.b.d0
        public Object a(g.e.b.i0.a aVar) throws IOException {
            if (aVar.I() == g.e.b.i0.b.NULL) {
                aVar.E();
                return null;
            }
            Collection<E> collectionA = this.f4044b.a();
            aVar.a();
            while (aVar.q()) {
                collectionA.add(this.a.a(aVar));
            }
            aVar.g();
            return collectionA;
        }

        @Override // g.e.b.d0
        public void b(g.e.b.i0.c cVar, Object obj) {
            Collection collection = (Collection) obj;
            if (collection == null) {
                cVar.m();
                return;
            }
            cVar.c();
            Iterator<E> it = collection.iterator();
            while (it.hasNext()) {
                this.a.b(cVar, it.next());
            }
            cVar.g();
        }
    }

    public b(g.e.b.g0.l lVar) {
        this.f4043f = lVar;
    }

    @Override // g.e.b.e0
    public <T> d0<T> b(g.e.b.j jVar, g.e.b.h0.a<T> aVar) {
        Type type = aVar.f4166b;
        Class<? super T> cls = aVar.a;
        if (!Collection.class.isAssignableFrom(cls)) {
            return null;
        }
        Type typeG = g.e.b.g0.a.g(type, cls, Collection.class);
        Class cls2 = typeG instanceof ParameterizedType ? ((ParameterizedType) typeG).getActualTypeArguments()[0] : Object.class;
        return new a(jVar, cls2, jVar.d(new g.e.b.h0.a<>(cls2)), this.f4043f.a(aVar));
    }
}
