提交 9dfaf8b0 authored 作者: jiangwujie's avatar jiangwujie

feature(货单、认证): 增加判空

上级 5802dd50
...@@ -21,10 +21,13 @@ public enum OrderGoodsEnum { ...@@ -21,10 +21,13 @@ public enum OrderGoodsEnum {
public static Optional<SendWaitModeEnum> getByCode(Integer code) { public static Optional<SendWaitModeEnum> getByCode(Integer code) {
if (code == null) {
return Optional.empty();
}
return Arrays.stream(values()).filter(e -> e.code.equals(code)).findFirst(); return Arrays.stream(values()).filter(e -> e.code.equals(code)).findFirst();
} }
public static String getMsgByCode(int code) { public static String getMsgByCode(Integer code) {
return getByCode(code).map(SendWaitModeEnum::getMsg).orElse(null); return getByCode(code).map(SendWaitModeEnum::getMsg).orElse(null);
} }
} }
...@@ -41,11 +44,18 @@ public enum OrderGoodsEnum { ...@@ -41,11 +44,18 @@ public enum OrderGoodsEnum {
public static Optional<SendWaitSystemMsgEnum> getByCode(Integer code) { public static Optional<SendWaitSystemMsgEnum> getByCode(Integer code) {
if (code == null) {
return Optional.empty();
}
return Arrays.stream(values()).filter(e -> e.code.equals(code)).findFirst(); return Arrays.stream(values()).filter(e -> e.code.equals(code)).findFirst();
} }
public static String getMsgByCode(int code) { public static String getMsgByCode(Integer code) {
return getByCode(code).map(SendWaitSystemMsgEnum::getMsg).orElse(null); return getByCode(code).map(SendWaitSystemMsgEnum::getMsg).orElse(null);
} }
} }
public static void main(String[] args) {
System.out.println(SendWaitModeEnum.getMsgByCode(null));
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论