package com.bonait.bnframework.common.helper;

import com.bonait.bnframework.common.helper.I.IRun;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 上升沿操作
 */
public class RTrig {
    private static volatile ConcurrentHashMap<String, RTrig> _Instance;

    public static RTrig get(String name) {
        if (_Instance == null)
            _Instance = new ConcurrentHashMap<String, RTrig>();
        if (!_Instance.containsKey(name))
            _Instance.put(name, new RTrig());
        return _Instance.get(name);
    }

    private RTrig() {
    }

    private boolean flag=false;
    private boolean Q=false;

    public boolean getQ() {
        return Q;
    }

    private void setIN(boolean falag) {
        Q = falag && !flag;
        flag = falag;
    }

    public void Start(boolean IN, IRun callback) {
        setIN(IN);
        if (Q)
            callback.Run();
    }

}
