package p447;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import kotlin.TypeCastException;
import kotlin.jvm.internal.DefaultConstructorMarker;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.C6541;
import p402.InterfaceC6540;
import p402.p411.p413.C6626;
import p402.p411.p413.C6635;
import p402.p411.p413.p414.InterfaceC6650;
import p402.p417.C6659;
import p402.p417.C6664;
import p402.p420.C6703;
import p447.p448.C6943;

/* JADX INFO: renamed from: ސ.ޓ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C6905 implements Iterable<C6541<? extends String, ? extends String>>, InterfaceC6650 {

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public static final C6907 f20008 = new C6907(null);

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final String[] f20009;

    /* JADX INFO: renamed from: ސ.ޓ$֏, reason: contains not printable characters */
    public static final class C6906 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final List<String> f20010 = new ArrayList(20);

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C6906 m10071(String str) {
            if (str == null) {
                C6635.m9824("name");
                throw null;
            }
            int i = 0;
            while (i < this.f20010.size()) {
                if (C6703.m9905(str, this.f20010.get(i), true)) {
                    this.f20010.remove(i);
                    this.f20010.remove(i);
                    i -= 2;
                }
                i += 2;
            }
            return this;
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C6906 m10072(String str, String str2) {
            if (str == null) {
                C6635.m9824("name");
                throw null;
            }
            if (str2 == null) {
                C6635.m9824("value");
                throw null;
            }
            C6905.f20008.m10077(str);
            C6905.f20008.m10078(str2, str);
            m10074(str, str2);
            return this;
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C6905 m10073() {
            Object[] array = this.f20010.toArray(new String[0]);
            if (array != null) {
                return new C6905((String[]) array, null);
            }
            throw new TypeCastException("null cannot be cast to non-null type kotlin.Array<T>");
        }

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final C6906 m10074(String str, String str2) {
            if (str == null) {
                C6635.m9824("name");
                throw null;
            }
            if (str2 == null) {
                C6635.m9824("value");
                throw null;
            }
            this.f20010.add(str);
            this.f20010.add(C6703.m9900(str2).toString());
            return this;
        }

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final C6906 m10075(String str, String str2) {
            if (str == null) {
                C6635.m9824("name");
                throw null;
            }
            if (str2 == null) {
                C6635.m9824("value");
                throw null;
            }
            C6905.f20008.m10077(str);
            C6905.f20008.m10078(str2, str);
            m10071(str);
            m10074(str, str2);
            return this;
        }
    }

    /* JADX INFO: renamed from: ސ.ޓ$ؠ, reason: contains not printable characters */
    public static final class C6907 {
        public C6907() {
        }

        public /* synthetic */ C6907(DefaultConstructorMarker defaultConstructorMarker) {
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C6905 m10076(String... strArr) throws CloneNotSupportedException {
            DefaultConstructorMarker defaultConstructorMarker = null;
            if (strArr == null) {
                C6635.m9824("namesAndValues");
                throw null;
            }
            if (!(strArr.length % 2 == 0)) {
                throw new IllegalArgumentException("Expected alternating header names and values".toString());
            }
            Object objClone = strArr.clone();
            if (objClone == null) {
                throw new TypeCastException("null cannot be cast to non-null type kotlin.Array<kotlin.String>");
            }
            String[] strArr2 = (String[]) objClone;
            int length = strArr2.length;
            for (int i = 0; i < length; i++) {
                if (!(strArr2[i] != null)) {
                    throw new IllegalArgumentException("Headers cannot be null".toString());
                }
                String str = strArr2[i];
                if (str == null) {
                    throw new TypeCastException("null cannot be cast to non-null type kotlin.CharSequence");
                }
                strArr2[i] = C6703.m9900(str).toString();
            }
            C6659 c6659M9845 = C6664.m9845(C6664.m9846(0, strArr2.length), 2);
            int i2 = c6659M9845.f19412;
            int i3 = c6659M9845.f19413;
            int i4 = c6659M9845.f19414;
            if (i4 < 0 ? i2 >= i3 : i2 <= i3) {
                while (true) {
                    String str2 = strArr2[i2];
                    String str3 = strArr2[i2 + 1];
                    m10077(str2);
                    m10078(str3, str2);
                    if (i2 == i3) {
                        break;
                    }
                    i2 += i4;
                }
            }
            return new C6905(strArr2, defaultConstructorMarker);
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void m10077(String str) {
            if (!(str.length() > 0)) {
                throw new IllegalArgumentException("name is empty".toString());
            }
            int length = str.length();
            for (int i = 0; i < length; i++) {
                char cCharAt = str.charAt(i);
                if (!('!' <= cCharAt && '~' >= cCharAt)) {
                    throw new IllegalArgumentException(C6943.m10156("Unexpected char %#04x at %d in header name: %s", Integer.valueOf(cCharAt), Integer.valueOf(i), str).toString());
                }
            }
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void m10078(String str, String str2) {
            int length = str.length();
            for (int i = 0; i < length; i++) {
                char cCharAt = str.charAt(i);
                if (!(cCharAt == '\t' || (' ' <= cCharAt && '~' >= cCharAt))) {
                    throw new IllegalArgumentException(C6943.m10156("Unexpected char %#04x at %d in %s value: %s", Integer.valueOf(cCharAt), Integer.valueOf(i), str2, str).toString());
                }
            }
        }
    }

    public /* synthetic */ C6905(String[] strArr, DefaultConstructorMarker defaultConstructorMarker) {
        this.f20009 = strArr;
    }

    public boolean equals(Object obj) {
        return (obj instanceof C6905) && Arrays.equals(this.f20009, ((C6905) obj).f20009);
    }

    public int hashCode() {
        return Arrays.hashCode(this.f20009);
    }

    @Override // java.lang.Iterable
    public Iterator<C6541<? extends String, ? extends String>> iterator() {
        int size = size();
        C6541[] c6541Arr = new C6541[size];
        for (int i = 0; i < size; i++) {
            c6541Arr[i] = new C6541(m10068(i), m10070(i));
        }
        return new C6626(c6541Arr);
    }

    public final int size() {
        return this.f20009.length / 2;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        int size = size();
        for (int i = 0; i < size; i++) {
            sb.append(m10068(i));
            sb.append(": ");
            sb.append(m10070(i));
            sb.append("\n");
        }
        String string = sb.toString();
        C6635.m9823((Object) string, "StringBuilder().apply(builderAction).toString()");
        return string;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final String m10067(String str) {
        if (str == null) {
            C6635.m9824("name");
            throw null;
        }
        C6907 c6907 = f20008;
        String[] strArr = this.f20009;
        if (c6907 == null) {
            throw null;
        }
        C6659 c6659M9845 = C6664.m9845(C6664.m9844(strArr.length - 2, 0), 2);
        int i = c6659M9845.f19412;
        int i2 = c6659M9845.f19413;
        int i3 = c6659M9845.f19414;
        if (i3 >= 0) {
            if (i > i2) {
                return null;
            }
        } else if (i < i2) {
            return null;
        }
        while (!C6703.m9905(str, strArr[i], true)) {
            if (i == i2) {
                return null;
            }
            i += i3;
        }
        return strArr[i + 1];
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final String m10068(int i) {
        return this.f20009[i * 2];
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final C6906 m10069() {
        C6906 c6906 = new C6906();
        C4303.m7132((Collection) c6906.f20010, (Object[]) this.f20009);
        return c6906;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final String m10070(int i) {
        return this.f20009[(i * 2) + 1];
    }
}
