package com.google.gson.internal.bind;

import com.google.gson.q;
import com.google.gson.u;
import com.google.gson.v;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import uk.i;

/* loaded from: classes3.dex */
public final class a extends u {

    /* renamed from: a, reason: collision with root package name */
    private final b f14977a;

    /* renamed from: b, reason: collision with root package name */
    private final List f14978b;

    /* loaded from: classes3.dex */
    public static abstract class b {

        /* renamed from: b, reason: collision with root package name */
        public static final b f14979b = new C0332a(Date.class);

        /* renamed from: a, reason: collision with root package name */
        private final Class f14980a;

        /* renamed from: com.google.gson.internal.bind.a$b$a, reason: collision with other inner class name */
        /* loaded from: classes3.dex */
        class C0332a extends b {
            C0332a(Class cls) {
                super(cls);
            }

            @Override // com.google.gson.internal.bind.a.b
            protected Date d(Date date) {
                return date;
            }
        }

        /* JADX INFO: Access modifiers changed from: protected */
        public b(Class cls) {
            this.f14980a = cls;
        }

        private final v c(a aVar) {
            return TypeAdapters.b(this.f14980a, aVar);
        }

        public final v a(int i10, int i11) {
            return c(new a(this, i10, i11));
        }

        public final v b(String str) {
            return c(new a(this, str));
        }

        protected abstract Date d(Date date);
    }

    private Date a(xk.a aVar) {
        String J = aVar.J();
        synchronized (this.f14978b) {
            Iterator it = this.f14978b.iterator();
            while (it.hasNext()) {
                try {
                    return ((DateFormat) it.next()).parse(J);
                } catch (ParseException unused) {
                }
            }
            try {
                return vk.a.c(J, new ParsePosition(0));
            } catch (ParseException e10) {
                throw new q("Failed parsing '" + J + "' as Date; at path " + aVar.m(), e10);
            }
        }
    }

    @Override // com.google.gson.u
    /* renamed from: b, reason: merged with bridge method [inline-methods] */
    public Date read(xk.a aVar) {
        if (aVar.L() == xk.b.NULL) {
            aVar.G();
            return null;
        }
        return this.f14977a.d(a(aVar));
    }

    @Override // com.google.gson.u
    /* renamed from: c, reason: merged with bridge method [inline-methods] */
    public void write(xk.c cVar, Date date) {
        String format;
        if (date == null) {
            cVar.t();
            return;
        }
        DateFormat dateFormat = (DateFormat) this.f14978b.get(0);
        synchronized (this.f14978b) {
            format = dateFormat.format(date);
        }
        cVar.Q(format);
    }

    public String toString() {
        DateFormat dateFormat = (DateFormat) this.f14978b.get(0);
        if (dateFormat instanceof SimpleDateFormat) {
            return "DefaultDateTypeAdapter(" + ((SimpleDateFormat) dateFormat).toPattern() + ')';
        }
        return "DefaultDateTypeAdapter(" + dateFormat.getClass().getSimpleName() + ')';
    }

    private a(b bVar, String str) {
        ArrayList arrayList = new ArrayList();
        this.f14978b = arrayList;
        this.f14977a = (b) uk.a.b(bVar);
        Locale locale = Locale.US;
        arrayList.add(new SimpleDateFormat(str, locale));
        if (Locale.getDefault().equals(locale)) {
            return;
        }
        arrayList.add(new SimpleDateFormat(str));
    }

    private a(b bVar, int i10, int i11) {
        ArrayList arrayList = new ArrayList();
        this.f14978b = arrayList;
        this.f14977a = (b) uk.a.b(bVar);
        Locale locale = Locale.US;
        arrayList.add(DateFormat.getDateTimeInstance(i10, i11, locale));
        if (!Locale.getDefault().equals(locale)) {
            arrayList.add(DateFormat.getDateTimeInstance(i10, i11));
        }
        if (uk.d.d()) {
            arrayList.add(i.c(i10, i11));
        }
    }
}
