From e6060a54ae28ab1681577b89743d395a799d857c Mon Sep 17 00:00:00 2001 From: johnniang Date: Wed, 20 Mar 2019 09:51:10 +0800 Subject: [PATCH] Replace Map#putIfAbsent with Map#computeIfAbsent --- .../cc/ryanc/halo/service/impl/PostCategoryServiceImpl.java | 2 +- .../java/cc/ryanc/halo/service/impl/PostTagServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/cc/ryanc/halo/service/impl/PostCategoryServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/PostCategoryServiceImpl.java index d7094da74..b3ad4cacf 100644 --- a/src/main/java/cc/ryanc/halo/service/impl/PostCategoryServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/PostCategoryServiceImpl.java @@ -71,7 +71,7 @@ public class PostCategoryServiceImpl extends AbstractCrudService> 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; } diff --git a/src/main/java/cc/ryanc/halo/service/impl/PostTagServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/PostTagServiceImpl.java index 45607cc57..efbcd6025 100644 --- a/src/main/java/cc/ryanc/halo/service/impl/PostTagServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/PostTagServiceImpl.java @@ -71,7 +71,7 @@ public class PostTagServiceImpl extends AbstractCrudService im Map> 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; }