package androidx.fragment.app;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class w {
    public final ArrayList a = new ArrayList();
    public final HashMap b = new HashMap();
    public final HashMap c = new HashMap();
    public t d;

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

    public final l b(String str) {
        v vVar = (v) this.b.get(str);
        if (vVar != null) {
            return vVar.c;
        }
        return null;
    }

    public final l c(String str) {
        l lVarFindFragmentByWho;
        for (v vVar : this.b.values()) {
            if (vVar != null && (lVarFindFragmentByWho = vVar.c.findFragmentByWho(str)) != null) {
                return lVarFindFragmentByWho;
            }
        }
        return null;
    }

    public final ArrayList d() {
        ArrayList arrayList = new ArrayList();
        for (v vVar : this.b.values()) {
            if (vVar != null) {
                arrayList.add(vVar);
            }
        }
        return arrayList;
    }

    public final ArrayList e() {
        ArrayList arrayList = new ArrayList();
        for (v vVar : this.b.values()) {
            if (vVar != null) {
                arrayList.add(vVar.c);
            } else {
                arrayList.add(null);
            }
        }
        return arrayList;
    }

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

    public final void g(v vVar) {
        l lVar = vVar.c;
        String str = lVar.mWho;
        HashMap map = this.b;
        if (map.get(str) != null) {
            return;
        }
        map.put(lVar.mWho, vVar);
        if (lVar.mRetainInstanceChangedWhileDetached) {
            if (lVar.mRetainInstance) {
                this.d.c(lVar);
            } else {
                this.d.e(lVar);
            }
            lVar.mRetainInstanceChangedWhileDetached = false;
        }
        if (s.F(2)) {
            lVar.toString();
        }
    }

    public final void h(v vVar) {
        l lVar = vVar.c;
        if (lVar.mRetainInstance) {
            this.d.e(lVar);
        }
        if (((v) this.b.put(lVar.mWho, null)) != null && s.F(2)) {
            lVar.toString();
        }
    }
}
