mirror of https://github.com/halo-dev/halo
Replace Map#putIfAbsent with Map#computeIfAbsent
parent
603be43a6a
commit
e6060a54ae
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue