码迷,mamicode.com
首页 > 编程语言 > 详细

【java】java枚举模板

时间:2020-03-18 17:16:08      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:string   script   复制   instance   top   color   add   opera   esc   

 

今日份:

/**
 * @Author: SXD
 * @Description: 操作枚举
 * @Date: create in 2020/3/18 16:11
 */
public enum OperateTypeEnum {

    ADD(1,"新增"),
    EDIT(2,"编辑"),
    VIEW(3,"查看"),
    REAPPLY(4,"重新申请"),
    COPY(5,"复制");

    private Integer value;

    private String desc;

    OperateTypeEnum(Integer type, String desc) {
        this.value = type;
        this.desc = desc;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据value值获取枚举对象
     * @param value
     * @return
     */
    public static OperateTypeEnum getOperateType(Integer value){
        OperateTypeEnum[] instances = OperateTypeEnum.values();
        for(OperateTypeEnum instance : instances){
            if(instance.getValue() == value){
                return instance;
            }
        }

        return null;
    }

}

 

=============

 

【java】java枚举模板

标签:string   script   复制   instance   top   color   add   opera   esc   

原文地址:https://www.cnblogs.com/sxdcgaq8080/p/12518459.html

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