package com.google.protobuf;

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

/* JADX INFO: loaded from: classes3.dex */
public final class L0 extends AbstractMap {

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final /* synthetic */ int f14210j = 0;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final int f14211a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public List f14212b = Collections.EMPTY_LIST;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Map f14213c;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public volatile androidx.datastore.preferences.protobuf.f0 f14215e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Map f14216f;

    public L0(int i6) {
        this.f14211a = i6;
        Map map = Collections.EMPTY_MAP;
        this.f14213c = map;
        this.f14216f = map;
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0024  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int a(Comparable comparable) {
        int i6;
        int i7;
        int size = this.f14212b.size();
        int i8 = size - 1;
        if (i8 < 0) {
            i6 = 0;
            while (i6 <= i8) {
                int i9 = (i6 + i8) / 2;
                int iCompareTo = comparable.compareTo(((P0) this.f14212b.get(i9)).f14222a);
                if (iCompareTo < 0) {
                    i8 = i9 - 1;
                } else {
                    if (iCompareTo <= 0) {
                        return i9;
                    }
                    i6 = i9 + 1;
                }
            }
            i7 = i6 + 1;
        } else {
            int iCompareTo2 = comparable.compareTo(((P0) this.f14212b.get(i8)).f14222a);
            if (iCompareTo2 > 0) {
                i7 = size + 1;
            } else {
                if (iCompareTo2 == 0) {
                    return i8;
                }
                i6 = 0;
                while (i6 <= i8) {
                }
                i7 = i6 + 1;
            }
        }
        return -i7;
    }

    public final void b() {
        if (this.f14214d) {
            throw new UnsupportedOperationException();
        }
    }

    public final Map.Entry c(int i6) {
        return (Map.Entry) this.f14212b.get(i6);
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final void clear() {
        b();
        if (!this.f14212b.isEmpty()) {
            this.f14212b.clear();
        }
        if (this.f14213c.isEmpty()) {
            return;
        }
        this.f14213c.clear();
    }

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

    public final Iterable d() {
        return this.f14213c.isEmpty() ? O0.f14218b : this.f14213c.entrySet();
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Set entrySet() {
        if (this.f14215e == null) {
            this.f14215e = new androidx.datastore.preferences.protobuf.f0(1, this);
        }
        return this.f14215e;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof L0)) {
            return super.equals(obj);
        }
        L0 l02 = (L0) obj;
        int size = size();
        if (size == l02.size()) {
            int size2 = this.f14212b.size();
            if (size2 != l02.f14212b.size()) {
                return ((AbstractSet) entrySet()).equals(l02.entrySet());
            }
            for (int i6 = 0; i6 < size2; i6++) {
                if (c(i6).equals(l02.c(i6))) {
                }
            }
            if (size2 != size) {
                return this.f14213c.equals(l02.f14213c);
            }
            return true;
        }
        return false;
    }

    public final SortedMap f() {
        b();
        if (this.f14213c.isEmpty() && !(this.f14213c instanceof TreeMap)) {
            TreeMap treeMap = new TreeMap();
            this.f14213c = treeMap;
            this.f14216f = treeMap.descendingMap();
        }
        return (SortedMap) this.f14213c;
    }

    @Override // java.util.AbstractMap, java.util.Map
    /* JADX INFO: renamed from: g, reason: merged with bridge method [inline-methods] */
    public final Object put(Comparable comparable, Object obj) {
        b();
        int iA = a(comparable);
        if (iA >= 0) {
            return ((P0) this.f14212b.get(iA)).setValue(obj);
        }
        b();
        boolean zIsEmpty = this.f14212b.isEmpty();
        int i6 = this.f14211a;
        if (zIsEmpty && !(this.f14212b instanceof ArrayList)) {
            this.f14212b = new ArrayList(i6);
        }
        int i7 = -(iA + 1);
        if (i7 >= i6) {
            return f().put(comparable, obj);
        }
        if (this.f14212b.size() == i6) {
            P0 p02 = (P0) this.f14212b.remove(i6 - 1);
            f().put(p02.f14222a, p02.f14223b);
        }
        this.f14212b.add(i7, new P0(this, comparable, obj));
        return null;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Object get(Object obj) {
        Comparable comparable = (Comparable) obj;
        int iA = a(comparable);
        return iA >= 0 ? ((P0) this.f14212b.get(iA)).f14223b : this.f14213c.get(comparable);
    }

    public final Object h(int i6) {
        b();
        Object obj = ((P0) this.f14212b.remove(i6)).f14223b;
        if (!this.f14213c.isEmpty()) {
            Iterator it = f().entrySet().iterator();
            List list = this.f14212b;
            Map.Entry entry = (Map.Entry) it.next();
            list.add(new P0(this, (Comparable) entry.getKey(), entry.getValue()));
            it.remove();
        }
        return obj;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final int hashCode() {
        int size = this.f14212b.size();
        int iHashCode = 0;
        for (int i6 = 0; i6 < size; i6++) {
            iHashCode += ((P0) this.f14212b.get(i6)).hashCode();
        }
        return this.f14213c.size() > 0 ? this.f14213c.hashCode() + iHashCode : iHashCode;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Object remove(Object obj) {
        b();
        Comparable comparable = (Comparable) obj;
        int iA = a(comparable);
        if (iA >= 0) {
            return h(iA);
        }
        if (this.f14213c.isEmpty()) {
            return null;
        }
        return this.f14213c.remove(comparable);
    }

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