在正常的開發程序中可能需要對某個變數進行定義,把該變數放在列舉中以便后期的開發和維護,
一般情況下列舉中只使用get(),不使用set(),避免列舉值發生變化,
package com.wondersgroup.hnmi.jmggyw.common.enums;
import java.util.HashMap;
import java.util.Map;
/**
* @author sunchao
* @description 市縣鄉村組的級別
* @date 2019/10/6 17:52
*/
public enum Aab021Enum {
center("10", "中央"),
province("20", "省"),
city("40", "市、地區"),
county("50", "縣(區)"),
county_q("51", "區"),
county_x("52", "縣"),
country("60", "街道、鎮、鄉"),
country_jd("61", "街道"),
country_z("62", "鎮"),
country_x("63", "鄉"),
village("70", "居民、村民委員會"),
village_jm("71", "居民委員會"),
village_cm("72", "村民委員會"),
army("80", "軍隊"),
other("90", "其他"),
;
private static final Map<String, Aab021Enum> strToEnum = new HashMap<>();
static {
for (Aab021Enum type : Aab021Enum.values()) {
strToEnum.put(type.getCode(), type);
}
}
private String code;
private String msg;
Aab021Enum(String code, String msg) {
this.code = code;
this.msg = msg;
}
public static Aab021Enum fromString(String code) {
return strToEnum.get(code);
}
public String getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/38599.html
標籤:Java
上一篇:資料結構—平衡二叉樹(Java)
