public enum LanguageEnum {//此处引用语言类型枚举
C("C"), CPP("C++"), JAVA("JAVA"), CS("C#"), JAVASCRIPT("JAVASCRIPT"), PYTHON("PYTHON"),HTML("HTML"),CSS("CSS");
private String value;
private static String[] svalues;
private LanguageEnum(String value) {
this.value = value; }
public String toString() { //toString 方法,将枚举转化为字符串
return value; }
public static LanguageEnum of(String language) { // of 方法,将字符串转换为枚举
for (LanguageEnum lan : LanguageEnum.values()) {
if (lan.toString().equals(language) || lan.name().equals(language)) {
return lan; } }
return null; }
public static String[] getValues() { //getValues 方法,获取所有枚举
if (svalues == null) {
LanguageEnum[] values = LanguageEnum.values();
svalues = new String[values.length];
for (int x = 0; x < values.length; x++) {
svalues[x] = values[x].toString(); } }
return svalues; }
public enum ToolEnum { //此处引用工具类型枚举a
ike, klocwork,sonarqube;
private static Map<String, Boolean> containsCache = new HashMap<>();
private static String[] shortnames = { "iKE", "KW" ,"SQ"}; //声明缩写
private static String[] cns = { "iKE", "Klocwork" ,"SonarQube"};//声明大写
public static ToolEnum of(String name) { //of 方法,字符串转化为枚举
for (ToolEnum tool : ToolEnum.values()) {
if (tool.name().equalsIgnoreCase(name)) {
return tool;}}
return null;}
public String shortname () { //声明 shortname 返回 shortname
return shortnames[this.ordinal()]; }
public String getCN () { //声明 getCN() 返回 cns
return cns[this.ordinal()];}
public static String[] sortnames() { //声明 sortnames 返回 shortnames 字符串数组
return shortnames;}
public static boolean isInclude(String key) { //判断 key 是否为枚举类型
boolean include = false;
for(ToolEnum e : ToolEnum.values()) {
if(e.name().equals(key)) {
include = true;
break; } }
return include;
}
public static boolean isIncludeCN(String key) { //判断 key 是否为 枚举类型的 cns
boolean include = false;
for(ToolEnum e : ToolEnum.values()) {
if(e.getCN().equals(key)) {
include = true;
break;}}
return include;
}