package jnpf.enums.memoo;

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

/**
 * 删除状态
 */
public enum DeleteMark {

    DEL(1, "已删除");

    private int val;

    private String name;

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

    public int getVal() {
        return val;
    }

    public String getName() {
        return name;
    }

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

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

    private static ReentrantLock mapLock = new ReentrantLock();

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