package XnFJ5_9;

import com.wang.avi.BuildConfig;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.Nullable;
/* compiled from: Headers.java */
/* loaded from: classes.dex */
public final class SI64pbG_23 {
    public final String[] KQgRr5e_0;

    public SI64pbG_23(KQgRr5e_0 kQgRr5e_0) {
        List<String> list = kQgRr5e_0.KQgRr5e_0;
        this.KQgRr5e_0 = (String[]) list.toArray(new String[list.size()]);
    }

    @Nullable
    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public String m769KQgRr5e_0(String str) {
        return KQgRr5e_0(this.KQgRr5e_0, str);
    }

    public String QxJ9d_1(int i) {
        return this.KQgRr5e_0[(i * 2) + 1];
    }

    public boolean equals(@Nullable Object obj) {
        return (obj instanceof SI64pbG_23) && Arrays.equals(((SI64pbG_23) obj).KQgRr5e_0, this.KQgRr5e_0);
    }

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

    public String toString() {
        StringBuilder sb = new StringBuilder();
        int KQgRr5e_02 = KQgRr5e_0();
        for (int i = 0; i < KQgRr5e_02; i++) {
            sb.append(KQgRr5e_0(i));
            sb.append(": ");
            sb.append(QxJ9d_1(i));
            sb.append("\n");
        }
        return sb.toString();
    }

    /* compiled from: Headers.java */
    /* loaded from: classes.dex */
    public static final class KQgRr5e_0 {
        public final List<String> KQgRr5e_0 = new ArrayList(20);

        public KQgRr5e_0 KQgRr5e_0(String str) {
            int indexOf = str.indexOf(":", 1);
            if (indexOf != -1) {
                QxJ9d_1(str.substring(0, indexOf), str.substring(indexOf + 1));
                return this;
            } else if (str.startsWith(":")) {
                QxJ9d_1(BuildConfig.FLAVOR, str.substring(1));
                return this;
            } else {
                QxJ9d_1(BuildConfig.FLAVOR, str);
                return this;
            }
        }

        public KQgRr5e_0 PGPF6hQ_2(String str, String str2) {
            SI64pbG_23.KQgRr5e_0(str);
            SI64pbG_23.KQgRr5e_0(str2, str);
            QxJ9d_1(str);
            QxJ9d_1(str, str2);
            return this;
        }

        public KQgRr5e_0 QxJ9d_1(String str, String str2) {
            this.KQgRr5e_0.add(str);
            this.KQgRr5e_0.add(str2.trim());
            return this;
        }

        public KQgRr5e_0 QxJ9d_1(String str) {
            int i = 0;
            while (i < this.KQgRr5e_0.size()) {
                if (str.equalsIgnoreCase(this.KQgRr5e_0.get(i))) {
                    this.KQgRr5e_0.remove(i);
                    this.KQgRr5e_0.remove(i);
                    i -= 2;
                }
                i += 2;
            }
            return this;
        }

        public KQgRr5e_0 KQgRr5e_0(String str, String str2) {
            SI64pbG_23.KQgRr5e_0(str);
            SI64pbG_23.KQgRr5e_0(str2, str);
            QxJ9d_1(str, str2);
            return this;
        }

        public SI64pbG_23 KQgRr5e_0() {
            return new SI64pbG_23(this);
        }
    }

    public int KQgRr5e_0() {
        return this.KQgRr5e_0.length / 2;
    }

    public SI64pbG_23(String[] strArr) {
        this.KQgRr5e_0 = strArr;
    }

    public String KQgRr5e_0(int i) {
        return this.KQgRr5e_0[i * 2];
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public List<String> m770KQgRr5e_0(String str) {
        int KQgRr5e_02 = KQgRr5e_0();
        ArrayList arrayList = null;
        for (int i = 0; i < KQgRr5e_02; i++) {
            if (str.equalsIgnoreCase(KQgRr5e_0(i))) {
                if (arrayList == null) {
                    arrayList = new ArrayList(2);
                }
                arrayList.add(QxJ9d_1(i));
            }
        }
        if (arrayList != null) {
            return Collections.unmodifiableList(arrayList);
        }
        return Collections.emptyList();
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public KQgRr5e_0 m768KQgRr5e_0() {
        KQgRr5e_0 kQgRr5e_0 = new KQgRr5e_0();
        Collections.addAll(kQgRr5e_0.KQgRr5e_0, this.KQgRr5e_0);
        return kQgRr5e_0;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public Map<String, List<String>> m771KQgRr5e_0() {
        TreeMap treeMap = new TreeMap(String.CASE_INSENSITIVE_ORDER);
        int KQgRr5e_02 = KQgRr5e_0();
        for (int i = 0; i < KQgRr5e_02; i++) {
            String lowerCase = KQgRr5e_0(i).toLowerCase(Locale.US);
            List list = (List) treeMap.get(lowerCase);
            if (list == null) {
                list = new ArrayList(2);
                treeMap.put(lowerCase, list);
            }
            list.add(QxJ9d_1(i));
        }
        return treeMap;
    }

    @Nullable
    public static String KQgRr5e_0(String[] strArr, String str) {
        for (int length = strArr.length - 2; length >= 0; length -= 2) {
            if (str.equalsIgnoreCase(strArr[length])) {
                return strArr[length + 1];
            }
        }
        return null;
    }

    public static SI64pbG_23 KQgRr5e_0(String... strArr) {
        if (strArr != null) {
            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];
                    KQgRr5e_0(str);
                    KQgRr5e_0(str2, str);
                }
                return new SI64pbG_23(strArr2);
            }
            throw new IllegalArgumentException("Expected alternating header names and values");
        }
        throw new NullPointerException("namesAndValues == null");
    }

    public static void KQgRr5e_0(String str) {
        if (str != null) {
            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(XnFJ5_9.Ft6VRog_36.X6FRs_4.KQgRr5e_0("Unexpected char %#04x at %d in header name: %s", Integer.valueOf(charAt), Integer.valueOf(i), str));
                    }
                }
                return;
            }
            throw new IllegalArgumentException("name is empty");
        }
        throw new NullPointerException("name == null");
    }

    public static void KQgRr5e_0(String str, String str2) {
        if (str != null) {
            int length = str.length();
            for (int i = 0; i < length; i++) {
                char charAt = str.charAt(i);
                if ((charAt <= 31 && charAt != '\t') || charAt >= 127) {
                    throw new IllegalArgumentException(XnFJ5_9.Ft6VRog_36.X6FRs_4.KQgRr5e_0("Unexpected char %#04x at %d in %s value: %s", Integer.valueOf(charAt), Integer.valueOf(i), str2, str));
                }
            }
            return;
        }
        throw new NullPointerException("value for name " + str2 + " == null");
    }
}
