|
|
@@ -0,0 +1,42 @@ |
|
|
|
package com.ningdatech.kqapi.common.enumeration; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* IEnum-通用枚举类接口 |
|
|
|
* </p> |
|
|
|
* |
|
|
|
* @author WendyYang |
|
|
|
* @since 10:10 2024/4/22 |
|
|
|
*/ |
|
|
|
public interface IEnum<C, V, E extends Enum<E> & IEnum<C, V, E>> { |
|
|
|
|
|
|
|
E[] all(); |
|
|
|
|
|
|
|
C getCode(); |
|
|
|
|
|
|
|
V getDesc(); |
|
|
|
|
|
|
|
default boolean eq(C code) { |
|
|
|
return getCode().equals(code); |
|
|
|
} |
|
|
|
|
|
|
|
default Optional<E> getByCode(C code) { |
|
|
|
return Arrays.stream(all()) |
|
|
|
.filter(w -> w.getCode().equals(code)) |
|
|
|
.findFirst(); |
|
|
|
} |
|
|
|
|
|
|
|
default E getNoNull(C code) { |
|
|
|
return Arrays.stream(all()) |
|
|
|
.filter(w -> w.getCode().equals(code)).findFirst() |
|
|
|
.orElseThrow(() -> new IllegalArgumentException("编码对应枚举值不存在")); |
|
|
|
} |
|
|
|
|
|
|
|
default V getDesc(C code) { |
|
|
|
return getByCode(code).flatMap(w -> Optional.of(w.getDesc())).orElse(null); |
|
|
|
} |
|
|
|
|
|
|
|
} |