WhetherEnums.java
777 Bytes
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
package com.bs.common.enums;
import java.util.Optional;
import java.util.stream.Stream;
public enum WhetherEnums {
YES(1,"是"),
NO(0,"否"),
WZ(2,"未知")
;
private final Integer code;
private final String info;
WhetherEnums(Integer code, String info)
{
this.code = code;
this.info = info;
}
public Integer getCode() {
return code;
}
public String getInfo() {
return info;
}
public static Optional<WhetherEnums> ofByCode(Integer code) {
return Stream.of(values()).filter(s -> s.code.equals(code)).findFirst();
}
public static Optional<WhetherEnums> ofByInfo(String info) {
return Stream.of(values()).filter(s -> s.info.equals(info)).findFirst();
}
}