Replace Map#putIfAbsent with Map#computeIfAbsent

pull/137/head
johnniang 2019-03-20 09:51:10 +08:00
parent 603be43a6a
commit e6060a54ae
2 changed files with 2 additions and 2 deletions

View File

@ -71,7 +71,7 @@ public class PostCategoryServiceImpl extends AbstractCrudService<PostCategory, I
Map<Integer, List<Category>> categoryListMap = new HashMap<>();
// Foreach and collect
postCategories.forEach(postCategory -> categoryListMap.putIfAbsent(postCategory.getPostId(), new LinkedList<>()).add(categoryMap.get(postCategory.getCategoryId())));
postCategories.forEach(postCategory -> categoryListMap.computeIfAbsent(postCategory.getPostId(), postId -> new LinkedList<>()).add(categoryMap.get(postCategory.getCategoryId())));
return categoryListMap;
}

View File

@ -71,7 +71,7 @@ public class PostTagServiceImpl extends AbstractCrudService<PostTag, Integer> im
Map<Integer, List<Tag>> tagListMap = new HashMap<>();
// Foreach and collect
postTags.forEach(postTag -> tagListMap.putIfAbsent(postTag.getPostId(), new LinkedList<>()).add(tagMap.get(postTag.getTagId())));
postTags.forEach(postTag -> tagListMap.computeIfAbsent(postTag.getPostId(), postId -> new LinkedList<>()).add(tagMap.get(postTag.getTagId())));
return tagListMap;
}