DeviceCmdLogStatus success = EnumUtil.*getByName*(DeviceCmdLogStatus.class, "Success");
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| public class EnumUtil { public EnumUtil() { }
public static <T extends ValueEnum> T getByValue(Class<T> clazz, Object value) { if (value == null) { return null; } else { ValueEnum[] var2 = (ValueEnum[])clazz.getEnumConstants(); int var3 = var2.length;
for(int var4 = 0; var4 < var3; ++var4) { T t = var2[var4]; if (value.equals(t.getValue())) { return t; }
if ((value instanceof Integer || value instanceof String && value.toString().matches("^-?\\d+$")) && t.getValue().equals(Integer.valueOf(value.toString()))) { return t; }
if (value instanceof LinkedHashMap) { Object v = ((LinkedHashMap)value).get("value"); if (v != null && v.equals(t.getValue())) { return t; } } }
return null; } }
public static <T extends ValueEnum> T getByName(Class<T> clazz, Object name) { if (name == null) { return null; } else { ValueEnum[] var2 = (ValueEnum[])clazz.getEnumConstants(); int var3 = var2.length;
for(int var4 = 0; var4 < var3; ++var4) { T t = var2[var4]; if (name.equals(t.getValue())) { return t; }
if ((name instanceof Integer || name instanceof String && name.toString().matches("^-?\\d+$")) && t.getValue().equals(Integer.valueOf(name.toString()))) { return t; }
if (name instanceof LinkedHashMap) { Object v = ((LinkedHashMap)name).get("value"); if (v != null && v.equals(t.getValue())) { return t; } } }
return null; } } }
|