package com.bytedance.provider.vm;

import X.0Bt;
import X.C3658EMs;
import X.LsC;
import X.M12;
import com.bytedance.covode.number.Covode;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;
import kotlin.h.b.n;

public final class ScopeViewModel extends 0Bt {
    public CopyOnWriteArrayList<C3658EMs> LIZ = new CopyOnWriteArrayList<>();

    static {
        Covode.recordClassIndex(36719);
    }

    public final void onCleared() {
        ScopeViewModel.super.onCleared();
        this.LIZ.clear();
    }

    private C3658EMs LIZ(String str) {
        T t;
        Iterator<T> it = this.LIZ.iterator();
        while (true) {
            if (!it.hasNext()) {
                t = null;
                break;
            }
            t = it.next();
            if (n.LIZ(((C3658EMs) t).LIZIZ(), str)) {
                break;
            }
        }
        return (C3658EMs) t;
    }

    public final C3658EMs LIZ(String str, LsC<? super String, ? extends C3658EMs> lsC) {
        M12.LIZ(lsC);
        if (str == null) {
            str = "scope_default_key";
        }
        C3658EMs LIZ2 = LIZ(str);
        if (LIZ2 != null) {
            return LIZ2;
        }
        C3658EMs eMs = (C3658EMs) lsC.invoke(str);
        this.LIZ.add(eMs);
        return eMs;
    }
}
