1.枚举当做key-value业务使用

 package com.uwillbe.pad.enums;

 import java.util.ArrayList;
import java.util.List; /**
* @Author: 姿势帝
* @Description:
* @Date: Create in 14:36 2019/1/27
*/
public enum GroupEnum {
/**
* 分组id与分组名称
*/
GROUP_1(1, "物化历"),
GROUP_2(2, "物化地"),
GROUP_3(3, "物生历"),
GROUP_4(4, "物政历"),
GROUP_5(5, "物历地"),
GROUP_6(6, "物生政"),
GROUP_7(7, "物生地"),
GROUP_8(8, "物政地"),
GROUP_9(9, "物化政"),
GROUP_10(10, "物化生"),
GROUP_11(11, "化生历"),
GROUP_12(12, "化政历"),
GROUP_13(13, "化生政"),
GROUP_14(14, "化政地"),
GROUP_15(15, "化历地"),
GROUP_16(16, "化生地"),
GROUP_17(17, "生历地"),
GROUP_18(18, "生政地"),
GROUP_19(19, "生政历"),
GROUP_20(20, "政历地"); /** 枚举值 */
private final Integer code; /** 枚举描述 */
private final String message; /**
* 构造方法
* @param code
* @param message
*/
GroupEnum(Integer code, String message) {
this.code = code;
this.message = message;
} public Integer getCode() {
return code;
} public String getMessage() {
return message;
} /**
* 通过code获取msg
*
* @param code 枚举值
*
* @return
*/
public static String getMsgByCode(Integer code) {
if (code == null) {
return null;
}
GroupEnum enumList = getByCode(code);
if (enumList == null) {
return null;
}
return enumList.getMessage();
} /**
* 通过枚举<code>code</code>获得枚举
*
* values() 方法将枚举转变为数组
*
* @return AuthGradeEnum
*/
public static GroupEnum getByCode(Integer code) {
for (GroupEnum enumList : values()) {
if (enumList.getCode().equals(code)) {
return enumList;
}
}
return null;
} /**
* 获取全部枚举
*
* @return List<AuthGradeEnum>
*/
public static List<GroupEnum> getAllEnum() {
List<GroupEnum> list = new ArrayList<>(values().length);
for (GroupEnum enumList : values()) {
list.add(enumList);
}
return list;
} /**
* 获取全部枚举值
*
* @return List<String>
*/
public static List<Integer> getAllEnumCode() {
List<Integer> list = new ArrayList<>(values().length);
for (GroupEnum enumList : values()) {
list.add(enumList.getCode());
}
return list;
} }
05-11 20:03