package androidx.fragment.app;

import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ArrayList f4359a = new ArrayList();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final HashMap f4360b = new HashMap();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final HashMap f4361c = new HashMap();

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

    public final void a(I i) {
        if (this.f4359a.contains(i)) {
            throw new IllegalStateException("Fragment already added: " + i);
        }
        synchronized (this.f4359a) {
            this.f4359a.add(i);
        }
        i.mAdded = true;
    }

    public final I b(String str) {
        p0 p0Var = (p0) this.f4360b.get(str);
        if (p0Var != null) {
            return p0Var.f4351c;
        }
        return null;
    }

    public final I c(String str) {
        I iFindFragmentByWho;
        for (p0 p0Var : this.f4360b.values()) {
            if (p0Var != null && (iFindFragmentByWho = p0Var.f4351c.findFragmentByWho(str)) != null) {
                return iFindFragmentByWho;
            }
        }
        return null;
    }

    public final ArrayList d() {
        ArrayList arrayList = new ArrayList();
        for (p0 p0Var : this.f4360b.values()) {
            if (p0Var != null) {
                arrayList.add(p0Var);
            }
        }
        return arrayList;
    }

    public final ArrayList e() {
        ArrayList arrayList = new ArrayList();
        for (p0 p0Var : this.f4360b.values()) {
            if (p0Var != null) {
                arrayList.add(p0Var.f4351c);
            } else {
                arrayList.add(null);
            }
        }
        return arrayList;
    }

    public final List f() {
        ArrayList arrayList;
        if (this.f4359a.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        synchronized (this.f4359a) {
            arrayList = new ArrayList(this.f4359a);
        }
        return arrayList;
    }

    public final void g(p0 p0Var) {
        I i = p0Var.f4351c;
        String str = i.mWho;
        HashMap map = this.f4360b;
        if (map.get(str) != null) {
            return;
        }
        map.put(i.mWho, p0Var);
        if (i.mRetainInstanceChangedWhileDetached) {
            if (i.mRetainInstance) {
                this.f4362d.c(i);
            } else {
                this.f4362d.g(i);
            }
            i.mRetainInstanceChangedWhileDetached = false;
        }
        if (h0.J(2)) {
            Log.v("FragmentManager", "Added fragment to active set " + i);
        }
    }

    public final void h(p0 p0Var) {
        I i = p0Var.f4351c;
        if (i.mRetainInstance) {
            this.f4362d.g(i);
        }
        HashMap map = this.f4360b;
        if (map.get(i.mWho) == p0Var && ((p0) map.put(i.mWho, null)) != null && h0.J(2)) {
            Log.v("FragmentManager", "Removed fragment from active set " + i);
        }
    }

    public final Bundle i(Bundle bundle, String str) {
        HashMap map = this.f4361c;
        return bundle != null ? (Bundle) map.put(str, bundle) : (Bundle) map.remove(str);
    }
}
