package com.lunhan.xxx.entity.enums; import java.util.Arrays; import java.util.Objects; /** * 状态 枚举 */ public enum EState { /** * 正常=1, */ NORMAL("正常", 1), /** * 关闭/停用=2, */ DISABLED("关闭/停用", 2), /** * 删除=3, */ DELETED("删除", 3); /** * 枚举描述 */ private String desc; /** * 枚举值 */ private Integer value; public Integer getValue() { return value; } public String getDesc() { return desc; } /** * 构造方法 * @param desc 枚举描述 * @param value 枚举值 */ EState(String desc, Integer value) { this.desc = desc; this.value = value; } /** * 根据值获取枚举 * * @param value 枚举值 * @return */ public static EState getByValue(Integer value) { return Arrays.stream(EState.values()) .filter(e -> Objects.equals(e.getValue(), value)) .findAny() .orElse(null); } @Override public String toString() { return "EState{" + "desc='" + desc + '\'' + ", value=" + value + '}'; } }