This commit is contained in:
Looly 2022-05-09 10:10:43 +08:00
parent 8cf462408d
commit 62f851142b
2 changed files with 4 additions and 2 deletions

View File

@ -3,10 +3,11 @@
-------------------------------------------------------------------------------------------------------------
# 5.8.1.M1 (2022-05-06)
# 5.8.1.M1 (2022-05-09)
### 🐣新特性
### 🐞Bug修复
* 【core 】 MapUtil.map对null友好且修复了测试用例中分组问题pr#614@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -82,7 +82,8 @@ public class MapUtilTest {
// 如你所见它是一个mapkey由用户idvalue由用户组成
Map<Long, User> idUserMap = Stream.iterate(0L, i -> ++i).limit(4).map(i -> User.builder().id(i).name(customers.poll()).build()).collect(Collectors.toMap(User::getId, Function.identity()));
// 如你所见它是一个mapkey由分组idvalue由用户ids组成典型的多对多关系
Map<Long, List<Long>> groupIdUserIdsMap = groups.stream().flatMap(group -> idUserMap.keySet().stream().map(userId -> UserGroup.builder().groupId(group.getId()).userId(userId).build())).collect(Collectors.groupingBy(UserGroup::getGroupId, Collectors.mapping(UserGroup::getUserId, Collectors.toList())));
Map<Long, List<Long>> groupIdUserIdsMap = groups.stream().flatMap(group -> idUserMap.keySet().stream().map(userId -> UserGroup.builder().groupId(group.getId()).userId(userId).build()))
.collect(Collectors.groupingBy(UserGroup::getGroupId, Collectors.mapping(UserGroup::getUserId, Collectors.toList())));
// 神奇的魔法发生了 分组id和用户ids组成的map竟然变成了订单编号和用户实体集合组成的map
Map<Long, List<User>> groupIdUserMap = MapUtil.map(groupIdUserIdsMap, (groupId, userIds) -> userIds.stream().map(idUserMap::get).collect(Collectors.toList()));