package jnpf.enums.memoo;

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

/**
 * 上架状态
 */
public enum PushState {

    TYPE1(0, "未上架"),
    TYPE2(1, "已上架"),
    TYPE3(-1, "用户已删除");

    private int val;

    private String name;

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

    public int getVal() {
        return val;
    }

    public String getName() {
        return name;
    }

    public static PushState getByVal(int val) {
        for (PushState 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 (PushState value : PushState.values()) {
                        map.put(value.getVal(), value.getName());
                    }
                }
            } finally {
                mapLock.unlock();
            }
        }
        return map;
    }
}
