package androidx.collection;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import xyz.stream.utils.a0;

/* JADX INFO: loaded from: classes.dex */
public class n {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final a0 f951b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final eb.e f952c;

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

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

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

    public n(int i10) {
        this.f950a = i10;
        if (i10 <= 0) {
            throw new IllegalArgumentException("maxSize <= 0".toString());
        }
        a0 a0Var = new a0();
        a0Var.f36098a = new LinkedHashMap(0, 0.75f, true);
        this.f951b = a0Var;
        this.f952c = new eb.e();
    }

    public static void d(Object obj, Object obj2) {
        nb.g.i(obj, "key");
        nb.g.i(obj2, "value");
    }

    public Object a(Object obj) {
        nb.g.i(obj, "key");
        return null;
    }

    public final Object b(Object obj) {
        Object objZ;
        nb.g.i(obj, "key");
        synchronized (this.f952c) {
            a0 a0Var = this.f951b;
            a0Var.getClass();
            Object obj2 = ((LinkedHashMap) a0Var.f36098a).get(obj);
            if (obj2 != null) {
                this.f954e++;
                return obj2;
            }
            this.f955f++;
            Object objA = a(obj);
            if (objA == null) {
                return null;
            }
            synchronized (this.f952c) {
                try {
                    objZ = this.f951b.z(obj, objA);
                    if (objZ != null) {
                        this.f951b.z(obj, objZ);
                    } else {
                        int i10 = this.f953d;
                        d(obj, objA);
                        this.f953d = i10 + 1;
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
            if (objZ != null) {
                return objZ;
            }
            e(this.f950a);
            return objA;
        }
    }

    public final Object c(Object obj, Object obj2) {
        Object objZ;
        nb.g.i(obj, "key");
        synchronized (this.f952c) {
            int i10 = this.f953d;
            d(obj, obj2);
            this.f953d = i10 + 1;
            objZ = this.f951b.z(obj, obj2);
            if (objZ != null) {
                int i11 = this.f953d;
                d(obj, objZ);
                this.f953d = i11 - 1;
            }
        }
        e(this.f950a);
        return objZ;
    }

    /* JADX WARN: Code restructure failed: missing block: B:36:0x008f, code lost:
    
        return;
     */
    /* JADX WARN: Code restructure failed: missing block: B:38:0x009b, code lost:
    
        throw new java.lang.IllegalStateException("LruCache.sizeOf() is reporting inconsistent results!".toString());
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void e(int i10) {
        Object value;
        while (true) {
            synchronized (this.f952c) {
                try {
                    if (this.f953d < 0 || (((LinkedHashMap) this.f951b.f36098a).isEmpty() && this.f953d != 0)) {
                        break;
                    }
                    if (this.f953d <= i10 || ((LinkedHashMap) this.f951b.f36098a).isEmpty()) {
                        break;
                    }
                    Set setEntrySet = ((LinkedHashMap) this.f951b.f36098a).entrySet();
                    nb.g.h(setEntrySet, "map.entries");
                    Object next = null;
                    if (setEntrySet instanceof List) {
                        List list = (List) setEntrySet;
                        if (!list.isEmpty()) {
                            next = list.get(0);
                        }
                    } else {
                        Iterator it = setEntrySet.iterator();
                        if (it.hasNext()) {
                            next = it.next();
                        }
                    }
                    Map.Entry entry = (Map.Entry) next;
                    if (entry == null) {
                        return;
                    }
                    Object key = entry.getKey();
                    value = entry.getValue();
                    a0 a0Var = this.f951b;
                    a0Var.getClass();
                    nb.g.i(key, "key");
                    ((LinkedHashMap) a0Var.f36098a).remove(key);
                    int i11 = this.f953d;
                    d(key, value);
                    this.f953d = i11 - 1;
                } catch (Throwable th) {
                    throw th;
                }
            }
            nb.g.i(value, "oldValue");
        }
    }

    public final String toString() {
        String str;
        synchronized (this.f952c) {
            try {
                int i10 = this.f954e;
                int i11 = this.f955f + i10;
                str = "LruCache[maxSize=" + this.f950a + ",hits=" + this.f954e + ",misses=" + this.f955f + ",hitRate=" + (i11 != 0 ? (i10 * 100) / i11 : 0) + "%]";
            } catch (Throwable th) {
                throw th;
            }
        }
        return str;
    }
}
