package x7;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
public final class x implements Comparable {

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static final String f18797r;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final C1734j f18798q;

    static {
        String str = File.separator;
        P6.g.d(str, "separator");
        f18797r = str;
    }

    public x(C1734j c1734j) {
        P6.g.e(c1734j, "bytes");
        this.f18798q = c1734j;
    }

    public final ArrayList a() {
        ArrayList arrayList = new ArrayList();
        int iA = y7.c.a(this);
        C1734j c1734j = this.f18798q;
        if (iA == -1) {
            iA = 0;
        } else if (iA < c1734j.c() && c1734j.h(iA) == 92) {
            iA++;
        }
        int iC = c1734j.c();
        int i = iA;
        while (iA < iC) {
            if (c1734j.h(iA) == 47 || c1734j.h(iA) == 92) {
                arrayList.add(c1734j.m(i, iA));
                i = iA + 1;
            }
            iA++;
        }
        if (i < c1734j.c()) {
            arrayList.add(c1734j.m(i, c1734j.c()));
        }
        return arrayList;
    }

    public final String b() {
        C1734j c1734j = y7.c.f19041a;
        C1734j c1734j2 = y7.c.f19041a;
        C1734j c1734jN = this.f18798q;
        int iJ = C1734j.j(c1734jN, c1734j2);
        if (iJ == -1) {
            iJ = C1734j.j(c1734jN, y7.c.f19042b);
        }
        if (iJ != -1) {
            c1734jN = C1734j.n(c1734jN, iJ + 1, 0, 2);
        } else if (h() != null && c1734jN.c() == 2) {
            c1734jN = C1734j.f18766t;
        }
        return c1734jN.p();
    }

    public final x c() {
        C1734j c1734j = y7.c.f19044d;
        C1734j c1734j2 = this.f18798q;
        if (P6.g.a(c1734j2, c1734j)) {
            return null;
        }
        C1734j c1734j3 = y7.c.f19041a;
        if (P6.g.a(c1734j2, c1734j3)) {
            return null;
        }
        C1734j c1734j4 = y7.c.f19042b;
        if (P6.g.a(c1734j2, c1734j4)) {
            return null;
        }
        C1734j c1734j5 = y7.c.f19045e;
        c1734j2.getClass();
        P6.g.e(c1734j5, "suffix");
        int iC = c1734j2.c();
        byte[] bArr = c1734j5.f18767q;
        if (c1734j2.l(iC - bArr.length, c1734j5, bArr.length) && (c1734j2.c() == 2 || c1734j2.l(c1734j2.c() - 3, c1734j3, 1) || c1734j2.l(c1734j2.c() - 3, c1734j4, 1))) {
            return null;
        }
        int iJ = C1734j.j(c1734j2, c1734j3);
        if (iJ == -1) {
            iJ = C1734j.j(c1734j2, c1734j4);
        }
        if (iJ == 2 && h() != null) {
            if (c1734j2.c() == 3) {
                return null;
            }
            return new x(C1734j.n(c1734j2, 0, 3, 1));
        }
        if (iJ == 1) {
            P6.g.e(c1734j4, "prefix");
            if (c1734j2.l(0, c1734j4, c1734j4.c())) {
                return null;
            }
        }
        if (iJ != -1 || h() == null) {
            return iJ == -1 ? new x(c1734j) : iJ == 0 ? new x(C1734j.n(c1734j2, 0, 1, 1)) : new x(C1734j.n(c1734j2, 0, iJ, 1));
        }
        if (c1734j2.c() == 2) {
            return null;
        }
        return new x(C1734j.n(c1734j2, 0, 2, 1));
    }

    @Override // java.lang.Comparable
    public final int compareTo(Object obj) {
        x xVar = (x) obj;
        P6.g.e(xVar, "other");
        return this.f18798q.compareTo(xVar.f18798q);
    }

    public final x d(x xVar) {
        P6.g.e(xVar, "other");
        int iA = y7.c.a(this);
        C1734j c1734j = this.f18798q;
        x xVar2 = iA == -1 ? null : new x(c1734j.m(0, iA));
        int iA2 = y7.c.a(xVar);
        C1734j c1734j2 = xVar.f18798q;
        if (!P6.g.a(xVar2, iA2 != -1 ? new x(c1734j2.m(0, iA2)) : null)) {
            throw new IllegalArgumentException(("Paths of different roots cannot be relative to each other: " + this + " and " + xVar).toString());
        }
        ArrayList arrayListA = a();
        ArrayList arrayListA2 = xVar.a();
        int iMin = Math.min(arrayListA.size(), arrayListA2.size());
        int i = 0;
        while (i < iMin && P6.g.a(arrayListA.get(i), arrayListA2.get(i))) {
            i++;
        }
        if (i == iMin && c1734j.c() == c1734j2.c()) {
            return d3.C.j(".", false);
        }
        if (arrayListA2.subList(i, arrayListA2.size()).indexOf(y7.c.f19045e) != -1) {
            throw new IllegalArgumentException(("Impossible relative path to resolve: " + this + " and " + xVar).toString());
        }
        C1731g c1731g = new C1731g();
        C1734j c1734jC = y7.c.c(xVar);
        if (c1734jC == null && (c1734jC = y7.c.c(this)) == null) {
            c1734jC = y7.c.f(f18797r);
        }
        int size = arrayListA2.size();
        for (int i5 = i; i5 < size; i5++) {
            c1731g.r0(y7.c.f19045e);
            c1731g.r0(c1734jC);
        }
        int size2 = arrayListA.size();
        while (i < size2) {
            c1731g.r0((C1734j) arrayListA.get(i));
            c1731g.r0(c1734jC);
            i++;
        }
        return y7.c.d(c1731g, false);
    }

    public final x e(String str) {
        P6.g.e(str, "child");
        C1731g c1731g = new C1731g();
        c1731g.z0(str);
        return y7.c.b(this, y7.c.d(c1731g, false), false);
    }

    public final boolean equals(Object obj) {
        return (obj instanceof x) && P6.g.a(((x) obj).f18798q, this.f18798q);
    }

    public final File f() {
        return new File(this.f18798q.p());
    }

    public final Path g() {
        Path path = Paths.get(this.f18798q.p(), new String[0]);
        P6.g.d(path, "get(...)");
        return path;
    }

    public final Character h() {
        C1734j c1734j = y7.c.f19041a;
        C1734j c1734j2 = this.f18798q;
        if (C1734j.f(c1734j2, c1734j) != -1 || c1734j2.c() < 2 || c1734j2.h(1) != 58) {
            return null;
        }
        char cH = (char) c1734j2.h(0);
        if (('a' > cH || cH >= '{') && ('A' > cH || cH >= '[')) {
            return null;
        }
        return Character.valueOf(cH);
    }

    public final int hashCode() {
        return this.f18798q.hashCode();
    }

    public final String toString() {
        return this.f18798q.p();
    }
}
