码迷,mamicode.com
首页 > 其他好文 > 详细

枚举的使用

时间:2021-03-05 13:21:36      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:cts   hash   nis   fill   run   pre   public   sync   get   

package com.erp.sign.pojo.constants;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 合同状态枚举
 * @auther han
 * @date 2021/1/19
 */
public enum MyContractStatus {
    DRAFT("DRAFT","草稿"),
    SIGNING("SIGNING","签署中"),
    COMPLETE("COMPLETE","已完成"),
    REJECTED("REJECTED","已退回"),
    RECALLED("RECALLED","已撤回"),
    EXPIRED("EXPIRED","已过期"),
    FILLING("FILLING","拟定中"),
    TERMINATING("TERMINATING","作废确认中"),
    TERMINATED("TERMINATED","已作废"),
    DELETE("DELETE","已删除"),
    FINISHED("FINISHED","已完成"),
    CANCELLED("CANCELLED","已作废");

    private final String val;
    private final String labCode;

    private static Map<String, MyContractStatus> enumMap;

    MyContractStatus(String val, String labCode) {
        this.val = val;
        this.labCode = labCode;
    }

    public String getVal() {
        return val;
    }

    public String getLabel() {
        return labCode;
    }
    public static MyContractStatus getInstByVal(String key) {
        if (enumMap == null) {
            synchronized (MyContractStatus.class) {
                if (enumMap == null) {
                    enumMap = new HashMap<String, MyContractStatus>();
                    for (MyContractStatus perEnum : MyContractStatus.values()) {
                        enumMap.put(perEnum.getVal() + "", perEnum);
                    }
                }
            }
        }
        if (!enumMap.containsKey(key)) {
            throw new RuntimeException("状态值" + key + "对应的MyContractStatus枚举值不存在。");
        }
        return enumMap.get(key);
    }

}

  

枚举的使用

标签:cts   hash   nis   fill   run   pre   public   sync   get   

原文地址:https://www.cnblogs.com/hanzhengjie/p/14483842.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!