/**
* 审核状态的枚举类
*
* @@author gouwenyong
* @date 2020年9月18日10:06:38
*/
public enum StatusEnum {
SUBMIT(0, "提交"),
UNDER_REVIEW(1, "审核中"),
SUCCESSFUL_REVIEW(2, "审核成功"),
RELEASE(3, "发布");
int code;
String msg;
StatusEnum() { }
StatusEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
/**
* 通过code获取msg
*
* @param code
* @return
*/
public static String getMsg(int code) {
for (StatusEnum entry : values()) {//values()类似于map的迭代时的Entry
if (code == entry.getCode()) {
return entry.getMsg();
}
}
throw new IllegalArgumentException("枚举类型异常");
}
/**
* 通过msg获取code
*
* @param msg
* @return
*/
public static int getCode(String msg) {
for (StatusEnum entry : values()) {//values()类似于map的迭代时的Entry
if (msg.equals(entry.getMsg())) {
return entry.getCode();
}
}
throw new IllegalArgumentException("枚举类型异常");
}
}
枚举类模板
最新推荐文章于 2023-01-03 17:21:09 发布