You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2020/03/17 02:11:58 UTC

[GitHub] [accumulo] ctubbsii commented on a change in pull request #1564: Use single map method where possible.

ctubbsii commented on a change in pull request #1564: Use single map method where possible.
URL: https://github.com/apache/accumulo/pull/1564#discussion_r393405647
 
 

 ##########
 File path: core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocatorImpl.java
 ##########
 @@ -730,17 +730,10 @@ private void processInvalidated(ClientContext context, LockCheckerSession lcSess
 
   protected static void addRange(Map<String,Map<KeyExtent,List<Range>>> binnedRanges,
       String location, KeyExtent ke, Range range) {
-    Map<KeyExtent,List<Range>> tablets = binnedRanges.get(location);
-    if (tablets == null) {
-      tablets = new HashMap<>();
-      binnedRanges.put(location, tablets);
-    }
+    Map<KeyExtent,List<Range>> tablets =
+        binnedRanges.computeIfAbsent(location, k -> new HashMap<>());
 
-    List<Range> tabletsRanges = tablets.get(ke);
-    if (tabletsRanges == null) {
-      tabletsRanges = new ArrayList<>();
-      tablets.put(ke, tabletsRanges);
-    }
+    List<Range> tabletsRanges = tablets.computeIfAbsent(ke, k -> new ArrayList<>());
 
 Review comment:
   These look like they can simplify to:
   
   ```java
   binnedRanges.computeIfAbsent(location, k -> new HashMap<>())
     .computeIfAbsent(ke, k -> new ArrayList<>())
     .add(range);
   ```
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services