package 㿎;

import com.facebook.internal.security.CertificateUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import ඓ.K.K.K.C1293;
import 㿎.ሽ.C2540;

/* renamed from: 㿎.䀟  reason: contains not printable characters */
/* compiled from: Headers */
public final class C2667 {

    /* renamed from: K  reason: contains not printable characters */
    public final String[] f9080;

    public C2667(C2668 k) {
        List<String> list = k.f9081;
        this.f9080 = (String[]) list.toArray(new String[list.size()]);
    }

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

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

    public String toString() {
        StringBuilder sb = new StringBuilder();
        int r1 = m6993();
        for (int i = 0; i < r1; i++) {
            sb.append(m6995(i));
            sb.append(": ");
            sb.append(m6994(i));
            sb.append("\n");
        }
        return sb.toString();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public int m6993() {
        return this.f9080.length / 2;
    }

    /* renamed from: K  reason: contains not printable characters */
    public String m6996(String str) {
        String[] strArr = this.f9080;
        int length = strArr.length;
        do {
            length -= 2;
            if (length < 0) {
                return null;
            }
        } while (!str.equalsIgnoreCase(strArr[length]));
        return strArr[length + 1];
    }

    /* renamed from: 㿎.䀟$K  reason: contains not printable characters */
    /* compiled from: Headers */
    public static final class C2668 {

        /* renamed from: K  reason: contains not printable characters */
        public final List<String> f9081 = new ArrayList(20);

        /* renamed from: ʬ  reason: contains not printable characters */
        public final void m6998(String str, String str2) {
            if (str == null) {
                throw new NullPointerException("name == null");
            } else if (!str.isEmpty()) {
                int length = str.length();
                for (int i = 0; i < length; i++) {
                    char charAt = str.charAt(i);
                    if (charAt <= ' ' || charAt >= 127) {
                        throw new IllegalArgumentException(C2540.m6642("Unexpected char %#04x at %d in header name: %s", Integer.valueOf(charAt), Integer.valueOf(i), str));
                    }
                }
                if (str2 != null) {
                    int length2 = str2.length();
                    for (int i2 = 0; i2 < length2; i2++) {
                        char charAt2 = str2.charAt(i2);
                        if ((charAt2 <= 31 && charAt2 != '\t') || charAt2 >= 127) {
                            throw new IllegalArgumentException(C2540.m6642("Unexpected char %#04x at %d in %s value: %s", Integer.valueOf(charAt2), Integer.valueOf(i2), str, str2));
                        }
                    }
                    return;
                }
                throw new NullPointerException(C1293.m3413("value for name ", str, " == null"));
            } else {
                throw new IllegalArgumentException("name is empty");
            }
        }

        /* renamed from: ῲ  reason: contains not printable characters */
        public C2668 m7000(String str, String str2) {
            this.f9081.add(str);
            this.f9081.add(str2.trim());
            return this;
        }

        /* renamed from: K  reason: contains not printable characters */
        public C2668 m7001(String str) {
            int indexOf = str.indexOf(CertificateUtil.DELIMITER, 1);
            if (indexOf != -1) {
                m7000(str.substring(0, indexOf), str.substring(indexOf + 1));
                return this;
            } else if (str.startsWith(CertificateUtil.DELIMITER)) {
                String substring = str.substring(1);
                this.f9081.add("");
                this.f9081.add(substring.trim());
                return this;
            } else {
                this.f9081.add("");
                this.f9081.add(str.trim());
                return this;
            }
        }

        /* renamed from: ῲ  reason: contains not printable characters */
        public C2668 m6999(String str) {
            int i = 0;
            while (i < this.f9081.size()) {
                if (str.equalsIgnoreCase(this.f9081.get(i))) {
                    this.f9081.remove(i);
                    this.f9081.remove(i);
                    i -= 2;
                }
                i += 2;
            }
            return this;
        }

        /* renamed from: K  reason: contains not printable characters */
        public C2668 m7002(String str, String str2) {
            m6998(str, str2);
            this.f9081.add(str);
            this.f9081.add(str2.trim());
            return this;
        }

        /* renamed from: K  reason: contains not printable characters */
        public C2667 m7003() {
            return new C2667(this);
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public String m6994(int i) {
        return this.f9080[(i * 2) + 1];
    }

    public C2667(String[] strArr) {
        this.f9080 = strArr;
    }

    /* renamed from: K  reason: contains not printable characters */
    public String m6995(int i) {
        return this.f9080[i * 2];
    }

    /* renamed from: K  reason: contains not printable characters */
    public C2668 m6997() {
        C2668 k = new C2668();
        Collections.addAll(k.f9081, this.f9080);
        return k;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static C2667 m6992(String... strArr) {
        if (strArr == null) {
            throw new NullPointerException("namesAndValues == null");
        } else if (strArr.length % 2 == 0) {
            String[] strArr2 = (String[]) strArr.clone();
            for (int i = 0; i < strArr2.length; i++) {
                if (strArr2[i] != null) {
                    strArr2[i] = strArr2[i].trim();
                } else {
                    throw new IllegalArgumentException("Headers cannot be null");
                }
            }
            for (int i2 = 0; i2 < strArr2.length; i2 += 2) {
                String str = strArr2[i2];
                String str2 = strArr2[i2 + 1];
                if (str.length() == 0 || str.indexOf(0) != -1 || str2.indexOf(0) != -1) {
                    throw new IllegalArgumentException("Unexpected header: " + str + ": " + str2);
                }
            }
            return new C2667(strArr2);
        } else {
            throw new IllegalArgumentException("Expected alternating header names and values");
        }
    }
}
