package com.ycl.jxkg.enums; import java.util.HashMap; import java.util.Map; public enum QuestionTypeEnum { SingleChoice(1, "单选题"), MultipleChoice(2, "多选题"), TrueFalse(3, "判断题"), GapFilling(4, "填空题"), ShortAnswer(5, "简答题"), Audio(6,"语音题"), Calculate(7,"计算题"), Analysis(8,"分析题"); Integer code; String name; QuestionTypeEnum(Integer code, String name) { this.code = code; this.name = name; } private static Map keyMap = new HashMap<>(); static { for (QuestionTypeEnum item : QuestionTypeEnum.values()) { keyMap.put(item.getCode(), item); } } public static QuestionTypeEnum fromCode(Integer code) { return keyMap.get(code); } public static boolean needSaveTextContent(Integer code) { QuestionTypeEnum questionTypeEnum = QuestionTypeEnum.fromCode(code); switch (questionTypeEnum) { case GapFilling: case ShortAnswer: return true; default: return false; } } public Integer getCode() { return code; } public String getName() { return name; } public static Integer get(String text){ if("".equals(text) || text == null){ return null; } QuestionTypeEnum[] enums = QuestionTypeEnum.values(); for (QuestionTypeEnum anEnum : enums) { if(anEnum.getName().equals(text)){ return anEnum.getCode(); } } return null; } }