一个枚举类

本文介绍了一个关于消息类型的枚举设计实例,详细展示了不同消息类型及其对应的描述,并提供了获取消息类型的方法。此外,还实现了将枚举类型转换为选择项映射的功能。
public enum MsgType {
    
    IPCHANGE_MSG(1, "ip地址改变警报"),
    LOCATION_CHANGE_MSG(2,"异地登录警报"),
    KEYWORD_MSG(3, "关键字警报"),
    STATUS_ABNORMAL_MSG(4, "状态异常警报"),
    APPTHRESHOLD_MSG(5, "ip地址改变警报"),
    USERTHRESHOLD_MSG(6, "ip地址改变警报"),
    APPERROE_MSG(7, "ip地址改变警报"),
    USERERROR_MSG(8, "ip地址改变警报");

    private Integer type;
    private String desc;

    private MsgType(Integer type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public static MsgType getMsgType(Integer code) {
        MsgType status = null;
        switch (code) {
        case 1:
            status = IPCHANGE_MSG;
            break;
        case 2:
            status = LOCATION_CHANGE_MSG;
            break;
        case 3:
            status = KEYWORD_MSG;
            break;
        case 4:
            status = STATUS_ABNORMAL_MSG;
            break;
        case 5:
            status = APPTHRESHOLD_MSG;
            break;
        case 6:
            status = USERTHRESHOLD_MSG;
            break;
        case 7:
            status = APPERROE_MSG;
            break;
        case 8:
            status = USERERROR_MSG;
            break;
        }
        return status;
    }

    public static Map<Integer, String> getChoiceMap() {
        HashMap<Integer, String> map = new HashMap<Integer, String>();
        for (MsgType item : MsgType.values()) {
            map.put(item.getType(), item.getDesc());
        }
        return map;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
 

 

转载于:https://www.cnblogs.com/duan2/p/7485434.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值