package j$.time.chrono;

import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;

/* JADX INFO: renamed from: j$.time.chrono.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes2.dex */
public abstract class AbstractC2282a implements k {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final ConcurrentHashMap f19138a = new ConcurrentHashMap();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final ConcurrentHashMap f19139b = new ConcurrentHashMap();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final /* synthetic */ int f19140c = 0;

    @Override // java.lang.Comparable
    public final int compareTo(Object obj) {
        return s().compareTo(((k) obj).s());
    }

    static {
        new Locale("ja", "JP", "JP");
    }

    static k B(AbstractC2282a abstractC2282a, String str) {
        String strT;
        k kVar = (k) f19138a.putIfAbsent(str, abstractC2282a);
        if (kVar == null && (strT = abstractC2282a.T()) != null) {
            f19139b.putIfAbsent(strT, abstractC2282a);
        }
        return kVar;
    }

    static k r(String str) {
        Objects.requireNonNull(str, "id");
        while (true) {
            ConcurrentHashMap concurrentHashMap = f19138a;
            k kVar = (k) concurrentHashMap.get(str);
            if (kVar == null) {
                kVar = (k) f19139b.get(str);
            }
            if (kVar != null) {
                return kVar;
            }
            if (concurrentHashMap.get("ISO") != null) {
                for (k kVar2 : ServiceLoader.load(k.class)) {
                    if (str.equals(kVar2.s()) || str.equals(kVar2.T())) {
                        return kVar2;
                    }
                }
                throw new j$.time.c("Unknown chronology: ".concat(str));
            }
            n nVar = n.f19156m;
            B(nVar, nVar.s());
            u uVar = u.f19174d;
            B(uVar, uVar.s());
            z zVar = z.f19186d;
            B(zVar, zVar.s());
            F f6 = F.f19134d;
            B(f6, f6.s());
            try {
                for (AbstractC2282a abstractC2282a : Arrays.asList(new AbstractC2282a[0])) {
                    if (!abstractC2282a.s().equals("ISO")) {
                        B(abstractC2282a, abstractC2282a.s());
                    }
                }
                r rVar = r.f19171d;
                B(rVar, rVar.s());
            } catch (Throwable th) {
                throw new ServiceConfigurationError(th.getMessage(), th);
            }
        }
    }

    protected AbstractC2282a() {
    }

    @Override // j$.time.chrono.k
    public ChronoLocalDate R(Map map, j$.time.format.G g6) {
        j$.time.temporal.a aVar = j$.time.temporal.a.EPOCH_DAY;
        if (map.containsKey(aVar)) {
            return q(((Long) map.remove(aVar)).longValue());
        }
        U(map, g6);
        ChronoLocalDate chronoLocalDateY = Y(map, g6);
        if (chronoLocalDateY != null) {
            return chronoLocalDateY;
        }
        j$.time.temporal.a aVar2 = j$.time.temporal.a.YEAR;
        if (!map.containsKey(aVar2)) {
            return null;
        }
        j$.time.temporal.a aVar3 = j$.time.temporal.a.MONTH_OF_YEAR;
        if (map.containsKey(aVar3)) {
            if (map.containsKey(j$.time.temporal.a.DAY_OF_MONTH)) {
                return V(map, g6);
            }
            j$.time.temporal.a aVar4 = j$.time.temporal.a.ALIGNED_WEEK_OF_MONTH;
            if (map.containsKey(aVar4)) {
                j$.time.temporal.a aVar5 = j$.time.temporal.a.ALIGNED_DAY_OF_WEEK_IN_MONTH;
                if (map.containsKey(aVar5)) {
                    int iA = W(aVar2).a(((Long) map.remove(aVar2)).longValue(), aVar2);
                    if (g6 == j$.time.format.G.LENIENT) {
                        long jSubtractExact = Math.subtractExact(((Long) map.remove(aVar3)).longValue(), 1L);
                        return G(iA, 1, 1).b(jSubtractExact, (j$.time.temporal.v) j$.time.temporal.b.MONTHS).b(Math.subtractExact(((Long) map.remove(aVar4)).longValue(), 1L), (j$.time.temporal.v) j$.time.temporal.b.WEEKS).b(Math.subtractExact(((Long) map.remove(aVar5)).longValue(), 1L), (j$.time.temporal.v) j$.time.temporal.b.DAYS);
                    }
                    int iA2 = W(aVar3).a(((Long) map.remove(aVar3)).longValue(), aVar3);
                    int iA3 = W(aVar4).a(((Long) map.remove(aVar4)).longValue(), aVar4);
                    ChronoLocalDate chronoLocalDateB = G(iA, iA2, 1).b((W(aVar5).a(((Long) map.remove(aVar5)).longValue(), aVar5) - 1) + ((iA3 - 1) * 7), (j$.time.temporal.v) j$.time.temporal.b.DAYS);
                    if (g6 != j$.time.format.G.STRICT || chronoLocalDateB.j(aVar3) == iA2) {
                        return chronoLocalDateB;
                    }
                    throw new j$.time.c("Strict mode rejected resolved date as it is in a different month");
                }
                j$.time.temporal.a aVar6 = j$.time.temporal.a.DAY_OF_WEEK;
                if (map.containsKey(aVar6)) {
                    int iA4 = W(aVar2).a(((Long) map.remove(aVar2)).longValue(), aVar2);
                    if (g6 == j$.time.format.G.LENIENT) {
                        return J(G(iA4, 1, 1), Math.subtractExact(((Long) map.remove(aVar3)).longValue(), 1L), Math.subtractExact(((Long) map.remove(aVar4)).longValue(), 1L), Math.subtractExact(((Long) map.remove(aVar6)).longValue(), 1L));
                    }
                    int iA5 = W(aVar3).a(((Long) map.remove(aVar3)).longValue(), aVar3);
                    ChronoLocalDate chronoLocalDateM = G(iA4, iA5, 1).b((W(aVar4).a(((Long) map.remove(aVar4)).longValue(), aVar4) - 1) * 7, (j$.time.temporal.v) j$.time.temporal.b.DAYS).m(new j$.time.temporal.p(j$.time.e.r(W(aVar6).a(((Long) map.remove(aVar6)).longValue(), aVar6)).p(), 0));
                    if (g6 != j$.time.format.G.STRICT || chronoLocalDateM.j(aVar3) == iA5) {
                        return chronoLocalDateM;
                    }
                    throw new j$.time.c("Strict mode rejected resolved date as it is in a different month");
                }
            }
        }
        j$.time.temporal.a aVar7 = j$.time.temporal.a.DAY_OF_YEAR;
        if (map.containsKey(aVar7)) {
            int iA6 = W(aVar2).a(((Long) map.remove(aVar2)).longValue(), aVar2);
            if (g6 != j$.time.format.G.LENIENT) {
                return z(iA6, W(aVar7).a(((Long) map.remove(aVar7)).longValue(), aVar7));
            }
            return z(iA6, 1).b(Math.subtractExact(((Long) map.remove(aVar7)).longValue(), 1L), (j$.time.temporal.v) j$.time.temporal.b.DAYS);
        }
        j$.time.temporal.a aVar8 = j$.time.temporal.a.ALIGNED_WEEK_OF_YEAR;
        if (!map.containsKey(aVar8)) {
            return null;
        }
        j$.time.temporal.a aVar9 = j$.time.temporal.a.ALIGNED_DAY_OF_WEEK_IN_YEAR;
        if (map.containsKey(aVar9)) {
            int iA7 = W(aVar2).a(((Long) map.remove(aVar2)).longValue(), aVar2);
            if (g6 == j$.time.format.G.LENIENT) {
                return z(iA7, 1).b(Math.subtractExact(((Long) map.remove(aVar8)).longValue(), 1L), (j$.time.temporal.v) j$.time.temporal.b.WEEKS).b(Math.subtractExact(((Long) map.remove(aVar9)).longValue(), 1L), (j$.time.temporal.v) j$.time.temporal.b.DAYS);
            }
            int iA8 = W(aVar8).a(((Long) map.remove(aVar8)).longValue(), aVar8);
            ChronoLocalDate chronoLocalDateB2 = z(iA7, 1).b((W(aVar9).a(((Long) map.remove(aVar9)).longValue(), aVar9) - 1) + ((iA8 - 1) * 7), (j$.time.temporal.v) j$.time.temporal.b.DAYS);
            if (g6 != j$.time.format.G.STRICT || chronoLocalDateB2.j(aVar2) == iA7) {
                return chronoLocalDateB2;
            }
            throw new j$.time.c("Strict mode rejected resolved date as it is in a different year");
        }
        j$.time.temporal.a aVar10 = j$.time.temporal.a.DAY_OF_WEEK;
        if (!map.containsKey(aVar10)) {
            return null;
        }
        int iA9 = W(aVar2).a(((Long) map.remove(aVar2)).longValue(), aVar2);
        if (g6 == j$.time.format.G.LENIENT) {
            return J(z(iA9, 1), 0L, Math.subtractExact(((Long) map.remove(aVar8)).longValue(), 1L), Math.subtractExact(((Long) map.remove(aVar10)).longValue(), 1L));
        }
        ChronoLocalDate chronoLocalDateM2 = z(iA9, 1).b((W(aVar8).a(((Long) map.remove(aVar8)).longValue(), aVar8) - 1) * 7, (j$.time.temporal.v) j$.time.temporal.b.DAYS).m(new j$.time.temporal.p(j$.time.e.r(W(aVar10).a(((Long) map.remove(aVar10)).longValue(), aVar10)).p(), 0));
        if (g6 != j$.time.format.G.STRICT || chronoLocalDateM2.j(aVar2) == iA9) {
            return chronoLocalDateM2;
        }
        throw new j$.time.c("Strict mode rejected resolved date as it is in a different year");
    }

    void U(Map map, j$.time.format.G g6) {
        j$.time.temporal.a aVar = j$.time.temporal.a.PROLEPTIC_MONTH;
        Long l = (Long) map.remove(aVar);
        if (l != null) {
            if (g6 != j$.time.format.G.LENIENT) {
                aVar.c0(l.longValue());
            }
            ChronoLocalDate chronoLocalDateA = M().a(1L, (j$.time.temporal.s) j$.time.temporal.a.DAY_OF_MONTH).a(l.longValue(), (j$.time.temporal.s) aVar);
            p(map, j$.time.temporal.a.MONTH_OF_YEAR, chronoLocalDateA.j(r0));
            p(map, j$.time.temporal.a.YEAR, chronoLocalDateA.j(r0));
        }
    }

    ChronoLocalDate Y(Map map, j$.time.format.G g6) {
        int intExact;
        j$.time.temporal.a aVar = j$.time.temporal.a.YEAR_OF_ERA;
        Long l = (Long) map.remove(aVar);
        if (l != null) {
            Long l6 = (Long) map.remove(j$.time.temporal.a.ERA);
            if (g6 != j$.time.format.G.LENIENT) {
                intExact = W(aVar).a(l.longValue(), aVar);
            } else {
                intExact = Math.toIntExact(l.longValue());
            }
            if (l6 != null) {
                p(map, j$.time.temporal.a.YEAR, v(P(W(r2).a(l6.longValue(), r2)), intExact));
                return null;
            }
            j$.time.temporal.a aVar2 = j$.time.temporal.a.YEAR;
            if (map.containsKey(aVar2)) {
                p(map, aVar2, v(z(W(aVar2).a(((Long) map.get(aVar2)).longValue(), aVar2), 1).u(), intExact));
                return null;
            }
            if (g6 == j$.time.format.G.STRICT) {
                map.put(aVar, l);
                return null;
            }
            if (C().isEmpty()) {
                p(map, aVar2, intExact);
                return null;
            }
            p(map, aVar2, v((l) r9.get(r9.size() - 1), intExact));
            return null;
        }
        j$.time.temporal.a aVar3 = j$.time.temporal.a.ERA;
        if (!map.containsKey(aVar3)) {
            return null;
        }
        W(aVar3).b(((Long) map.get(aVar3)).longValue(), aVar3);
        return null;
    }

    ChronoLocalDate V(Map map, j$.time.format.G g6) {
        j$.time.temporal.a aVar = j$.time.temporal.a.YEAR;
        int iA = W(aVar).a(((Long) map.remove(aVar)).longValue(), aVar);
        if (g6 == j$.time.format.G.LENIENT) {
            long jSubtractExact = Math.subtractExact(((Long) map.remove(j$.time.temporal.a.MONTH_OF_YEAR)).longValue(), 1L);
            return G(iA, 1, 1).b(jSubtractExact, (j$.time.temporal.v) j$.time.temporal.b.MONTHS).b(Math.subtractExact(((Long) map.remove(j$.time.temporal.a.DAY_OF_MONTH)).longValue(), 1L), (j$.time.temporal.v) j$.time.temporal.b.DAYS);
        }
        j$.time.temporal.a aVar2 = j$.time.temporal.a.MONTH_OF_YEAR;
        int iA2 = W(aVar2).a(((Long) map.remove(aVar2)).longValue(), aVar2);
        j$.time.temporal.a aVar3 = j$.time.temporal.a.DAY_OF_MONTH;
        int iA3 = W(aVar3).a(((Long) map.remove(aVar3)).longValue(), aVar3);
        if (g6 != j$.time.format.G.SMART) {
            return G(iA, iA2, iA3);
        }
        try {
            return G(iA, iA2, iA3);
        } catch (j$.time.c unused) {
            return G(iA, iA2, 1).m(new j$.time.temporal.q(0));
        }
    }

    static ChronoLocalDate J(ChronoLocalDate chronoLocalDate, long j4, long j6, long j7) {
        long j8;
        ChronoLocalDate chronoLocalDateB = chronoLocalDate.b(j4, (j$.time.temporal.v) j$.time.temporal.b.MONTHS);
        j$.time.temporal.b bVar = j$.time.temporal.b.WEEKS;
        ChronoLocalDate chronoLocalDateB2 = chronoLocalDateB.b(j6, (j$.time.temporal.v) bVar);
        if (j7 > 7) {
            long j9 = j7 - 1;
            chronoLocalDateB2 = chronoLocalDateB2.b(j9 / 7, (j$.time.temporal.v) bVar);
            j8 = j9 % 7;
        } else {
            if (j7 < 1) {
                chronoLocalDateB2 = chronoLocalDateB2.b(Math.subtractExact(j7, 7L) / 7, (j$.time.temporal.v) bVar);
                j8 = (j7 + 6) % 7;
            }
            return chronoLocalDateB2.m(new j$.time.temporal.p(j$.time.e.r((int) j7).p(), 0));
        }
        j7 = j8 + 1;
        return chronoLocalDateB2.m(new j$.time.temporal.p(j$.time.e.r((int) j7).p(), 0));
    }

    static void p(Map map, j$.time.temporal.a aVar, long j4) {
        Long l = (Long) map.get(aVar);
        if (l != null && l.longValue() != j4) {
            throw new j$.time.c("Conflict found: " + aVar + " " + l + " differs from " + aVar + " " + j4);
        }
        map.put(aVar, Long.valueOf(j4));
    }

    @Override // j$.time.chrono.k
    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        return (obj instanceof AbstractC2282a) && s().compareTo(((AbstractC2282a) obj).s()) == 0;
    }

    @Override // j$.time.chrono.k
    public final int hashCode() {
        return getClass().hashCode() ^ s().hashCode();
    }

    @Override // j$.time.chrono.k
    public final String toString() {
        return s();
    }
}
