package o;

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;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.pu0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2193pu0 extends AbstractMap {
    public Object[] l;
    public int m;
    public Map n;

    /* renamed from: o, reason: collision with root package name */
    public boolean f682o;
    public volatile C1364h9 p;
    public Map q;

    public C2193pu0() {
        Map map = Collections.EMPTY_MAP;
        this.n = map;
        this.q = map;
    }

    public final C2288qu0 a(int i) {
        if (i < this.m) {
            return (C2288qu0) this.l[i];
        }
        throw new ArrayIndexOutOfBoundsException(i);
    }

    public final Set b() {
        return this.n.isEmpty() ? Collections.EMPTY_SET : this.n.entrySet();
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* renamed from: c, reason: merged with bridge method [inline-methods] */
    public final Object put(Comparable comparable, Object obj) {
        f();
        int iE = e(comparable);
        if (iE >= 0) {
            return ((C2288qu0) this.l[iE]).setValue(obj);
        }
        f();
        if (this.l == null) {
            this.l = new Object[16];
        }
        int i = -(iE + 1);
        if (i >= 16) {
            return g().put(comparable, obj);
        }
        if (this.m == 16) {
            C2288qu0 c2288qu0 = (C2288qu0) this.l[15];
            this.m = 15;
            g().put(c2288qu0.l, c2288qu0.m);
        }
        Object[] objArr = this.l;
        int length = objArr.length;
        System.arraycopy(objArr, i, objArr, i + 1, 15 - i);
        this.l[i] = new C2288qu0(this, comparable, obj);
        this.m++;
        return null;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final void clear() {
        f();
        if (this.m != 0) {
            this.l = null;
            this.m = 0;
        }
        if (this.n.isEmpty()) {
            return;
        }
        this.n.clear();
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final boolean containsKey(Object obj) {
        Comparable comparable = (Comparable) obj;
        return e(comparable) >= 0 || this.n.containsKey(comparable);
    }

    public final Object d(int i) {
        f();
        Object[] objArr = this.l;
        Object obj = ((C2288qu0) objArr[i]).m;
        System.arraycopy(objArr, i + 1, objArr, i, (this.m - i) - 1);
        this.m--;
        if (!this.n.isEmpty()) {
            Iterator it = g().entrySet().iterator();
            Object[] objArr2 = this.l;
            int i2 = this.m;
            Map.Entry entry = (Map.Entry) it.next();
            objArr2[i2] = new C2288qu0(this, (Comparable) entry.getKey(), entry.getValue());
            this.m++;
            it.remove();
        }
        return obj;
    }

    public final int e(Comparable comparable) {
        int i = this.m;
        int i2 = i - 1;
        int i3 = 0;
        if (i2 >= 0) {
            int iCompareTo = comparable.compareTo(((C2288qu0) this.l[i2]).l);
            if (iCompareTo > 0) {
                return -(i + 1);
            }
            if (iCompareTo == 0) {
                return i2;
            }
        }
        while (i3 <= i2) {
            int i4 = (i3 + i2) / 2;
            int iCompareTo2 = comparable.compareTo(((C2288qu0) this.l[i4]).l);
            if (iCompareTo2 < 0) {
                i2 = i4 - 1;
            } else {
                if (iCompareTo2 <= 0) {
                    return i4;
                }
                i3 = i4 + 1;
            }
        }
        return -(i3 + 1);
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Set entrySet() {
        if (this.p == null) {
            this.p = new C1364h9(this, 2);
        }
        return this.p;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof C2193pu0)) {
            return super.equals(obj);
        }
        C2193pu0 c2193pu0 = (C2193pu0) obj;
        int size = size();
        if (size == c2193pu0.size()) {
            int i = this.m;
            if (i != c2193pu0.m) {
                return entrySet().equals(c2193pu0.entrySet());
            }
            for (int i2 = 0; i2 < i; i2++) {
                if (a(i2).equals(c2193pu0.a(i2))) {
                }
            }
            if (i != size) {
                return this.n.equals(c2193pu0.n);
            }
            return true;
        }
        return false;
    }

    public final void f() {
        if (this.f682o) {
            throw new UnsupportedOperationException();
        }
    }

    public final SortedMap g() {
        f();
        if (this.n.isEmpty() && !(this.n instanceof TreeMap)) {
            TreeMap treeMap = new TreeMap();
            this.n = treeMap;
            this.q = treeMap.descendingMap();
        }
        return (SortedMap) this.n;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Object get(Object obj) {
        Comparable comparable = (Comparable) obj;
        int iE = e(comparable);
        return iE >= 0 ? ((C2288qu0) this.l[iE]).m : this.n.get(comparable);
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final int hashCode() {
        int i = this.m;
        int iHashCode = 0;
        for (int i2 = 0; i2 < i; i2++) {
            iHashCode += this.l[i2].hashCode();
        }
        return this.n.size() > 0 ? this.n.hashCode() + iHashCode : iHashCode;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Object remove(Object obj) {
        f();
        Comparable comparable = (Comparable) obj;
        int iE = e(comparable);
        if (iE >= 0) {
            return d(iE);
        }
        if (this.n.isEmpty()) {
            return null;
        }
        return this.n.remove(comparable);
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final int size() {
        return this.n.size() + this.m;
    }
}
