From 1f303ff1de5d8bca063d0774e4f17ebeda00eeff Mon Sep 17 00:00:00 2001 From: bleachtred Date: Fri, 7 Jul 2023 17:41:33 +0800 Subject: [PATCH] =?UTF-8?q?update=20stream=E6=B5=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB=E5=85=B6=E4=BB=96=E6=96=B9=E6=B3=95=E8=BF=87=E6=BB=A4?= =?UTF-8?q?null=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/dromara/common/core/utils/StreamUtils.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/StreamUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/StreamUtils.java index d9dcb401..967612ef 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/StreamUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/StreamUtils.java @@ -72,7 +72,7 @@ public class StreamUtils { return CollUtil.newArrayList(); } // 注意此处不要使用 .toList() 新语法 因为返回的是不可变List 会导致序列化问题 - return collection.stream().sorted(comparing).collect(Collectors.toList()); + return collection.stream().filter(Objects::nonNull).sorted(comparing).collect(Collectors.toList()); } /** @@ -89,7 +89,7 @@ public class StreamUtils { if (CollUtil.isEmpty(collection)) { return MapUtil.newHashMap(); } - return collection.stream().collect(Collectors.toMap(key, Function.identity(), (l, r) -> l)); + return collection.stream().filter(Objects::nonNull).collect(Collectors.toMap(key, Function.identity(), (l, r) -> l)); } /** @@ -108,7 +108,7 @@ public class StreamUtils { if (CollUtil.isEmpty(collection)) { return MapUtil.newHashMap(); } - return collection.stream().collect(Collectors.toMap(key, value, (l, r) -> l)); + return collection.stream().filter(Objects::nonNull).collect(Collectors.toMap(key, value, (l, r) -> l)); } /** @@ -126,7 +126,7 @@ public class StreamUtils { return MapUtil.newHashMap(); } return collection - .stream() + .stream().filter(Objects::nonNull) .collect(Collectors.groupingBy(key, LinkedHashMap::new, Collectors.toList())); } @@ -147,7 +147,7 @@ public class StreamUtils { return MapUtil.newHashMap(); } return collection - .stream() + .stream().filter(Objects::nonNull) .collect(Collectors.groupingBy(key1, LinkedHashMap::new, Collectors.groupingBy(key2, LinkedHashMap::new, Collectors.toList()))); } @@ -168,7 +168,7 @@ public class StreamUtils { return MapUtil.newHashMap(); } return collection - .stream() + .stream().filter(Objects::nonNull) .collect(Collectors.groupingBy(key1, LinkedHashMap::new, Collectors.toMap(key2, Function.identity(), (l, r) -> l))); }