package com.nanometer.smartlab.entity.enumtype; import java.util.HashMap; public enum WarningLevel { WARN(1, "警告"), ERROR(2, "错误"), FATAL(3, "危险"), MORE_FATAL(4, "严重危险"); private int levelCode; private String levelMsg; private WarningLevel(int levelCode, String levelMsg) { this.levelCode = levelCode; this.levelMsg = levelMsg; } public int getLevelCode() { return levelCode; } public String getLevelMsg() { return levelMsg; } private static HashMap map = new HashMap(); static { for(WarningLevel d : WarningLevel.values()){ map.put(d.levelCode, d); } } public static WarningLevel parse(Integer index) { if(map.containsKey(index)){ return map.get(index); } return null; } }