package t5;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final LinkedHashMap f32969a = new LinkedHashMap(100, 0.75f, true);

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

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

    public k(long j10) {
        this.f32970b = j10;
    }

    public final synchronized void a(long j10) {
        while (this.f32971c > j10) {
            Iterator it = this.f32969a.entrySet().iterator();
            Map.Entry entry = (Map.Entry) it.next();
            j jVar = (j) entry.getValue();
            this.f32971c -= (long) jVar.f32968b;
            Object key = entry.getKey();
            it.remove();
            onItemEvicted(key, jVar.f32967a);
        }
    }

    @Nullable
    public synchronized Object get(@NonNull Object obj) {
        j jVar;
        jVar = (j) this.f32969a.get(obj);
        return jVar != null ? jVar.f32967a : null;
    }

    public int getSize(@Nullable Object obj) {
        return 1;
    }

    public void onItemEvicted(@NonNull Object obj, @Nullable Object obj2) {
    }

    @Nullable
    public synchronized Object put(@NonNull Object obj, @Nullable Object obj2) {
        int size = getSize(obj2);
        long j10 = size;
        if (j10 >= this.f32970b) {
            onItemEvicted(obj, obj2);
            return null;
        }
        if (obj2 != null) {
            this.f32971c += j10;
        }
        j jVar = (j) this.f32969a.put(obj, obj2 == null ? null : new j(obj2, size));
        if (jVar != null) {
            this.f32971c -= (long) jVar.f32968b;
            if (!jVar.f32967a.equals(obj2)) {
                onItemEvicted(obj, jVar.f32967a);
            }
        }
        a(this.f32970b);
        return jVar != null ? jVar.f32967a : null;
    }

    @Nullable
    public synchronized Object remove(@NonNull Object obj) {
        j jVar = (j) this.f32969a.remove(obj);
        if (jVar == null) {
            return null;
        }
        this.f32971c -= (long) jVar.f32968b;
        return jVar.f32967a;
    }
}
