package com.google.android.gms.internal.ads;

import java.util.AbstractMap;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

/* JADX INFO: loaded from: classes2.dex */
public final class kc2 extends AbstractMap {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Object[] f13219a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f13220b;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f13222d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public volatile sr1 f13223e;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Map f13221c = Collections.emptyMap();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Map f13224f = Collections.emptyMap();

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
    public final void clear() {
        q();
        if (this.f13220b != 0) {
            this.f13219a = null;
            this.f13220b = 0;
        }
        if (this.f13221c.isEmpty()) {
            return;
        }
        this.f13221c.clear();
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
    public final boolean containsKey(Object obj) {
        Comparable comparable = (Comparable) obj;
        return p(comparable) >= 0 || this.f13221c.containsKey(comparable);
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: d, reason: merged with bridge method [inline-methods] */
    public final Set entrySet() {
        if (this.f13223e == null) {
            this.f13223e = new sr1(this);
        }
        return this.f13223e;
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: e, reason: merged with bridge method [inline-methods] */
    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof kc2)) {
            return super.equals(obj);
        }
        kc2 kc2Var = (kc2) obj;
        int size = size();
        if (size != kc2Var.size()) {
            return false;
        }
        int i10 = this.f13220b;
        if (i10 != kc2Var.f13220b) {
            return entrySet().equals(kc2Var.entrySet());
        }
        for (int i11 = 0; i11 < i10; i11++) {
            if (!l(i11).equals(kc2Var.l(i11))) {
                return false;
            }
        }
        if (i10 != size) {
            return this.f13221c.equals(kc2Var.f13221c);
        }
        return true;
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: g, reason: merged with bridge method [inline-methods] */
    public final Object get(Object obj) {
        Comparable comparable = (Comparable) obj;
        int iP = p(comparable);
        return iP >= 0 ? ((lc2) this.f13219a[iP]).f13632b : this.f13221c.get(comparable);
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: i, reason: merged with bridge method [inline-methods] */
    public final int hashCode() {
        int i10 = this.f13220b;
        int iHashCode = 0;
        for (int i11 = 0; i11 < i10; i11++) {
            iHashCode += this.f13219a[i11].hashCode();
        }
        return this.f13221c.size() > 0 ? this.f13221c.hashCode() + iHashCode : iHashCode;
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: j, reason: merged with bridge method [inline-methods] */
    public final Object remove(Object obj) {
        q();
        Comparable comparable = (Comparable) obj;
        int iP = p(comparable);
        if (iP >= 0) {
            return o(iP);
        }
        if (this.f13221c.isEmpty()) {
            return null;
        }
        return this.f13221c.remove(comparable);
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: k, reason: merged with bridge method [inline-methods] */
    public final int size() {
        return this.f13221c.size() + this.f13220b;
    }

    public final lc2 l(int i10) {
        if (i10 < this.f13220b) {
            return (lc2) this.f13219a[i10];
        }
        throw new ArrayIndexOutOfBoundsException(i10);
    }

    public final Set m() {
        return this.f13221c.isEmpty() ? Collections.emptySet() : this.f13221c.entrySet();
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: n, reason: merged with bridge method [inline-methods] */
    public final Object put(Comparable comparable, Object obj) {
        q();
        int iP = p(comparable);
        if (iP >= 0) {
            return ((lc2) this.f13219a[iP]).setValue(obj);
        }
        q();
        if (this.f13219a == null) {
            this.f13219a = new Object[16];
        }
        int i10 = -(iP + 1);
        if (i10 >= 16) {
            return r().put(comparable, obj);
        }
        if (this.f13220b == 16) {
            lc2 lc2Var = (lc2) this.f13219a[15];
            this.f13220b = 15;
            r().put(lc2Var.f13631a, lc2Var.f13632b);
        }
        Object[] objArr = this.f13219a;
        int length = objArr.length;
        System.arraycopy(objArr, i10, objArr, i10 + 1, 15 - i10);
        this.f13219a[i10] = new lc2(this, comparable, obj);
        this.f13220b++;
        return null;
    }

    public final Object o(int i10) {
        q();
        Object[] objArr = this.f13219a;
        Object obj = ((lc2) objArr[i10]).f13632b;
        System.arraycopy(objArr, i10 + 1, objArr, i10, (this.f13220b - i10) - 1);
        this.f13220b--;
        if (!this.f13221c.isEmpty()) {
            Iterator it = r().entrySet().iterator();
            Object[] objArr2 = this.f13219a;
            int i11 = this.f13220b;
            Map.Entry entry = (Map.Entry) it.next();
            objArr2[i11] = new lc2(this, (Comparable) entry.getKey(), entry.getValue());
            this.f13220b++;
            it.remove();
        }
        return obj;
    }

    public final int p(Comparable comparable) {
        int i10 = this.f13220b;
        int i11 = i10 - 1;
        int i12 = 0;
        if (i11 >= 0) {
            int iCompareTo = comparable.compareTo(((lc2) this.f13219a[i11]).f13631a);
            if (iCompareTo > 0) {
                return -(i10 + 1);
            }
            if (iCompareTo == 0) {
                return i11;
            }
        }
        while (i12 <= i11) {
            int i13 = (i12 + i11) / 2;
            int iCompareTo2 = comparable.compareTo(((lc2) this.f13219a[i13]).f13631a);
            if (iCompareTo2 < 0) {
                i11 = i13 - 1;
            } else {
                if (iCompareTo2 <= 0) {
                    return i13;
                }
                i12 = i13 + 1;
            }
        }
        return -(i12 + 1);
    }

    public final void q() {
        if (this.f13222d) {
            throw new UnsupportedOperationException();
        }
    }

    public final SortedMap r() {
        q();
        if (this.f13221c.isEmpty() && !(this.f13221c instanceof TreeMap)) {
            TreeMap treeMap = new TreeMap();
            this.f13221c = treeMap;
            this.f13224f = treeMap.descendingMap();
        }
        return (SortedMap) this.f13221c;
    }
}
