zoukankan      html  css  js  c++  java
  • Java 枚举类型设置数据字典

    package org.seckill.enums;
    
    /**
     * 使用枚举表示常量数据字典
     * Created by 18401 on 2017/11/25.
     */
    public enum SeckillStateEnum {
        SUCCESS(1, "秒杀成功"),
        END(0, "秒杀结束"),
        REPEAT_KILL(-1,"重复秒杀"),
        INNER_ERROR(-2,"系统异常"),
        DATA_REWRITE(-3,"数据篡改")
        ;
    
        private int state;
        private String stateInfo;
    
        SeckillStateEnum(int state, String stateInfo) {
            this.state = state;
            this.stateInfo = stateInfo;
        }
    
        public int getState() {
            return state;
        }
    
        public String getStateInfo() {
            return stateInfo;
        }
    
        public static SeckillStateEnum stateOf(int index){
            for(SeckillStateEnum state : values()){
                if(state.getState() == index){
                    return state;
                }
            }
            return null;
        }
    }
    

      

      public static SeckillStateEnum stateOf(int index){
            for(SeckillStateEnum state : values()){
                if(state.getState() == index){
                    return state;
                }
            }
            return null;
        }
    static<T extens Enum<T>> valueOf(class<T> enumType,String name) 根据名字返回enum实例
    传入index,获取SeckillStateEnum的实例
  • 相关阅读:
    Linux pmap 工具
    bzoj 1060 贪心
    bzoj 1076 状压DP
    bzoj 1150 贪心
    bzoj 1412 最小割 网络流
    bzoj 3212 线段树
    bzoj 1942 斜率优化DP
    bzoj 1876 高精
    bzoj 1880 最短路
    斜率优化DP讲解
  • 原文地址:https://www.cnblogs.com/luffe/p/7976924.html
Copyright © 2011-2022 走看看