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/16 20:26:42 UTC
[GitHub] [accumulo] jmark99 opened a new pull request #1564: Use single map
method where possible.
jmark99 opened a new pull request #1564: Use single map method where possible.
URL: https://github.com/apache/accumulo/pull/1564
Replace common usage patterns of java.util.Map with Java 8 methods such as computeIfAbsent(), putIfAbsent(), etc.
----------------------------------------------------------------
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
[GitHub] [accumulo] ctubbsii commented on a change in pull request #1564:
Use single map method where possible.
Posted by GitBox <gi...@apache.org>.
ctubbsii commented on a change in pull request #1564: Use single map method where possible.
URL: https://github.com/apache/accumulo/pull/1564#discussion_r393403373
##########
File path: core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java
##########
@@ -552,13 +550,9 @@ public void close(Reporter reporter) throws IOException {
} catch (MutationsRejectedException e) {
if (!e.getSecurityErrorCodes().isEmpty()) {
HashMap<String,Set<SecurityErrorCode>> tables = new HashMap<>();
- for (Entry<TabletId,Set<SecurityErrorCode>> ke : e.getSecurityErrorCodes().entrySet()) {
+ for (var ke : e.getSecurityErrorCodes().entrySet()) {
Review comment:
If there aren't any checked exceptions, you can probably do `e.getSecurityErrorCodes().forEach(...)` instead of a loop over the entry set.
----------------------------------------------------------------
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
[GitHub] [accumulo] ctubbsii commented on a change in pull request #1564:
Use single map method where possible.
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [accumulo] ctubbsii commented on a change in pull request #1564:
Use single map method where possible.
Posted by GitBox <gi...@apache.org>.
ctubbsii commented on a change in pull request #1564: Use single map method where possible.
URL: https://github.com/apache/accumulo/pull/1564#discussion_r393436962
##########
File path: test/src/main/java/org/apache/accumulo/test/functional/ManyWriteAheadLogsIT.java
##########
@@ -213,7 +213,8 @@ private void addOpenWals(ServerContext c, Set<String> allWalsSeen) throws Except
allWalsSeen.add(entry.getKey());
foundWal = true;
} else {
- log.debug("The WalState for {} is {}", entry.getKey(), entry.getValue()); // CLOSED or UNREFERENCED
+ log.debug("The WalState for {} is {}", entry.getKey(), entry.getValue()); // CLOSED or
+ // UNREFERENCED
Review comment:
Disregard this one. I fixed the formatting in the master branch.
----------------------------------------------------------------
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
[GitHub] [accumulo] jmark99 commented on issue #1564: Use single map method
where possible.
Posted by GitBox <gi...@apache.org>.
jmark99 commented on issue #1564: Use single map method where possible.
URL: https://github.com/apache/accumulo/pull/1564#issuecomment-600245338
@ctubbsii I added additional refactoring/chaining as you suggested. Can you take a look and verify I didn't break anything along the way. I successfully ran the unit tests and Sunny IT's.
----------------------------------------------------------------
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
[GitHub] [accumulo] ctubbsii commented on a change in pull request #1564:
Use single map method where possible.
Posted by GitBox <gi...@apache.org>.
ctubbsii commented on a change in pull request #1564: Use single map method where possible.
URL: https://github.com/apache/accumulo/pull/1564#discussion_r393404423
##########
File path: core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java
##########
@@ -552,13 +550,9 @@ public void close(Reporter reporter) throws IOException {
} catch (MutationsRejectedException e) {
if (!e.getSecurityErrorCodes().isEmpty()) {
HashMap<String,Set<SecurityErrorCode>> tables = new HashMap<>();
- for (Entry<TabletId,Set<SecurityErrorCode>> ke : e.getSecurityErrorCodes().entrySet()) {
+ for (var ke : e.getSecurityErrorCodes().entrySet()) {
String tableId = ke.getKey().getTableId().toString();
- Set<SecurityErrorCode> secCodes = tables.get(tableId);
- if (secCodes == null) {
- secCodes = new HashSet<>();
- tables.put(tableId, secCodes);
- }
+ Set<SecurityErrorCode> secCodes = tables.computeIfAbsent(tableId, k -> new HashSet<>());
Review comment:
One of the great things about `.computeIfAbsent()` is that you don't need to assign it to a variable... you could just immediately use it on the next line:
```java
tables.computeIfAbsent(tableId, k -> new HashSet<>()).addAll(ke.getValue());
```
----------------------------------------------------------------
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
[GitHub] [accumulo] jmark99 merged pull request #1564: Use single map method
where possible.
Posted by GitBox <gi...@apache.org>.
jmark99 merged pull request #1564: Use single map method where possible.
URL: https://github.com/apache/accumulo/pull/1564
----------------------------------------------------------------
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
[GitHub] [accumulo] ctubbsii commented on a change in pull request #1564:
Use single map method where possible.
Posted by GitBox <gi...@apache.org>.
ctubbsii commented on a change in pull request #1564: Use single map method where possible.
URL: https://github.com/apache/accumulo/pull/1564#discussion_r393406424
##########
File path: test/src/main/java/org/apache/accumulo/test/functional/ManyWriteAheadLogsIT.java
##########
@@ -213,7 +213,8 @@ private void addOpenWals(ServerContext c, Set<String> allWalsSeen) throws Except
allWalsSeen.add(entry.getKey());
foundWal = true;
} else {
- log.debug("The WalState for {} is {}", entry.getKey(), entry.getValue()); // CLOSED or UNREFERENCED
+ log.debug("The WalState for {} is {}", entry.getKey(), entry.getValue()); // CLOSED or
+ // UNREFERENCED
Review comment:
This seems unrelated. If having trouble with the formatter, could just remove that comment at the end of the line, or put it above the log statement.
----------------------------------------------------------------
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