package X6FRs_4.Mqv2r_3;

import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
/* compiled from: LruCache.java */
/* loaded from: classes.dex */
public class X6FRs_4<K, V> {

    /* renamed from: IFxWkV_5  reason: collision with root package name */
    public int f3224IFxWkV_5;

    /* renamed from: IMuAHx_6  reason: collision with root package name */
    public int f3225IMuAHx_6;
    public int KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final LinkedHashMap<K, V> f1021KQgRr5e_0;

    /* renamed from: Mqv2r_3  reason: collision with root package name */
    public int f3226Mqv2r_3;
    public int PGPF6hQ_2;
    public int QxJ9d_1;

    /* renamed from: X6FRs_4  reason: collision with root package name */
    public int f3227X6FRs_4;

    public X6FRs_4(int i) {
        if (i > 0) {
            this.QxJ9d_1 = i;
            this.f1021KQgRr5e_0 = new LinkedHashMap<>(0, 0.75f, true);
            return;
        }
        throw new IllegalArgumentException("maxSize <= 0");
    }

    public V KQgRr5e_0(K k) {
        return null;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final V m513KQgRr5e_0(K k, V v) {
        V put;
        if (k != null && v != null) {
            synchronized (this) {
                this.PGPF6hQ_2++;
                this.KQgRr5e_0 += KQgRr5e_0((X6FRs_4<K, V>) k, (K) v);
                put = this.f1021KQgRr5e_0.put(k, v);
                if (put != null) {
                    this.KQgRr5e_0 -= KQgRr5e_0((X6FRs_4<K, V>) k, (K) put);
                }
            }
            if (put != null) {
                KQgRr5e_0(false, k, put, v);
            }
            KQgRr5e_0(this.QxJ9d_1);
            return put;
        }
        throw new NullPointerException("key == null || value == null");
    }

    public void KQgRr5e_0(boolean z, K k, V v, V v2) {
    }

    public int QxJ9d_1(K k, V v) {
        return 1;
    }

    public final V QxJ9d_1(K k) {
        V put;
        if (k != null) {
            synchronized (this) {
                V v = this.f1021KQgRr5e_0.get(k);
                if (v != null) {
                    this.f3224IFxWkV_5++;
                    return v;
                }
                this.f3225IMuAHx_6++;
                V KQgRr5e_0 = KQgRr5e_0((X6FRs_4<K, V>) k);
                if (KQgRr5e_0 == null) {
                    return null;
                }
                synchronized (this) {
                    this.f3226Mqv2r_3++;
                    put = this.f1021KQgRr5e_0.put(k, KQgRr5e_0);
                    if (put != null) {
                        this.f1021KQgRr5e_0.put(k, put);
                    } else {
                        this.KQgRr5e_0 += KQgRr5e_0((X6FRs_4<K, V>) k, (K) KQgRr5e_0);
                    }
                }
                if (put != null) {
                    KQgRr5e_0(false, k, KQgRr5e_0, put);
                    return put;
                }
                KQgRr5e_0(this.QxJ9d_1);
                return KQgRr5e_0;
            }
        }
        throw new NullPointerException("key == null");
    }

    public final synchronized String toString() {
        int i;
        i = this.f3224IFxWkV_5 + this.f3225IMuAHx_6;
        return String.format(Locale.US, "LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]", Integer.valueOf(this.QxJ9d_1), Integer.valueOf(this.f3224IFxWkV_5), Integer.valueOf(this.f3225IMuAHx_6), Integer.valueOf(i != 0 ? (this.f3224IFxWkV_5 * 100) / i : 0));
    }

    /* JADX WARN: Code restructure failed: missing block: B:20:0x0070, code lost:
        throw new java.lang.IllegalStateException(getClass().getName() + ".sizeOf() is reporting inconsistent results!");
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void KQgRr5e_0(int i) {
        K key;
        V value;
        while (true) {
            synchronized (this) {
                if (this.KQgRr5e_0 >= 0 && (!this.f1021KQgRr5e_0.isEmpty() || this.KQgRr5e_0 == 0)) {
                    if (this.KQgRr5e_0 <= i || this.f1021KQgRr5e_0.isEmpty()) {
                        break;
                    }
                    Map.Entry<K, V> next = this.f1021KQgRr5e_0.entrySet().iterator().next();
                    key = next.getKey();
                    value = next.getValue();
                    this.f1021KQgRr5e_0.remove(key);
                    this.KQgRr5e_0 -= KQgRr5e_0((X6FRs_4<K, V>) key, (K) value);
                    this.f3227X6FRs_4++;
                } else {
                    break;
                }
            }
            KQgRr5e_0(true, key, value, null);
        }
    }

    public final int KQgRr5e_0(K k, V v) {
        int QxJ9d_1 = QxJ9d_1(k, v);
        if (QxJ9d_1 >= 0) {
            return QxJ9d_1;
        }
        throw new IllegalStateException("Negative size: " + k + "=" + v);
    }
}
