mirror of https://github.com/ZhongFuCheng3y/austin
parent
70ba17de2a
commit
0a5c793bf4
@ -0,0 +1,30 @@
|
||||
package com.java3y.austin.common.enums;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnumUtil {
|
||||
|
||||
private EnumUtil() {
|
||||
}
|
||||
|
||||
public static <T extends PowerfulEnum> String getDescriptionByCode(Integer code, Class<T> enumClass) {
|
||||
return Arrays.stream(enumClass.getEnumConstants())
|
||||
.filter(e -> Objects.equals(e.getCode(), code))
|
||||
.findFirst().map(PowerfulEnum::getDescription).orElse("");
|
||||
}
|
||||
|
||||
public static <T extends PowerfulEnum> T getEnumByCode(Integer code, Class<T> enumClass) {
|
||||
return Arrays.stream(enumClass.getEnumConstants())
|
||||
.filter(e -> Objects.equals(e.getCode(), code))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static <T extends PowerfulEnum> List<Integer> getCodeList(Class<T> enumClass) {
|
||||
return Arrays.stream(enumClass.getEnumConstants())
|
||||
.map(PowerfulEnum::getCode)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.java3y.austin.common.enums;
|
||||
|
||||
public interface PowerfulEnum {
|
||||
|
||||
Integer getCode();
|
||||
|
||||
String getDescription();
|
||||
|
||||
}
|
Loading…
Reference in new issue