package jnpf.enums.memoo;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

public enum UserDel {


    NO("0", "未删除"),
    YES("-1", "已删除");

    private String val;

    private String name;

    UserDel(String val, String name) {
        this.val = val;
        this.name = name;
    }

    public String getVal() {
        return val;
    }

    public String getName() {
        return name;
    }

    public static UserDel getByVal(String val) {
        for (UserDel os : values()) {
            if (os.getVal() == val) {
                return os;
            }
        }
        return null;
    }

    private static Map<String, String> map = null;

    private static ReentrantLock mapLock = new ReentrantLock();

    public static Map<String, String> getMap() {
        if (map == null) {
            try {
                mapLock.lock();
                if (map == null) {
                    map = new LinkedHashMap<>();
                    for (UserDel value : UserDel.values()) {
                        map.put(value.getVal(), value.getName());
                    }
                }
            } finally {
                mapLock.unlock();
            }
        }
        return map;
    }
}
