package defpackage;

import android.view.View;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/* renamed from: ᵤᵩᵾ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public class C3457 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public int f12974;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final Object f12975;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final Object f12976;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public int f12977;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final /* synthetic */ int f12978;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public int f12979;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public int f12980;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public static final C2360 f12973 = new C2360(19);

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public static final C2360 f12972 = new C2360(20);

    public C3457() {
        this.f12978 = 0;
        this.f12975 = new C3100[5];
        this.f12976 = new ArrayList();
        this.f12979 = -1;
    }

    public C3457(int i) {
        this.f12978 = 1;
        this.f12979 = i;
        if (i <= 0) {
            ᵯᵽᵦ.ˀᵗᵩ("maxSize <= 0");
            throw null;
        }
        this.f12976 = new C4752(2);
        this.f12975 = new ᵼᵫᵧˀ(29);
    }

    public C3457(StaggeredGridLayoutManager staggeredGridLayoutManager, int i) {
        this.f12978 = 2;
        this.f12975 = staggeredGridLayoutManager;
        this.f12976 = new ArrayList();
        this.f12979 = Integer.MIN_VALUE;
        this.f12977 = Integer.MIN_VALUE;
        this.f12980 = 0;
        this.f12974 = i;
    }

    public String toString() {
        String str;
        switch (this.f12978) {
            case 1:
                synchronized (((ᵼᵫᵧˀ) this.f12975)) {
                    try {
                        int i = this.f12980;
                        int i2 = this.f12974 + i;
                        str = "LruCache[maxSize=" + this.f12979 + ",hits=" + this.f12980 + ",misses=" + this.f12974 + ",hitRate=" + (i2 != 0 ? (i * 100) / i2 : 0) + "%]";
                    } catch (Throwable th) {
                        throw th;
                    }
                }
                return str;
            default:
                return super.toString();
        }
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public void mo7847(Object obj, Object obj2, Object obj3) {
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public Object m7848(String str) {
        Object objRemove;
        synchronized (((ᵼᵫᵧˀ) this.f12975)) {
            objRemove = ((C4752) this.f12976).f17615.remove(str);
            if (objRemove != null) {
                this.f12977--;
            }
        }
        if (objRemove != null) {
            mo7847(str, objRemove, null);
        }
        return objRemove;
    }

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public float m7849() {
        ArrayList arrayList = (ArrayList) this.f12976;
        if (this.f12979 != 0) {
            Collections.sort(arrayList, f12972);
            this.f12979 = 0;
        }
        float f = 0.5f * this.f12980;
        int i = 0;
        for (int i2 = 0; i2 < arrayList.size(); i2++) {
            C3100 c3100 = (C3100) arrayList.get(i2);
            i += c3100.f11821;
            if (i >= f) {
                return c3100.f11819;
            }
        }
        if (arrayList.isEmpty()) {
            return Float.NaN;
        }
        return ((C3100) AbstractC1327.m4111(1, arrayList)).f11819;
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public int m7850() {
        return ((StaggeredGridLayoutManager) this.f12975).f939 ? m7863(0, ((ArrayList) this.f12976).size()) : m7863(r1.size() - 1, -1);
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public int m7851() {
        return ((StaggeredGridLayoutManager) this.f12975).f939 ? m7863(r1.size() - 1, -1) : m7863(0, ((ArrayList) this.f12976).size());
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public void m7852() {
        ((ArrayList) this.f12976).clear();
        this.f12979 = Integer.MIN_VALUE;
        this.f12977 = Integer.MIN_VALUE;
        this.f12980 = 0;
    }

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public Object m7853(Object obj) {
        Object objPut;
        synchronized (((ᵼᵫᵧˀ) this.f12975)) {
            Object obj2 = ((C4752) this.f12976).f17615.get(obj);
            if (obj2 != null) {
                this.f12980++;
                return obj2;
            }
            this.f12974++;
            Object objMo1807 = mo1807(obj);
            if (objMo1807 == null) {
                return null;
            }
            synchronized (((ᵼᵫᵧˀ) this.f12975)) {
                objPut = ((C4752) this.f12976).f17615.put(obj, objMo1807);
                if (objPut != null) {
                    ((C4752) this.f12976).f17615.put(obj, objPut);
                } else {
                    this.f12977++;
                }
            }
            if (objPut != null) {
                mo7847(obj, objMo1807, objPut);
                return objPut;
            }
            m7861(this.f12979);
            return objMo1807;
        }
    }

    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public LinkedHashMap m7854() {
        LinkedHashMap linkedHashMap;
        synchronized (((ᵼᵫᵧˀ) this.f12975)) {
            linkedHashMap = new LinkedHashMap(((C4752) this.f12976).f17615.entrySet().size());
            for (Map.Entry entry : ((C4752) this.f12976).f17615.entrySet()) {
                linkedHashMap.put(entry.getKey(), entry.getValue());
            }
        }
        return linkedHashMap;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public void m7855(int i, float f) {
        C3100 c3100;
        C3100[] c3100Arr = (C3100[]) this.f12975;
        ArrayList arrayList = (ArrayList) this.f12976;
        if (this.f12979 != 1) {
            Collections.sort(arrayList, f12973);
            this.f12979 = 1;
        }
        int i2 = this.f12974;
        if (i2 > 0) {
            int i3 = i2 - 1;
            this.f12974 = i3;
            c3100 = c3100Arr[i3];
        } else {
            c3100 = new C3100();
        }
        int i4 = this.f12977;
        this.f12977 = i4 + 1;
        c3100.f11820 = i4;
        c3100.f11821 = i;
        c3100.f11819 = f;
        arrayList.add(c3100);
        this.f12980 += i;
        while (true) {
            int i5 = this.f12980;
            if (i5 <= 2000) {
                return;
            }
            int i6 = i5 - 2000;
            C3100 c31002 = (C3100) arrayList.get(0);
            int i7 = c31002.f11821;
            if (i7 <= i6) {
                this.f12980 -= i7;
                arrayList.remove(0);
                int i8 = this.f12974;
                if (i8 < 5) {
                    this.f12974 = i8 + 1;
                    c3100Arr[i8] = c31002;
                }
            } else {
                c31002.f11821 = i7 - i6;
                this.f12980 -= i6;
            }
        }
    }

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public int m7856() {
        int i;
        synchronized (((ᵼᵫᵧˀ) this.f12975)) {
            i = this.f12979;
        }
        return i;
    }

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public int m7857(int i) {
        ArrayList arrayList = (ArrayList) this.f12976;
        int i2 = this.f12979;
        if (i2 != Integer.MIN_VALUE) {
            return i2;
        }
        if (arrayList.size() == 0) {
            return i;
        }
        View view = (View) arrayList.get(0);
        C4785 c4785 = (C4785) view.getLayoutParams();
        this.f12979 = ((StaggeredGridLayoutManager) this.f12975).f946.mo1111(view);
        c4785.getClass();
        return this.f12979;
    }

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public Object m7858(Object obj, Object obj2) {
        Object objPut;
        synchronized (((ᵼᵫᵧˀ) this.f12975)) {
            this.f12977++;
            objPut = ((C4752) this.f12976).f17615.put(obj, obj2);
            if (objPut != null) {
                this.f12977--;
            }
        }
        if (objPut != null) {
            mo7847(obj, objPut, obj2);
        }
        m7861(this.f12979);
        return objPut;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public void m7859() {
        View view = (View) AbstractC1327.m4111(1, (ArrayList) this.f12976);
        C4785 c4785 = (C4785) view.getLayoutParams();
        this.f12977 = ((StaggeredGridLayoutManager) this.f12975).f946.mo1120(view);
        c4785.getClass();
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public int m7860(int i) {
        int i2 = this.f12977;
        if (i2 != Integer.MIN_VALUE) {
            return i2;
        }
        if (((ArrayList) this.f12976).size() == 0) {
            return i;
        }
        m7859();
        return this.f12977;
    }

    /* JADX WARN: Code restructure failed: missing block: B:26:0x005f, code lost:
    
        return;
     */
    /* JADX WARN: Code restructure failed: missing block: B:28:0x0067, code lost:
    
        throw new java.lang.IllegalStateException("LruCache.sizeOf() is reporting inconsistent results!");
     */
    /* renamed from: ᵸʓᵠ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void m7861(int r5) {
        /*
            r4 = this;
        L0:
            java.lang.Object r0 = r4.f12975
            ᵼᵫᵧˀ r0 = (ᵼᵫᵧˀ) r0
            monitor-enter(r0)
            int r1 = r4.f12977     // Catch: java.lang.Throwable -> L1a
            if (r1 < 0) goto L60
            java.lang.Object r1 = r4.f12976     // Catch: java.lang.Throwable -> L1a
            ᵵᵳˆᵛ r1 = (defpackage.C4752) r1     // Catch: java.lang.Throwable -> L1a
            java.util.LinkedHashMap r1 = r1.f17615     // Catch: java.lang.Throwable -> L1a
            boolean r1 = r1.isEmpty()     // Catch: java.lang.Throwable -> L1a
            if (r1 == 0) goto L1c
            int r1 = r4.f12977     // Catch: java.lang.Throwable -> L1a
            if (r1 != 0) goto L60
            goto L1c
        L1a:
            r4 = move-exception
            goto L68
        L1c:
            int r1 = r4.f12977     // Catch: java.lang.Throwable -> L1a
            if (r1 <= r5) goto L5e
            java.lang.Object r1 = r4.f12976     // Catch: java.lang.Throwable -> L1a
            ᵵᵳˆᵛ r1 = (defpackage.C4752) r1     // Catch: java.lang.Throwable -> L1a
            java.util.LinkedHashMap r1 = r1.f17615     // Catch: java.lang.Throwable -> L1a
            boolean r1 = r1.isEmpty()     // Catch: java.lang.Throwable -> L1a
            if (r1 == 0) goto L2d
            goto L5e
        L2d:
            java.lang.Object r1 = r4.f12976     // Catch: java.lang.Throwable -> L1a
            ᵵᵳˆᵛ r1 = (defpackage.C4752) r1     // Catch: java.lang.Throwable -> L1a
            java.util.LinkedHashMap r1 = r1.f17615     // Catch: java.lang.Throwable -> L1a
            java.util.Set r1 = r1.entrySet()     // Catch: java.lang.Throwable -> L1a
            java.lang.Object r1 = defpackage.AbstractC2767.m6834(r1)     // Catch: java.lang.Throwable -> L1a
            java.util.Map$Entry r1 = (java.util.Map.Entry) r1     // Catch: java.lang.Throwable -> L1a
            if (r1 != 0) goto L41
            monitor-exit(r0)
            return
        L41:
            java.lang.Object r2 = r1.getKey()     // Catch: java.lang.Throwable -> L1a
            java.lang.Object r1 = r1.getValue()     // Catch: java.lang.Throwable -> L1a
            java.lang.Object r3 = r4.f12976     // Catch: java.lang.Throwable -> L1a
            ᵵᵳˆᵛ r3 = (defpackage.C4752) r3     // Catch: java.lang.Throwable -> L1a
            java.util.LinkedHashMap r3 = r3.f17615     // Catch: java.lang.Throwable -> L1a
            r3.remove(r2)     // Catch: java.lang.Throwable -> L1a
            int r3 = r4.f12977     // Catch: java.lang.Throwable -> L1a
            int r3 = r3 + (-1)
            r4.f12977 = r3     // Catch: java.lang.Throwable -> L1a
            monitor-exit(r0)
            r0 = 0
            r4.mo7847(r2, r1, r0)
            goto L0
        L5e:
            monitor-exit(r0)
            return
        L60:
            java.lang.String r4 = "LruCache.sizeOf() is reporting inconsistent results!"
            java.lang.IllegalStateException r5 = new java.lang.IllegalStateException     // Catch: java.lang.Throwable -> L1a
            r5.<init>(r4)     // Catch: java.lang.Throwable -> L1a
            throw r5     // Catch: java.lang.Throwable -> L1a
        L68:
            monitor-exit(r0)
            throw r4
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C3457.m7861(int):void");
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public View m7862(int i, int i2) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) this.f12975;
        ArrayList arrayList = (ArrayList) this.f12976;
        View view = null;
        if (i2 != -1) {
            int size = arrayList.size() - 1;
            while (size >= 0) {
                View view2 = (View) arrayList.get(size);
                if ((staggeredGridLayoutManager.f939 && AbstractC1935.m5415(view2) >= i) || ((!staggeredGridLayoutManager.f939 && AbstractC1935.m5415(view2) <= i) || !view2.hasFocusable())) {
                    break;
                }
                size--;
                view = view2;
            }
            return view;
        }
        int size2 = arrayList.size();
        int i3 = 0;
        while (i3 < size2) {
            View view3 = (View) arrayList.get(i3);
            if ((staggeredGridLayoutManager.f939 && AbstractC1935.m5415(view3) <= i) || ((!staggeredGridLayoutManager.f939 && AbstractC1935.m5415(view3) >= i) || !view3.hasFocusable())) {
                break;
            }
            i3++;
            view = view3;
        }
        return view;
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public int m7863(int i, int i2) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) this.f12975;
        int iMo1122 = staggeredGridLayoutManager.f946.mo1122();
        int iMo1113 = staggeredGridLayoutManager.f946.mo1113();
        int i3 = i2 > i ? 1 : -1;
        while (i != i2) {
            View view = (View) ((ArrayList) this.f12976).get(i);
            int iMo1111 = staggeredGridLayoutManager.f946.mo1111(view);
            int iMo1120 = staggeredGridLayoutManager.f946.mo1120(view);
            boolean z = iMo1111 <= iMo1113;
            boolean z2 = iMo1120 >= iMo1122;
            if (z && z2 && (iMo1111 < iMo1122 || iMo1120 > iMo1113)) {
                return AbstractC1935.m5415(view);
            }
            i += i3;
        }
        return -1;
    }

    /* renamed from: ᵻᵢﹳᵰ */
    public Object mo1807(Object obj) {
        return null;
    }
}
