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 f0d43c794..c5487c0b6 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 @@ -1,6 +1,7 @@ package org.dromara.common.core.utils; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -148,7 +149,7 @@ public class StreamUtils { */ public static Map toIdentityMap(Collection collection, Function key) { if (CollUtil.isEmpty(collection)) { - return Collections.emptyMap(); + return MapUtil.newHashMap(); } return collection.stream() .filter(Objects::nonNull) @@ -169,7 +170,7 @@ public class StreamUtils { */ public static Map toMap(Collection collection, Function key, Function value) { if (CollUtil.isEmpty(collection)) { - return Collections.emptyMap(); + return MapUtil.newHashMap(); } return collection.stream() .filter(Objects::nonNull) @@ -187,7 +188,7 @@ public class StreamUtils { */ public static Map toMap(Map map, BiFunction take) { if (CollUtil.isEmpty(map)) { - return Collections.emptyMap(); + return MapUtil.newHashMap(); } return toMap(map.entrySet(), Map.Entry::getKey, entry -> take.apply(entry.getKey(), entry.getValue())); } @@ -204,7 +205,7 @@ public class StreamUtils { */ public static Map> groupByKey(Collection collection, Function key) { if (CollUtil.isEmpty(collection)) { - return Collections.emptyMap(); + return MapUtil.newHashMap(); } return collection.stream() .filter(Objects::nonNull) @@ -225,7 +226,7 @@ public class StreamUtils { */ public static Map>> groupBy2Key(Collection collection, Function key1, Function key2) { if (CollUtil.isEmpty(collection)) { - return Collections.emptyMap(); + return MapUtil.newHashMap(); } return collection.stream() .filter(Objects::nonNull) @@ -246,7 +247,7 @@ public class StreamUtils { */ public static Map> group2Map(Collection collection, Function key1, Function key2) { if (CollUtil.isEmpty(collection)) { - return Collections.emptyMap(); + return MapUtil.newHashMap(); } return collection.stream() .filter(Objects::nonNull) @@ -286,7 +287,7 @@ public class StreamUtils { */ public static Set toSet(Collection collection, Function function) { if (CollUtil.isEmpty(collection)) { - return Collections.emptySet(); + return CollUtil.newHashSet(); } return collection.stream() .map(function) @@ -310,7 +311,7 @@ public class StreamUtils { public static Map merge(Map map1, Map map2, BiFunction merge) { if (CollUtil.isEmpty(map1) && CollUtil.isEmpty(map2)) { // 如果两个 map 都为空,则直接返回空的 map - return Collections.emptyMap(); + return MapUtil.newHashMap(); } else if (CollUtil.isEmpty(map1)) { // 如果 map1 为空,则直接处理返回 map2 return toMap(map2.entrySet(), Map.Entry::getKey, entry -> merge.apply(null, entry.getValue()));