This is an automated email from the ASF dual-hosted git repository. mwalch 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 e6eb6b9 Replace loops that remove with Collection.removeIf (#1014) e6eb6b9 is described below commit e6eb6b9664e1a5054245fca44715c4d8877849e3 Author: Mike Walch <mwa...@apache.org> AuthorDate: Wed Mar 6 16:31:23 2019 -0500 Replace loops that remove with Collection.removeIf (#1014) --- .../apache/accumulo/fate/zookeeper/ZooCache.java | 23 +++------------------- .../accumulo/server/client/BulkImporter.java | 7 +------ .../java/org/apache/accumulo/master/Master.java | 8 +------- .../accumulo/shell/commands/SetIterCommand.java | 17 ++++------------ .../shell/commands/SetScanIterCommand.java | 8 +------- .../shell/commands/SetShellIterCommand.java | 17 ++-------------- .../accumulo/test/InterruptibleScannersIT.java | 13 +++--------- .../java/org/apache/accumulo/test/SampleIT.java | 8 +------- 8 files changed, 16 insertions(+), 85 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java index 499a9dc..7fff9ec 100644 --- a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java +++ b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java @@ -22,7 +22,6 @@ import java.security.SecureRandom; import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.locks.Lock; @@ -520,7 +519,6 @@ public class ZooCache { } finally { cacheReadLock.unlock(); } - } /** @@ -550,28 +548,13 @@ public class ZooCache { Preconditions.checkState(!closed); cacheWriteLock.lock(); try { - for (Iterator<String> i = cache.keySet().iterator(); i.hasNext();) { - String path = i.next(); - if (path.startsWith(zPath)) - i.remove(); - } - - for (Iterator<String> i = childrenCache.keySet().iterator(); i.hasNext();) { - String path = i.next(); - if (path.startsWith(zPath)) - i.remove(); - } - - for (Iterator<String> i = statCache.keySet().iterator(); i.hasNext();) { - String path = i.next(); - if (path.startsWith(zPath)) - i.remove(); - } + cache.keySet().removeIf(path -> path.startsWith(zPath)); + childrenCache.keySet().removeIf(path -> path.startsWith(zPath)); + statCache.keySet().removeIf(path -> path.startsWith(zPath)); immutableCache = new ImmutableCacheCopies(++updateCount, cache, statCache, childrenCache); } finally { cacheWriteLock.unlock(); } } - } 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 4f56b2d..2028706 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 @@ -236,12 +236,7 @@ public class BulkImporter { } // remove map files that have no more key extents to assign - Iterator<Entry<Path,List<KeyExtent>>> afIter = assignmentFailures.entrySet().iterator(); - while (afIter.hasNext()) { - Entry<Path,List<KeyExtent>> entry = afIter.next(); - if (entry.getValue().size() == 0) - afIter.remove(); - } + assignmentFailures.values().removeIf(List::isEmpty); Set<Entry<Path,Integer>> failureIter = failureCount.entrySet(); for (Entry<Path,Integer> entry : failureIter) { diff --git a/server/master/src/main/java/org/apache/accumulo/master/Master.java b/server/master/src/main/java/org/apache/accumulo/master/Master.java index 3e5fd7f..5d7fc6d 100644 --- a/server/master/src/main/java/org/apache/accumulo/master/Master.java +++ b/server/master/src/main/java/org/apache/accumulo/master/Master.java @@ -821,13 +821,7 @@ public class Master public void clearMigrations(TableId tableId) { synchronized (migrations) { - Iterator<KeyExtent> iterator = migrations.keySet().iterator(); - while (iterator.hasNext()) { - KeyExtent extent = iterator.next(); - if (extent.getTableId().equals(tableId)) { - iterator.remove(); - } - } + migrations.keySet().removeIf(extent -> extent.getTableId().equals(tableId)); } } diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/SetIterCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/SetIterCommand.java index d66d88b..092aef3 100644 --- a/shell/src/main/java/org/apache/accumulo/shell/commands/SetIterCommand.java +++ b/shell/src/main/java/org/apache/accumulo/shell/commands/SetIterCommand.java @@ -19,7 +19,6 @@ package org.apache.accumulo.shell.commands; import java.io.IOException; import java.util.EnumSet; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; @@ -143,12 +142,8 @@ public class SetIterCommand extends Command { ScanCommand.ensureTserversCanLoadIterator(shellState, tableName, classname); - for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();) { - final Entry<String,String> entry = i.next(); - if (entry.getValue() == null || entry.getValue().isEmpty()) { - i.remove(); - } - } + options.values().removeIf(v -> v == null || v.isEmpty()); + final EnumSet<IteratorScope> scopes = EnumSet.noneOf(IteratorScope.class); if (cl.hasOption(allScopeOpt.getOpt()) || cl.hasOption(mincScopeOpt.getOpt())) { scopes.add(IteratorScope.minc); @@ -181,12 +176,8 @@ public class SetIterCommand extends Command { + SortedKeyValueIterator.class.getName()); } - for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();) { - final Entry<String,String> entry = i.next(); - if (entry.getValue() == null || entry.getValue().isEmpty()) { - i.remove(); - } - } + options.values().removeIf(v -> v == null || v.isEmpty()); + final EnumSet<IteratorScope> scopes = EnumSet.noneOf(IteratorScope.class); if (cl.hasOption(allScopeOpt.getOpt()) || cl.hasOption(mincScopeOpt.getOpt())) { scopes.add(IteratorScope.minc); 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 0fa83e1..95b4582 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 @@ -22,7 +22,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; @@ -57,12 +56,7 @@ public class SetScanIterCommand extends SetIterCommand { ScanCommand.ensureTserversCanLoadIterator(shellState, tableName, classname); - for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();) { - final Entry<String,String> entry = i.next(); - if (entry.getValue() == null || entry.getValue().isEmpty()) { - i.remove(); - } - } + options.values().removeIf(v -> v == null || v.isEmpty()); List<IteratorSetting> tableScanIterators = shellState.scanIteratorOptions.get(tableName); if (tableScanIterators == null) { 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 2156ea8..e583078 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 @@ -18,10 +18,8 @@ package org.apache.accumulo.shell.commands; import java.io.IOException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; @@ -51,13 +49,7 @@ public class SetShellIterCommand extends SetIterCommand { String profile = cl.getOptionValue(profileOpt.getOpt()); - // instead of setting table properties, just put the options in a list to use at scan time - for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();) { - final Entry<String,String> entry = i.next(); - if (entry.getValue() == null || entry.getValue().isEmpty()) { - i.remove(); - } - } + options.values().removeIf(v -> v == null || v.isEmpty()); List<IteratorSetting> tableScanIterators = shellState.iteratorProfiles.get(profile); if (tableScanIterators == null) { @@ -67,12 +59,7 @@ public class SetShellIterCommand extends SetIterCommand { final IteratorSetting setting = new IteratorSetting(priority, name, classname); setting.addOptions(options); - Iterator<IteratorSetting> iter = tableScanIterators.iterator(); - while (iter.hasNext()) { - if (iter.next().getName().equals(name)) { - iter.remove(); - } - } + tableScanIterators.removeIf(iteratorSetting -> iteratorSetting.getName().equals(name)); tableScanIterators.add(setting); } diff --git a/test/src/main/java/org/apache/accumulo/test/InterruptibleScannersIT.java b/test/src/main/java/org/apache/accumulo/test/InterruptibleScannersIT.java index a647cde..a7a0c72 100644 --- a/test/src/main/java/org/apache/accumulo/test/InterruptibleScannersIT.java +++ b/test/src/main/java/org/apache/accumulo/test/InterruptibleScannersIT.java @@ -19,7 +19,6 @@ package org.apache.accumulo.test; import static org.junit.Assert.fail; import java.util.ArrayList; -import java.util.Iterator; import org.apache.accumulo.core.client.AccumuloClient; import org.apache.accumulo.core.client.IteratorSetting; @@ -69,15 +68,9 @@ public class InterruptibleScannersIT extends AccumuloClusterHarness { do { ArrayList<ActiveScan> scans = new ArrayList<>( client.instanceOperations().getActiveScans(tserver)); - Iterator<ActiveScan> iter = scans.iterator(); - while (iter.hasNext()) { - ActiveScan scan = iter.next(); - // Remove scans not against our table and not owned by us - if (!getAdminPrincipal().equals(scan.getUser()) - || !tableName.equals(scan.getTable())) { - iter.remove(); - } - } + // Remove scans not against our table and not owned by us + scans.removeIf(scan -> !getAdminPrincipal().equals(scan.getUser()) + || !tableName.equals(scan.getTable())); if (!scans.isEmpty()) { // We found our scan diff --git a/test/src/main/java/org/apache/accumulo/test/SampleIT.java b/test/src/main/java/org/apache/accumulo/test/SampleIT.java index ba7678b..28c4cde 100644 --- a/test/src/main/java/org/apache/accumulo/test/SampleIT.java +++ b/test/src/main/java/org/apache/accumulo/test/SampleIT.java @@ -164,13 +164,7 @@ public class SampleIT extends AccumuloClusterHarness { sb.setSamplerConfiguration(SC1); } - Iterator<Key> it = expected.keySet().iterator(); - while (it.hasNext()) { - Key k = it.next(); - if (k.getRow().toString().equals(someRow)) { - it.remove(); - } - } + expected.keySet().removeIf(k -> k.getRow().toString().equals(someRow)); expected.put(new Key(someRow, "cf1", "cq1", 8), new Value("42".getBytes())); expected.put(new Key(someRow, "cf1", "cq3", 8), new Value("suprise".getBytes()));