You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by jm...@apache.org on 2020/03/17 21:51:07 UTC
[accumulo] branch master updated: Use single map method where
possible. (#1564)
This is an automated email from the ASF dual-hosted git repository.
jmark99 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/master by this push:
new 9d77257 Use single map method where possible. (#1564)
9d77257 is described below
commit 9d772570ca1985076a420c71ea27f3bd2b351eb7
Author: Mark Owens <jm...@apache.org>
AuthorDate: Tue Mar 17 17:50:57 2020 -0400
Use single map method where possible. (#1564)
* Use single map method where possible.
Replace common usage patterns of java.util.Map with Java 8 methods such as computeIfAbsent(), putIfAbsent(), etc.
Added additional refactoring to the various Map methods as well. Namely chaining commands where appropriate.
---
.../core/client/mapred/AccumuloOutputFormat.java | 18 +++-----
.../client/mapreduce/AccumuloOutputFormat.java | 18 +++-----
.../accumulo/core/clientImpl/ScannerOptions.java | 19 ++------
.../core/clientImpl/TableOperationsImpl.java | 14 ++----
.../core/clientImpl/TabletLocatorImpl.java | 15 +------
.../core/clientImpl/TabletServerBatchWriter.java | 20 ++-------
.../mapreduce/lib/InputConfigurator.java | 15 +------
.../apache/accumulo/core/conf/IterConfigUtil.java | 8 +---
.../core/iterators/user/ColumnSliceFilter.java | 26 +++--------
.../system/ColumnQualifierFilter.java | 15 +++----
.../format/ShardedTableDistributionFormatter.java | 3 +-
.../java/org/apache/accumulo/fate/AdminUtil.java | 9 +---
.../core/clientImpl/TabletLocatorImplTest.java | 35 +++------------
.../hadoopImpl/mapred/AccumuloRecordWriter.java | 17 +++----
.../hadoopImpl/mapreduce/AccumuloRecordWriter.java | 11 +----
.../mapreduce/lib/InputConfigurator.java | 15 +------
.../accumulo/server/client/BulkImporter.java | 52 ++++++----------------
.../accumulo/server/log/WalStateManager.java | 5 +--
.../master/balancer/DefaultLoadBalancer.java | 5 +--
.../balancer/HostRegexTableLoadBalancer.java | 13 ++----
.../server/master/balancer/TableLoadBalancer.java | 14 +++---
.../accumulo/server/util/MetadataTableUtil.java | 8 +---
.../server/util/VerifyTabletAssignments.java | 7 +--
.../master/balancer/DefaultLoadBalancerTest.java | 7 ++-
.../master/replication/SequentialWorkAssigner.java | 15 ++-----
.../create/SetupNamespacePermissions.java | 2 +-
.../org/apache/accumulo/tserver/FileManager.java | 22 ++-------
.../accumulo/tserver/log/SortedLogRecovery.java | 8 +---
.../shell/commands/SetScanIterCommand.java | 7 +--
.../shell/commands/SetShellIterCommand.java | 7 +--
30 files changed, 101 insertions(+), 329 deletions(-)
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java
index 5260748..738e624 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java
@@ -21,7 +21,6 @@ package org.apache.accumulo.core.client.mapred;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map.Entry;
import java.util.Set;
import org.apache.accumulo.core.client.AccumuloClient;
@@ -47,7 +46,6 @@ import org.apache.accumulo.core.clientImpl.DelegationTokenImpl;
import org.apache.accumulo.core.clientImpl.mapreduce.lib.OutputConfigurator;
import org.apache.accumulo.core.data.ColumnUpdate;
import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.core.data.TabletId;
import org.apache.accumulo.core.security.ColumnVisibility;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.io.Text;
@@ -551,17 +549,11 @@ public class AccumuloOutputFormat implements OutputFormat<Text,Mutation> {
mtbw.close();
} catch (MutationsRejectedException e) {
if (!e.getSecurityErrorCodes().isEmpty()) {
- HashMap<String,Set<SecurityErrorCode>> tables = new HashMap<>();
- for (Entry<TabletId,Set<SecurityErrorCode>> 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);
- }
- secCodes.addAll(ke.getValue());
- }
-
+ var tables = new HashMap<String,Set<SecurityErrorCode>>();
+ e.getSecurityErrorCodes().forEach((tabletId, secSet) -> {
+ var tableId = tabletId.getTableId().toString();
+ tables.computeIfAbsent(tableId, p -> new HashSet<>()).addAll(secSet);
+ });
log.error("Not authorized to write to tables : " + tables);
}
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloOutputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloOutputFormat.java
index b9fa8ea..39d3e9a 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloOutputFormat.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloOutputFormat.java
@@ -21,7 +21,6 @@ package org.apache.accumulo.core.client.mapreduce;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map.Entry;
import java.util.Set;
import org.apache.accumulo.core.client.AccumuloClient;
@@ -47,7 +46,6 @@ import org.apache.accumulo.core.clientImpl.DelegationTokenImpl;
import org.apache.accumulo.core.clientImpl.mapreduce.lib.OutputConfigurator;
import org.apache.accumulo.core.data.ColumnUpdate;
import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.core.data.TabletId;
import org.apache.accumulo.core.security.ColumnVisibility;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
@@ -552,17 +550,11 @@ public class AccumuloOutputFormat extends OutputFormat<Text,Mutation> {
mtbw.close();
} catch (MutationsRejectedException e) {
if (!e.getSecurityErrorCodes().isEmpty()) {
- HashMap<String,Set<SecurityErrorCode>> tables = new HashMap<>();
- for (Entry<TabletId,Set<SecurityErrorCode>> 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);
- }
- secCodes.addAll(ke.getValue());
- }
-
+ var tables = new HashMap<String,Set<SecurityErrorCode>>();
+ e.getSecurityErrorCodes().forEach((tabletId, secSet) -> {
+ var tableId = tabletId.getTableId().toString();
+ tables.computeIfAbsent(tableId, p -> new HashSet<>()).addAll(secSet);
+ });
log.error("Not authorized to write to tables : " + tables);
}
diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/ScannerOptions.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/ScannerOptions.java
index 3e19ddd..2a54d7e 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ScannerOptions.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ScannerOptions.java
@@ -92,14 +92,8 @@ public class ScannerOptions implements ScannerBase {
if (serverSideIteratorOptions.size() == 0) {
serverSideIteratorOptions = new HashMap<>();
}
-
- Map<String,String> opts = serverSideIteratorOptions.get(si.getName());
-
- if (opts == null) {
- opts = new HashMap<>();
- serverSideIteratorOptions.put(si.getName(), opts);
- }
- opts.putAll(si.getOptions());
+ serverSideIteratorOptions.computeIfAbsent(si.getName(), k -> new HashMap<>())
+ .putAll(si.getOptions());
}
@Override
@@ -128,14 +122,7 @@ public class ScannerOptions implements ScannerBase {
if (serverSideIteratorOptions.size() == 0) {
serverSideIteratorOptions = new HashMap<>();
}
-
- Map<String,String> opts = serverSideIteratorOptions.get(iteratorName);
-
- if (opts == null) {
- opts = new HashMap<>();
- serverSideIteratorOptions.put(iteratorName, opts);
- }
- opts.put(key, value);
+ serverSideIteratorOptions.computeIfAbsent(iteratorName, k -> new HashMap<>()).put(key, value);
}
@Override
diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java
index 1e89e04..29880bc 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java
@@ -1724,17 +1724,11 @@ public class TableOperationsImpl extends TableOperationsHelper {
if (groupedByRanges == null) {
Map<Range,List<TabletId>> tmp = new HashMap<>();
- for (Entry<TabletId,List<Range>> entry : groupedByTablets.entrySet()) {
- for (Range range : entry.getValue()) {
- List<TabletId> tablets = tmp.get(range);
- if (tablets == null) {
- tablets = new ArrayList<>();
- tmp.put(range, tablets);
- }
-
- tablets.add(entry.getKey());
+ groupedByTablets.forEach((table, rangeList) -> {
+ for (Range range : rangeList) {
+ tmp.computeIfAbsent(range, k -> new ArrayList<>()).add(table);
}
- }
+ });
Map<Range,List<TabletId>> tmp2 = new HashMap<>();
for (Entry<Range,List<TabletId>> entry : tmp.entrySet()) {
diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocatorImpl.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocatorImpl.java
index 9fdc9e2..06d8518 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocatorImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocatorImpl.java
@@ -730,19 +730,8 @@ public class TabletLocatorImpl extends TabletLocator {
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);
- }
-
- List<Range> tabletsRanges = tablets.get(ke);
- if (tabletsRanges == null) {
- tabletsRanges = new ArrayList<>();
- tablets.put(ke, tabletsRanges);
- }
-
- tabletsRanges.add(range);
+ binnedRanges.computeIfAbsent(location, k -> new HashMap<>())
+ .computeIfAbsent(ke, k -> new ArrayList<>()).add(range);
}
}
diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchWriter.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchWriter.java
index 015d7fa..3ca7da1 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchWriter.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchWriter.java
@@ -517,14 +517,9 @@ public class TabletServerBatchWriter implements AutoCloseable {
private void mergeAuthorizationFailures(Map<KeyExtent,Set<SecurityErrorCode>> source,
Map<KeyExtent,SecurityErrorCode> addition) {
- for (Entry<KeyExtent,SecurityErrorCode> entry : addition.entrySet()) {
- Set<SecurityErrorCode> secs = source.get(entry.getKey());
- if (secs == null) {
- secs = new HashSet<>();
- source.put(entry.getKey(), secs);
- }
- secs.add(entry.getValue());
- }
+ addition.forEach((ke, sec) -> {
+ source.computeIfAbsent(ke, p -> new HashSet<>()).add(sec);
+ });
}
private synchronized void updateServerErrors(String server, Exception e) {
@@ -1010,14 +1005,7 @@ public class TabletServerBatchWriter implements AutoCloseable {
}
void addMutation(TableId table, Mutation mutation) {
- List<Mutation> tabMutList = mutations.get(table);
- if (tabMutList == null) {
- tabMutList = new ArrayList<>();
- mutations.put(table, tabMutList);
- }
-
- tabMutList.add(mutation);
-
+ mutations.computeIfAbsent(table, k -> new ArrayList<>()).add(mutation);
memoryUsed += mutation.estimatedMemoryUsed();
}
diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/mapreduce/lib/InputConfigurator.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/mapreduce/lib/InputConfigurator.java
index e555b40..1254b35 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/mapreduce/lib/InputConfigurator.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/mapreduce/lib/InputConfigurator.java
@@ -892,19 +892,8 @@ public class InputConfigurator extends ConfiguratorBase {
throw new AccumuloException(" " + lastExtent + " is not previous extent " + extent);
}
- Map<KeyExtent,List<Range>> tabletRanges = binnedRanges.get(last);
- if (tabletRanges == null) {
- tabletRanges = new HashMap<>();
- binnedRanges.put(last, tabletRanges);
- }
-
- List<Range> rangeList = tabletRanges.get(extent);
- if (rangeList == null) {
- rangeList = new ArrayList<>();
- tabletRanges.put(extent, rangeList);
- }
-
- rangeList.add(range);
+ binnedRanges.computeIfAbsent(last, k -> new HashMap<>())
+ .computeIfAbsent(extent, k -> new ArrayList<>()).add(range);
if (extent.getEndRow() == null
|| range.afterEndKey(new Key(extent.getEndRow()).followingKey(PartialKey.ROW))) {
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/IterConfigUtil.java b/core/src/main/java/org/apache/accumulo/core/conf/IterConfigUtil.java
index f3e2ca1..1a204da 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/IterConfigUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/IterConfigUtil.java
@@ -116,13 +116,7 @@ public class IterConfigUtil {
String iterName = suffixSplit[0];
String optName = suffixSplit[2];
- Map<String,String> options = allOptions.get(iterName);
- if (options == null) {
- options = new HashMap<>();
- allOptions.put(iterName, options);
- }
-
- options.put(optName, entry.getValue());
+ allOptions.computeIfAbsent(iterName, k -> new HashMap<>()).put(optName, entry.getValue());
} else {
throw new IllegalArgumentException("Invalid iterator format: " + entry.getKey());
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnSliceFilter.java b/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnSliceFilter.java
index 020ab91..455b033 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnSliceFilter.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnSliceFilter.java
@@ -52,29 +52,15 @@ public class ColumnSliceFilter extends Filter {
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
IteratorEnvironment env) throws IOException {
super.init(source, options, env);
- if (options.containsKey(START_BOUND)) {
- startBound = options.get(START_BOUND);
- } else {
- startBound = null;
- }
+ startBound = options.getOrDefault(START_BOUND, null);
- if (options.containsKey(START_INCLUSIVE)) {
- startInclusive = Boolean.parseBoolean(options.get(START_INCLUSIVE));
- } else {
- startInclusive = true;
- }
+ startInclusive = options.containsKey(START_INCLUSIVE)
+ ? Boolean.parseBoolean(options.get(START_INCLUSIVE)) : true;
- if (options.containsKey(END_BOUND)) {
- endBound = options.get(END_BOUND);
- } else {
- endBound = null;
- }
+ endBound = options.getOrDefault(END_BOUND, null);
- if (options.containsKey(END_INCLUSIVE)) {
- endInclusive = Boolean.parseBoolean(options.get(END_INCLUSIVE));
- } else {
- endInclusive = false;
- }
+ endInclusive = options.containsKey(END_INCLUSIVE)
+ ? Boolean.parseBoolean(options.get(END_INCLUSIVE)) : false;
}
@Override
diff --git a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/ColumnQualifierFilter.java b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/ColumnQualifierFilter.java
index 29bafb0..8687d15 100644
--- a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/ColumnQualifierFilter.java
+++ b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/ColumnQualifierFilter.java
@@ -40,21 +40,16 @@ public class ColumnQualifierFilter extends ServerFilter {
this.columnFamilies = new HashSet<>();
this.columnsQualifiers = new HashMap<>();
- for (Column col : columns) {
+ columns.forEach(col -> {
if (col.columnQualifier != null) {
- ArrayByteSequence cq = new ArrayByteSequence(col.columnQualifier);
- HashSet<ByteSequence> cfset = this.columnsQualifiers.get(cq);
- if (cfset == null) {
- cfset = new HashSet<>();
- this.columnsQualifiers.put(cq, cfset);
- }
-
- cfset.add(new ArrayByteSequence(col.columnFamily));
+ this.columnsQualifiers
+ .computeIfAbsent(new ArrayByteSequence(col.columnQualifier), k -> new HashSet<>())
+ .add(new ArrayByteSequence(col.columnFamily));
} else {
// this whole column family should pass
columnFamilies.add(new ArrayByteSequence(col.columnFamily));
}
- }
+ });
}
private ColumnQualifierFilter(SortedKeyValueIterator<Key,Value> iterator,
diff --git a/core/src/main/java/org/apache/accumulo/core/util/format/ShardedTableDistributionFormatter.java b/core/src/main/java/org/apache/accumulo/core/util/format/ShardedTableDistributionFormatter.java
index 640f46d..a7a9a30 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/format/ShardedTableDistributionFormatter.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/format/ShardedTableDistributionFormatter.java
@@ -53,8 +53,7 @@ public class ShardedTableDistributionFormatter extends AggregatingFormatter {
} else
day = "NULL ";
String server = entry.getValue().toString();
- if (countsByDay.get(day) == null)
- countsByDay.put(day, new HashSet<>());
+ countsByDay.computeIfAbsent(day, k -> new HashSet<>());
countsByDay.get(day).add(server);
}
}
diff --git a/core/src/main/java/org/apache/accumulo/fate/AdminUtil.java b/core/src/main/java/org/apache/accumulo/fate/AdminUtil.java
index 38a02a6..f062bb2 100644
--- a/core/src/main/java/org/apache/accumulo/fate/AdminUtil.java
+++ b/core/src/main/java/org/apache/accumulo/fate/AdminUtil.java
@@ -301,13 +301,8 @@ public class AdminUtil<T> {
}
}
- List<String> tables = locks.get(Long.parseLong(lda[1], 16));
- if (tables == null) {
- tables = new ArrayList<>();
- locks.put(Long.parseLong(lda[1], 16), tables);
- }
-
- tables.add(lda[0].charAt(0) + ":" + id);
+ locks.computeIfAbsent(Long.parseLong(lda[1], 16), k -> new ArrayList<>())
+ .add(lda[0].charAt(0) + ":" + id);
} catch (Exception e) {
log.error("{}", e.getMessage(), e);
diff --git a/core/src/test/java/org/apache/accumulo/core/clientImpl/TabletLocatorImplTest.java b/core/src/test/java/org/apache/accumulo/core/clientImpl/TabletLocatorImplTest.java
index 1dfbaae..84ceff1 100644
--- a/core/src/test/java/org/apache/accumulo/core/clientImpl/TabletLocatorImplTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/clientImpl/TabletLocatorImplTest.java
@@ -296,19 +296,8 @@ public class TabletLocatorImplTest {
String server = (String) ol[1];
KeyExtent ke = (KeyExtent) ol[2];
- Map<KeyExtent,List<String>> tb = emb.get(server);
- if (tb == null) {
- tb = new HashMap<>();
- emb.put(server, tb);
- }
-
- List<String> rl = tb.get(ke);
- if (rl == null) {
- rl = new ArrayList<>();
- tb.put(ke, rl);
- }
-
- rl.add(row);
+ emb.computeIfAbsent(server, k -> new HashMap<>()).computeIfAbsent(ke, k -> new ArrayList<>())
+ .add(row);
}
return emb;
@@ -527,11 +516,8 @@ public class TabletLocatorImplTest {
}
static void createEmptyTablet(TServers tservers, String server, KeyExtent tablet) {
- Map<KeyExtent,SortedMap<Key,Value>> tablets = tservers.tservers.get(server);
- if (tablets == null) {
- tablets = new HashMap<>();
- tservers.tservers.put(server, tablets);
- }
+ Map<KeyExtent,SortedMap<Key,Value>> tablets =
+ tservers.tservers.computeIfAbsent(server, k -> new HashMap<>());
SortedMap<Key,Value> tabletData = tablets.get(tablet);
if (tabletData == null) {
@@ -562,17 +548,10 @@ public class TabletLocatorImplTest {
static void setLocation(TServers tservers, String server, KeyExtent tablet, KeyExtent ke,
String location, String instance) {
- Map<KeyExtent,SortedMap<Key,Value>> tablets = tservers.tservers.get(server);
- if (tablets == null) {
- tablets = new HashMap<>();
- tservers.tservers.put(server, tablets);
- }
+ Map<KeyExtent,SortedMap<Key,Value>> tablets =
+ tservers.tservers.computeIfAbsent(server, k -> new HashMap<>());
- SortedMap<Key,Value> tabletData = tablets.get(tablet);
- if (tabletData == null) {
- tabletData = new TreeMap<>();
- tablets.put(tablet, tabletData);
- }
+ SortedMap<Key,Value> tabletData = tablets.computeIfAbsent(tablet, k -> new TreeMap<>());
Text mr = ke.getMetadataEntry();
Value per = KeyExtent.encodePrevEndRow(ke.getPrevEndRow());
diff --git a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapred/AccumuloRecordWriter.java b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapred/AccumuloRecordWriter.java
index cdea20d..702f482 100644
--- a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapred/AccumuloRecordWriter.java
+++ b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapred/AccumuloRecordWriter.java
@@ -21,7 +21,6 @@ package org.apache.accumulo.hadoopImpl.mapred;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import org.apache.accumulo.core.client.AccumuloClient;
@@ -35,7 +34,6 @@ import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.data.ColumnUpdate;
import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.core.data.TabletId;
import org.apache.accumulo.core.security.ColumnVisibility;
import org.apache.accumulo.hadoop.mapred.AccumuloOutputFormat;
import org.apache.accumulo.hadoopImpl.mapreduce.lib.OutputConfigurator;
@@ -187,16 +185,11 @@ public class AccumuloRecordWriter implements RecordWriter<Text,Mutation> {
mtbw.close();
} catch (MutationsRejectedException e) {
if (!e.getSecurityErrorCodes().isEmpty()) {
- HashMap<String,Set<SecurityErrorCode>> tables = new HashMap<>();
- for (Map.Entry<TabletId,Set<SecurityErrorCode>> 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);
- }
- secCodes.addAll(ke.getValue());
- }
+ var tables = new HashMap<String,Set<SecurityErrorCode>>();
+ e.getSecurityErrorCodes().forEach((tabletId, secSet) -> {
+ String tableId = tabletId.getTableId().toString();
+ tables.computeIfAbsent(tableId, p -> new HashSet<>()).addAll(secSet);
+ });
log.error("Not authorized to write to tables : " + tables);
}
diff --git a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/AccumuloRecordWriter.java b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/AccumuloRecordWriter.java
index d89a845..48e2e34 100644
--- a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/AccumuloRecordWriter.java
+++ b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/AccumuloRecordWriter.java
@@ -21,7 +21,6 @@ package org.apache.accumulo.hadoopImpl.mapreduce;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import org.apache.accumulo.core.client.AccumuloClient;
@@ -35,7 +34,6 @@ import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.data.ColumnUpdate;
import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.core.data.TabletId;
import org.apache.accumulo.core.security.ColumnVisibility;
import org.apache.accumulo.hadoop.mapreduce.AccumuloOutputFormat;
import org.apache.accumulo.hadoopImpl.mapreduce.lib.OutputConfigurator;
@@ -189,14 +187,9 @@ public class AccumuloRecordWriter extends RecordWriter<Text,Mutation> {
} catch (MutationsRejectedException e) {
if (!e.getSecurityErrorCodes().isEmpty()) {
HashMap<String,Set<SecurityErrorCode>> tables = new HashMap<>();
- for (Map.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);
- }
- secCodes.addAll(ke.getValue());
+ tables.computeIfAbsent(tableId, k -> new HashSet<>()).addAll(ke.getValue());
}
log.error("Not authorized to write to tables : " + tables);
diff --git a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/InputConfigurator.java b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/InputConfigurator.java
index f710aea..d15d855 100644
--- a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/InputConfigurator.java
+++ b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/InputConfigurator.java
@@ -880,19 +880,8 @@ public class InputConfigurator extends ConfiguratorBase {
throw new AccumuloException(" " + lastExtent + " is not previous extent " + extent);
}
- Map<KeyExtent,List<Range>> tabletRanges = binnedRanges.get(last);
- if (tabletRanges == null) {
- tabletRanges = new HashMap<>();
- binnedRanges.put(last, tabletRanges);
- }
-
- List<Range> rangeList = tabletRanges.get(extent);
- if (rangeList == null) {
- rangeList = new ArrayList<>();
- tabletRanges.put(extent, rangeList);
- }
-
- rangeList.add(range);
+ binnedRanges.computeIfAbsent(last, k -> new HashMap<>())
+ .computeIfAbsent(extent, k -> new ArrayList<>()).add(range);
if (extent.getEndRow() == null
|| range.afterEndKey(new Key(extent.getEndRow()).followingKey(PartialKey.ROW))) {
diff --git a/server/base/src/main/java/org/apache/accumulo/server/client/BulkImporter.java b/server/base/src/main/java/org/apache/accumulo/server/client/BulkImporter.java
index 10b0433..2db5a4b 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/client/BulkImporter.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/client/BulkImporter.java
@@ -461,23 +461,17 @@ public class BulkImporter {
}
private void handleFailures(Collection<KeyExtent> failures, String message) {
- for (KeyExtent ke : failures) {
+ failures.forEach(ke -> {
List<PathSize> mapFiles = assignmentsPerTablet.get(ke);
synchronized (assignmentFailures) {
- for (PathSize pathSize : mapFiles) {
- List<KeyExtent> existingFailures = assignmentFailures.get(pathSize.path);
- if (existingFailures == null) {
- existingFailures = new ArrayList<>();
- assignmentFailures.put(pathSize.path, existingFailures);
- }
-
- existingFailures.add(ke);
- }
+ mapFiles.forEach(pathSize -> {
+ assignmentFailures.computeIfAbsent(pathSize.path, k -> new ArrayList<>()).add(ke);
+ });
}
log.info("Could not assign {} map files to tablet {} because : {}. Will retry ...",
mapFiles.size(), ke, message);
- }
+ });
}
@Override
@@ -520,20 +514,13 @@ public class BulkImporter {
// group assignments by tablet
Map<KeyExtent,List<PathSize>> assignmentsPerTablet = new TreeMap<>();
- for (Entry<Path,List<AssignmentInfo>> entry : assignments.entrySet()) {
- Path mapFile = entry.getKey();
- List<AssignmentInfo> tabletsToAssignMapFileTo = entry.getValue();
-
- for (AssignmentInfo ai : tabletsToAssignMapFileTo) {
- List<PathSize> mapFiles = assignmentsPerTablet.get(ai.ke);
- if (mapFiles == null) {
- mapFiles = new ArrayList<>();
- assignmentsPerTablet.put(ai.ke, mapFiles);
- }
- mapFiles.add(new PathSize(mapFile, ai.estSize));
- }
- }
+ assignments.forEach((mapFile, tabletsToAssignMapFileTo) -> {
+ tabletsToAssignMapFileTo.forEach(ai -> {
+ assignmentsPerTablet.computeIfAbsent(ai.ke, k -> new ArrayList<>())
+ .add(new PathSize(mapFile, ai.estSize));
+ });
+ });
// group assignments by tabletserver
@@ -548,13 +535,7 @@ public class BulkImporter {
if (location == null) {
for (PathSize pathSize : entry.getValue()) {
synchronized (assignmentFailures) {
- List<KeyExtent> failures = assignmentFailures.get(pathSize.path);
- if (failures == null) {
- failures = new ArrayList<>();
- assignmentFailures.put(pathSize.path, failures);
- }
-
- failures.add(ke);
+ assignmentFailures.computeIfAbsent(pathSize.path, k -> new ArrayList<>()).add(ke);
}
}
@@ -565,13 +546,8 @@ public class BulkImporter {
continue;
}
- Map<KeyExtent,List<PathSize>> apt = assignmentsPerTabletServer.get(location);
- if (apt == null) {
- apt = new TreeMap<>();
- assignmentsPerTabletServer.put(location, apt);
- }
-
- apt.put(entry.getKey(), entry.getValue());
+ assignmentsPerTabletServer.computeIfAbsent(location, k -> new TreeMap<>()).put(entry.getKey(),
+ entry.getValue());
}
ExecutorService threadPool =
diff --git a/server/base/src/main/java/org/apache/accumulo/server/log/WalStateManager.java b/server/base/src/main/java/org/apache/accumulo/server/log/WalStateManager.java
index a8bce74..855c582 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/log/WalStateManager.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/log/WalStateManager.java
@@ -197,10 +197,7 @@ public class WalStateManager {
String path = root();
for (String child : zoo.getChildren(path)) {
TServerInstance inst = new TServerInstance(child);
- List<UUID> logs = result.get(inst);
- if (logs == null) {
- result.put(inst, logs = new ArrayList<>());
- }
+ List<UUID> logs = result.computeIfAbsent(inst, k -> new ArrayList<>());
// This function is called by the Accumulo GC which deletes WAL markers. Therefore we do not
// expect the following call to fail because the WAL info in ZK was deleted.
diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java
index 2653f99..96e0cad 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java
@@ -223,10 +223,9 @@ public class DefaultLoadBalancer extends TabletBalancer {
// look for an uneven table count
int biggestDifference = 0;
TableId biggestDifferenceTable = null;
- for (Entry<TableId,Integer> tableEntry : tooMuchMap.entrySet()) {
+ for (var tableEntry : tooMuchMap.entrySet()) {
TableId tableID = tableEntry.getKey();
- if (tooLittleMap.get(tableID) == null)
- tooLittleMap.put(tableID, 0);
+ tooLittleMap.putIfAbsent(tableID, 0);
int diff = tableEntry.getValue() - tooLittleMap.get(tableID);
if (diff > biggestDifference) {
biggestDifference = diff;
diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java
index 880bab5..3560a47 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java
@@ -351,15 +351,10 @@ public class HostRegexTableLoadBalancer extends TableLoadBalancer {
Map<String,SortedMap<TServerInstance,TabletServerStatus>> pools = splitCurrentByRegex(current);
// group the unassigned into tables
Map<TableId,Map<KeyExtent,TServerInstance>> groupedUnassigned = new HashMap<>();
- for (Entry<KeyExtent,TServerInstance> e : unassigned.entrySet()) {
- Map<KeyExtent,TServerInstance> tableUnassigned =
- groupedUnassigned.get(e.getKey().getTableId());
- if (tableUnassigned == null) {
- tableUnassigned = new HashMap<>();
- groupedUnassigned.put(e.getKey().getTableId(), tableUnassigned);
- }
- tableUnassigned.put(e.getKey(), e.getValue());
- }
+ unassigned.forEach((keyExtent, tServerInstance) -> {
+ groupedUnassigned.computeIfAbsent(keyExtent.getTableId(), p -> new HashMap<>()).put(keyExtent,
+ tServerInstance);
+ });
Map<TableId,String> tableIdToTableName = createdTableNameMap(getTableOperations().tableIdMap());
diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/TableLoadBalancer.java b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/TableLoadBalancer.java
index 855ce18..5ecc41d 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/TableLoadBalancer.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/TableLoadBalancer.java
@@ -118,15 +118,11 @@ public class TableLoadBalancer extends TabletBalancer {
Map<KeyExtent,TServerInstance> unassigned, Map<KeyExtent,TServerInstance> assignments) {
// separate the unassigned into tables
Map<TableId,Map<KeyExtent,TServerInstance>> groupedUnassigned = new HashMap<>();
- for (Entry<KeyExtent,TServerInstance> e : unassigned.entrySet()) {
- Map<KeyExtent,TServerInstance> tableUnassigned =
- groupedUnassigned.get(e.getKey().getTableId());
- if (tableUnassigned == null) {
- tableUnassigned = new HashMap<>();
- groupedUnassigned.put(e.getKey().getTableId(), tableUnassigned);
- }
- tableUnassigned.put(e.getKey(), e.getValue());
- }
+ unassigned.forEach((keyExtent, tServerInstance) -> {
+ groupedUnassigned.computeIfAbsent(keyExtent.getTableId(), p -> new HashMap<>()).put(keyExtent,
+ tServerInstance);
+ });
+
for (Entry<TableId,Map<KeyExtent,TServerInstance>> e : groupedUnassigned.entrySet()) {
Map<KeyExtent,TServerInstance> newAssignments = new HashMap<>();
getBalancerForTable(e.getKey()).getAssignments(current, e.getValue(), newAssignments);
diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java b/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
index e855821..c0984fe 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
@@ -717,13 +717,7 @@ public class MetadataTableUtil {
Text row = entry.getKey().getRow();
- SortedMap<ColumnFQ,Value> colVals = tabletEntries.get(row);
- if (colVals == null) {
- colVals = new TreeMap<>();
- tabletEntries.put(row, colVals);
- }
-
- colVals.put(currentKey, entry.getValue());
+ tabletEntries.computeIfAbsent(row, k -> new TreeMap<>()).put(currentKey, entry.getValue());
}
return tabletEntries;
diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/VerifyTabletAssignments.java b/server/base/src/main/java/org/apache/accumulo/server/util/VerifyTabletAssignments.java
index bb76cb4..abdda09 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/util/VerifyTabletAssignments.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/VerifyTabletAssignments.java
@@ -112,11 +112,8 @@ public class VerifyTabletAssignments {
if (loc != null) {
final HostAndPort parsedLoc = HostAndPort.fromString(loc);
- List<KeyExtent> extentList = extentsPerServer.get(parsedLoc);
- if (extentList == null) {
- extentList = new ArrayList<>();
- extentsPerServer.put(parsedLoc, extentList);
- }
+ List<KeyExtent> extentList =
+ extentsPerServer.computeIfAbsent(parsedLoc, k -> new ArrayList<>());
if (check == null || check.contains(keyExtent))
extentList.add(keyExtent);
diff --git a/server/base/src/test/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancerTest.java b/server/base/src/test/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancerTest.java
index 0c7e4b9..71f3775 100644
--- a/server/base/src/test/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancerTest.java
+++ b/server/base/src/test/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancerTest.java
@@ -271,13 +271,12 @@ public class DefaultLoadBalancerTest {
if (expectedCounts != null) {
for (FakeTServer server : servers.values()) {
Map<String,Integer> counts = new HashMap<>();
- for (KeyExtent extent : server.extents) {
+ for (var extent : server.extents) {
String t = extent.getTableId().canonical();
- if (counts.get(t) == null)
- counts.put(t, 0);
+ counts.putIfAbsent(t, 0);
counts.put(t, counts.get(t) + 1);
}
- for (Entry<String,Integer> entry : counts.entrySet()) {
+ for (var entry : counts.entrySet()) {
assertEquals(expectedCounts.get(entry.getKey()), counts.get(entry.getKey()));
}
}
diff --git a/server/master/src/main/java/org/apache/accumulo/master/replication/SequentialWorkAssigner.java b/server/master/src/main/java/org/apache/accumulo/master/replication/SequentialWorkAssigner.java
index 7457109..7837332 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/replication/SequentialWorkAssigner.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/replication/SequentialWorkAssigner.java
@@ -104,13 +104,7 @@ public class SequentialWorkAssigner extends DistributedWorkQueueWorkAssigner {
log.debug("In progress replication of {} from table with ID {} to peer {}", filename,
sourceTableId, peerName);
- Map<TableId,String> replicationForPeer = queuedWorkByPeerName.get(peerName);
- if (replicationForPeer == null) {
- replicationForPeer = new HashMap<>();
- queuedWorkByPeerName.put(peerName, replicationForPeer);
- }
-
- replicationForPeer.put(sourceTableId, work);
+ queuedWorkByPeerName.computeIfAbsent(peerName, k -> new HashMap<>()).put(sourceTableId, work);
}
}
@@ -173,11 +167,8 @@ public class SequentialWorkAssigner extends DistributedWorkQueueWorkAssigner {
@Override
protected boolean queueWork(Path path, ReplicationTarget target) {
String queueKey = DistributedWorkQueueWorkAssignerHelper.getQueueKey(path.getName(), target);
- Map<TableId,String> workForPeer = this.queuedWorkByPeerName.get(target.getPeerName());
- if (workForPeer == null) {
- workForPeer = new HashMap<>();
- this.queuedWorkByPeerName.put(target.getPeerName(), workForPeer);
- }
+ Map<TableId,String> workForPeer =
+ this.queuedWorkByPeerName.computeIfAbsent(target.getPeerName(), k -> new HashMap<>());
String queuedWork = workForPeer.get(target.getSourceTableId());
if (queuedWork == null) {
diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/namespace/create/SetupNamespacePermissions.java b/server/master/src/main/java/org/apache/accumulo/master/tableOps/namespace/create/SetupNamespacePermissions.java
index 65c1e56..57b0717 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/namespace/create/SetupNamespacePermissions.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/namespace/create/SetupNamespacePermissions.java
@@ -41,7 +41,7 @@ class SetupNamespacePermissions extends MasterRepo {
public Repo<Master> call(long tid, Master env) throws Exception {
// give all namespace permissions to the creator
SecurityOperation security = AuditedSecurityOperation.getInstance(env.getContext());
- for (NamespacePermission permission : NamespacePermission.values()) {
+ for (var permission : NamespacePermission.values()) {
try {
security.grantNamespacePermission(env.getContext().rpcCreds(), namespaceInfo.user,
namespaceInfo.namespaceId, permission);
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/FileManager.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/FileManager.java
index 66ee7ec..eaff0ba 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/FileManager.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/FileManager.java
@@ -221,13 +221,7 @@ public class FileManager {
}
private static <T> List<T> getFileList(String file, Map<String,List<T>> files) {
- List<T> ofl = files.get(file);
- if (ofl == null) {
- ofl = new ArrayList<>();
- files.put(file, ofl);
- }
-
- return ofl;
+ return files.computeIfAbsent(file, k -> new ArrayList<>());
}
private void closeReaders(Collection<FileSKVIterator> filesToClose) {
@@ -594,17 +588,9 @@ public class FileManager {
Map<FileSKVIterator,String> newlyReservedReaders = openFiles(files);
Map<String,List<FileSKVIterator>> map = new HashMap<>();
- for (Entry<FileSKVIterator,String> entry : newlyReservedReaders.entrySet()) {
- FileSKVIterator reader = entry.getKey();
- String fileName = entry.getValue();
- List<FileSKVIterator> list = map.get(fileName);
- if (list == null) {
- list = new LinkedList<>();
- map.put(fileName, list);
- }
-
- list.add(reader);
- }
+ newlyReservedReaders.forEach((reader, fileName) -> {
+ map.computeIfAbsent(fileName, k -> new LinkedList<>()).add(reader);
+ });
for (FileDataSource fds : dataSources) {
FileSKVIterator source = map.get(fds.file).remove(0);
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/log/SortedLogRecovery.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/log/SortedLogRecovery.java
index 9371eef..5d1faef 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/log/SortedLogRecovery.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/log/SortedLogRecovery.java
@@ -144,13 +144,7 @@ public class SortedLogRecovery {
for (Path wal : recoveryLogs) {
int tabletId = findMaxTabletId(extent, Collections.singletonList(wal));
if (tabletId != -1) {
- List<Path> perIdList = logsThatDefineTablet.get(tabletId);
- if (perIdList == null) {
- perIdList = new ArrayList<>();
- logsThatDefineTablet.put(tabletId, perIdList);
-
- }
- perIdList.add(wal);
+ logsThatDefineTablet.computeIfAbsent(tabletId, k -> new ArrayList<>()).add(wal);
log.debug("Found tablet {} with id {} in recovery log {}", extent, tabletId, wal.getName());
} else {
log.debug("Did not find tablet {} in recovery log {}", extent, wal.getName());
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/SetScanIterCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/SetScanIterCommand.java
index 66fd1f2..a92a0c1 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/SetScanIterCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/SetScanIterCommand.java
@@ -59,11 +59,8 @@ public class SetScanIterCommand extends SetIterCommand {
options.values().removeIf(v -> v == null || v.isEmpty());
- List<IteratorSetting> tableScanIterators = shellState.scanIteratorOptions.get(tableName);
- if (tableScanIterators == null) {
- tableScanIterators = new ArrayList<>();
- shellState.scanIteratorOptions.put(tableName, tableScanIterators);
- }
+ List<IteratorSetting> tableScanIterators =
+ shellState.scanIteratorOptions.computeIfAbsent(tableName, k -> new ArrayList<>());
final IteratorSetting setting = new IteratorSetting(priority, name, classname);
setting.addOptions(options);
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/SetShellIterCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/SetShellIterCommand.java
index 7bf92da..21b4d2a 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/SetShellIterCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/SetShellIterCommand.java
@@ -53,11 +53,8 @@ public class SetShellIterCommand extends SetIterCommand {
options.values().removeIf(v -> v == null || v.isEmpty());
- List<IteratorSetting> tableScanIterators = shellState.iteratorProfiles.get(profile);
- if (tableScanIterators == null) {
- tableScanIterators = new ArrayList<>();
- shellState.iteratorProfiles.put(profile, tableScanIterators);
- }
+ List<IteratorSetting> tableScanIterators =
+ shellState.iteratorProfiles.computeIfAbsent(profile, k -> new ArrayList<>());
final IteratorSetting setting = new IteratorSetting(priority, name, classname);
setting.addOptions(options);