优化枚举类
This commit is contained in:
parent
8bb2fa71f3
commit
c531135190
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>common-common</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.1.1</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package cn.azxo.framework.common.model;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 枚举抽象类
|
||||
*
|
||||
@ -21,4 +23,10 @@ public interface EnumBase<T> {
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
static <T extends EnumBase> T getByCode(Class<T> clazz, Object code) {
|
||||
return Stream.of(clazz.getEnumConstants())
|
||||
.filter(v -> v.getCode().equals(code))
|
||||
.findAny().orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user