You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@eventmesh.apache.org by "mytang0 (via GitHub)" <gi...@apache.org> on 2023/03/23 01:57:04 UTC

[GitHub] [incubator-eventmesh] mytang0 commented on a diff in pull request #3499: [ISSUE #3481] Replace this "Map.containsKey()" with a call to "Map.computeIfAbsent()".

mytang0 commented on code in PR #3499:
URL: https://github.com/apache/incubator-eventmesh/pull/3499#discussion_r1145587175


##########
eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/Manufacturer.java:
##########
@@ -54,11 +54,7 @@ public void setManufacturerEventMap(Map<String, List<String>> manufacturerEventM
     }
 
     public List<String> getManufacturerEvents(String manufacturerName) {
-        if (!manufacturerEventMap.containsKey(manufacturerName)) {
-            List<String> m = new ArrayList<>();
-            manufacturerEventMap.put(manufacturerName, m);
-            return m;
-        }
+        manufacturerEventMap.computeIfAbsent(manufacturerName, key -> manufacturerEventMap.put(manufacturerName, new ArrayList<>()));

Review Comment:
   1. It is recommended to use ConcurrentHashMap
   2. The logic can be further simplified
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org