package k7;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes.dex */
public final class q {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final char[] f14120k = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final String f14121a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f14122b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f14123c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final String f14124d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int f14125e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final ArrayList f14126f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final ArrayList f14127g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final String f14128h;
    public final String i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final boolean f14129j;

    public q(String str, String str2, String str3, String str4, int i, ArrayList arrayList, ArrayList arrayList2, String str5, String str6) {
        P6.g.e(str, "scheme");
        P6.g.e(str4, "host");
        this.f14121a = str;
        this.f14122b = str2;
        this.f14123c = str3;
        this.f14124d = str4;
        this.f14125e = i;
        this.f14126f = arrayList;
        this.f14127g = arrayList2;
        this.f14128h = str5;
        this.i = str6;
        this.f14129j = str.equals("https");
    }

    public final String a() {
        if (this.f14123c.length() == 0) {
            return "";
        }
        int length = this.f14121a.length() + 3;
        String str = this.i;
        String strSubstring = str.substring(X6.e.S(str, ':', length, 4) + 1, X6.e.S(str, '@', 0, 6));
        P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public final String b() {
        int length = this.f14121a.length() + 3;
        String str = this.i;
        int iS = X6.e.S(str, '/', length, 4);
        String strSubstring = str.substring(iS, l7.b.g(str, iS, str.length(), "?#"));
        P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public final ArrayList c() {
        int length = this.f14121a.length() + 3;
        String str = this.i;
        int iS = X6.e.S(str, '/', length, 4);
        int iG = l7.b.g(str, iS, str.length(), "?#");
        ArrayList arrayList = new ArrayList();
        while (iS < iG) {
            int i = iS + 1;
            int iF = l7.b.f(str, '/', i, iG);
            String strSubstring = str.substring(i, iF);
            P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
            arrayList.add(strSubstring);
            iS = iF;
        }
        return arrayList;
    }

    public final String d() {
        if (this.f14127g == null) {
            return null;
        }
        String str = this.i;
        int iS = X6.e.S(str, '?', 0, 6) + 1;
        String strSubstring = str.substring(iS, l7.b.f(str, '#', iS, str.length()));
        P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public final String e() {
        if (this.f14122b.length() == 0) {
            return "";
        }
        int length = this.f14121a.length() + 3;
        String str = this.i;
        String strSubstring = str.substring(length, l7.b.g(str, length, str.length(), ":@"));
        P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

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

    public final p f(String str) {
        P6.g.e(str, "link");
        try {
            p pVar = new p();
            pVar.c(this, str);
            return pVar;
        } catch (IllegalArgumentException unused) {
            return null;
        }
    }

    public final String g() {
        p pVarF = f("/...");
        P6.g.b(pVarF);
        pVarF.f14113b = l.b("", 0, 0, " \"':;<=>@[]^`{}|/\\?#", 251);
        pVarF.f14114c = l.b("", 0, 0, " \"':;<=>@[]^`{}|/\\?#", 251);
        return pVarF.a().i;
    }

    public final URI h() {
        String strSubstring;
        String strReplaceAll;
        p pVar = new p();
        String str = this.f14121a;
        pVar.f14112a = str;
        pVar.f14113b = e();
        pVar.f14114c = a();
        pVar.f14115d = this.f14124d;
        P6.g.e(str, "scheme");
        int i = str.equals("http") ? 80 : str.equals("https") ? 443 : -1;
        int i5 = this.f14125e;
        pVar.f14116e = i5 != i ? i5 : -1;
        ArrayList arrayList = pVar.f14117f;
        arrayList.clear();
        arrayList.addAll(c());
        String strD = d();
        pVar.f14118g = strD != null ? l.g(l.b(strD, 0, 0, " \"'<>#", 211)) : null;
        if (this.f14128h == null) {
            strSubstring = null;
        } else {
            String str2 = this.i;
            strSubstring = str2.substring(X6.e.S(str2, '#', 0, 6) + 1);
            P6.g.d(strSubstring, "this as java.lang.String).substring(startIndex)");
        }
        pVar.f14119h = strSubstring;
        String str3 = pVar.f14115d;
        if (str3 != null) {
            Pattern patternCompile = Pattern.compile("[\"<>^`{|}]");
            P6.g.d(patternCompile, "compile(...)");
            strReplaceAll = patternCompile.matcher(str3).replaceAll("");
            P6.g.d(strReplaceAll, "replaceAll(...)");
        } else {
            strReplaceAll = null;
        }
        pVar.f14115d = strReplaceAll;
        int size = arrayList.size();
        for (int i8 = 0; i8 < size; i8++) {
            arrayList.set(i8, l.b((String) arrayList.get(i8), 0, 0, "[]", 227));
        }
        ArrayList arrayList2 = pVar.f14118g;
        if (arrayList2 != null) {
            int size2 = arrayList2.size();
            for (int i9 = 0; i9 < size2; i9++) {
                String str4 = (String) arrayList2.get(i9);
                arrayList2.set(i9, str4 != null ? l.b(str4, 0, 0, "\\^`{|}", 195) : null);
            }
        }
        String str5 = pVar.f14119h;
        pVar.f14119h = str5 != null ? l.b(str5, 0, 0, " \"#<>\\^`{|}", 163) : null;
        String string = pVar.toString();
        try {
            return new URI(string);
        } catch (URISyntaxException e8) {
            try {
                Pattern patternCompile2 = Pattern.compile("[\\u0000-\\u001F\\u007F-\\u009F\\p{javaWhitespace}]");
                P6.g.d(patternCompile2, "compile(...)");
                String strReplaceAll2 = patternCompile2.matcher(string).replaceAll("");
                P6.g.d(strReplaceAll2, "replaceAll(...)");
                URI uriCreate = URI.create(strReplaceAll2);
                P6.g.d(uriCreate, "{\n      // Unlikely edge…Unexpected!\n      }\n    }");
                return uriCreate;
            } catch (Exception unused) {
                throw new RuntimeException(e8);
            }
        }
    }

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

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