package com.goafanti.common.enums; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.StringUtils; public enum UserLevel { GENERAL(0, "注册客户"), CERTIFIED(1, "认证会员"), SECONDLEVEL(2, "二级会员"), THIRDLEVEL(3, "三级会员"), FORTHLEVEL(4, "四级会员"), FIFTHLEVEL(5, "五级会员"); private UserLevel(Integer code, String desc) { this.code = code; this.desc = desc; } private static Map status = new HashMap(); static { for (UserLevel value : UserLevel.values()) { status.put(value.getCode(), value); } } public static UserLevel getStatus(Integer code) { if (containsType(code)) { return status.get(code); } return GENERAL; } public static UserLevel getStatus(String code) { if (StringUtils.isNumeric(code)) { return getStatus(Integer.parseInt(code)); } return GENERAL; } public static boolean containsType(Integer code) { return status.containsKey(code); } private Integer code; private String desc; public Integer getCode() { return code; } public String getDesc() { return desc; } }