package IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.KNBe_11.PGPF6hQ_2;

import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.KNBe_11.PGPF6hQ_2.Mqv2r_3.KQgRr5e_0;
import android.util.SparseArray;
/* compiled from: ListenerModelHandler.java */
/* loaded from: classes.dex */
public class Mqv2r_3<T extends KQgRr5e_0> implements PGPF6hQ_2 {
    public volatile T KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final QxJ9d_1<T> f136KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final SparseArray<T> f137KQgRr5e_0 = new SparseArray<>();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public Boolean f138KQgRr5e_0;

    /* compiled from: ListenerModelHandler.java */
    /* loaded from: classes.dex */
    public interface KQgRr5e_0 {
        void KQgRr5e_0(IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.PGPF6hQ_2 pGPF6hQ_2);

        int getId();
    }

    /* compiled from: ListenerModelHandler.java */
    /* loaded from: classes.dex */
    public interface QxJ9d_1<T extends KQgRr5e_0> {
        T KQgRr5e_0(int i);
    }

    public Mqv2r_3(QxJ9d_1<T> qxJ9d_1) {
        this.f136KQgRr5e_0 = qxJ9d_1;
    }

    public boolean KQgRr5e_0() {
        Boolean bool = this.f138KQgRr5e_0;
        return bool != null && bool.booleanValue();
    }

    public T PGPF6hQ_2(IMuAHx_6.KQgRr5e_0.KQgRr5e_0.PGPF6hQ_2 pGPF6hQ_2, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.PGPF6hQ_2 pGPF6hQ_22) {
        T t;
        int KQgRr5e_02 = pGPF6hQ_2.KQgRr5e_0();
        synchronized (this) {
            if (this.KQgRr5e_0 != null && this.KQgRr5e_0.getId() == KQgRr5e_02) {
                t = this.KQgRr5e_0;
                this.KQgRr5e_0 = null;
            } else {
                t = this.f137KQgRr5e_0.get(KQgRr5e_02);
                this.f137KQgRr5e_0.remove(KQgRr5e_02);
            }
        }
        if (t == null) {
            t = this.f136KQgRr5e_0.KQgRr5e_0(KQgRr5e_02);
            if (pGPF6hQ_22 != null) {
                t.KQgRr5e_0(pGPF6hQ_22);
            }
        }
        return t;
    }

    public T QxJ9d_1(IMuAHx_6.KQgRr5e_0.KQgRr5e_0.PGPF6hQ_2 pGPF6hQ_2, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.PGPF6hQ_2 pGPF6hQ_22) {
        T t;
        int KQgRr5e_02 = pGPF6hQ_2.KQgRr5e_0();
        synchronized (this) {
            t = (this.KQgRr5e_0 == null || this.KQgRr5e_0.getId() != KQgRr5e_02) ? null : this.KQgRr5e_0;
        }
        if (t == null) {
            t = this.f137KQgRr5e_0.get(KQgRr5e_02);
        }
        return (t == null && KQgRr5e_0()) ? KQgRr5e_0(pGPF6hQ_2, pGPF6hQ_22) : t;
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.KNBe_11.PGPF6hQ_2.PGPF6hQ_2
    public void KQgRr5e_0(boolean z) {
        if (this.f138KQgRr5e_0 == null) {
            this.f138KQgRr5e_0 = Boolean.valueOf(z);
        }
    }

    public T KQgRr5e_0(IMuAHx_6.KQgRr5e_0.KQgRr5e_0.PGPF6hQ_2 pGPF6hQ_2, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.PGPF6hQ_2 pGPF6hQ_22) {
        T KQgRr5e_02 = this.f136KQgRr5e_0.KQgRr5e_0(pGPF6hQ_2.KQgRr5e_0());
        synchronized (this) {
            if (this.KQgRr5e_0 == null) {
                this.KQgRr5e_0 = KQgRr5e_02;
            } else {
                this.f137KQgRr5e_0.put(pGPF6hQ_2.KQgRr5e_0(), KQgRr5e_02);
            }
            if (pGPF6hQ_22 != null) {
                KQgRr5e_02.KQgRr5e_0(pGPF6hQ_22);
            }
        }
        return KQgRr5e_02;
    }
}
