AMBARI-22297. Simplify getWithEmptyDefault using computeIfAbsent (adoroszlai)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e00b081c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e00b081c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e00b081c Branch: refs/heads/branch-feature-AMBARI-14714-blueprintv2 Commit: e00b081ced924d27cd66e2097e83e70c1a7c8ae2 Parents: ac80b4c Author: Attila Doroszlai <[email protected]> Authored: Fri Nov 17 10:26:55 2017 +0100 Committer: Doroszlai, Attila <[email protected]> Committed: Tue Dec 5 23:55:56 2017 +0100 ---------------------------------------------------------------------- .../java/org/apache/ambari/server/controller/StackV2.java | 7 +------ .../java/org/apache/ambari/server/topology/Configurable.java | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e00b081c/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java index 0b0329c..9bdd6a6 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2.java @@ -516,12 +516,7 @@ public class StackV2 { } static <OK, IK, IV> Map<IK, IV> getWithEmptyDefault(Map<OK, Map<IK, IV>> outerMap, OK outerKey) { - Map<IK, IV> innerMap = outerMap.get(outerKey); - if (null == innerMap) { - innerMap = new HashMap<>(); - outerMap.put(outerKey, innerMap); - } - return innerMap; + return outerMap.computeIfAbsent(outerKey, __ -> new HashMap<>()); } http://git-wip-us.apache.org/repos/asf/ambari/blob/e00b081c/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java index 0f3cf17..bab7da6 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Configurable.java @@ -49,7 +49,7 @@ public interface Configurable { if (null != getConfiguration()) { configAsMap.put("properties", getConfiguration().getProperties()); } - return Lists.newArrayList(configAsMap); + return Lists.newArrayList(configAsMap); // TODO replace with Collections.singletonList? } }
