Skip to content

Commit

Permalink
Loop replace with Collection.removeIf() (elastic#36351)
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-suhorukov authored and javanna committed Dec 18, 2018
1 parent 9a5af3b commit 171e097
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -104,13 +103,7 @@ private static Settings filterSettings(Iterable<String> patterns, Settings setti
}
if (!simpleMatchPatternList.isEmpty()) {
String[] simpleMatchPatterns = simpleMatchPatternList.toArray(new String[simpleMatchPatternList.size()]);
Iterator<String> iterator = builder.keys().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
if (Regex.simpleMatch(simpleMatchPatterns, key)) {
iterator.remove();
}
}
builder.keys().removeIf(key -> Regex.simpleMatch(simpleMatchPatterns, key));
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -206,12 +205,7 @@ private List<DiscoveryNode> sortedMasterNodes(Iterable<DiscoveryNode> nodes) {
return null;
}
// clean non master nodes
for (Iterator<DiscoveryNode> it = possibleNodes.iterator(); it.hasNext(); ) {
DiscoveryNode node = it.next();
if (!node.isMasterNode()) {
it.remove();
}
}
possibleNodes.removeIf(node -> !node.isMasterNode());
CollectionUtil.introSort(possibleNodes, ElectMasterService::compareNodes);
return possibleNodes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@ private void fillShardCacheWithDataNodes(Map<String, NodeEntry<T>> shardCache, D
}
}
// remove nodes that are not longer part of the data nodes set
for (Iterator<String> it = shardCache.keySet().iterator(); it.hasNext(); ) {
String nodeId = it.next();
if (nodes.nodeExists(nodeId) == false) {
it.remove();
}
}
shardCache.keySet().removeIf(nodeId -> !nodes.nodeExists(nodeId));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -134,12 +133,7 @@ public void clusterChanged(ClusterChangedEvent event) {
// remove entries from cache that don't exist in the routing table anymore (either closed or deleted indices)
// - removing shard data of deleted indices is handled by IndicesClusterStateService
// - closed indices don't need to be removed from the cache but we do it anyway for code simplicity
for (Iterator<ShardId> it = folderNotFoundCache.iterator(); it.hasNext(); ) {
ShardId shardId = it.next();
if (routingTable.hasIndex(shardId.getIndex()) == false) {
it.remove();
}
}
folderNotFoundCache.removeIf(shardId -> !routingTable.hasIndex(shardId.getIndex()));
// remove entries from cache which are allocated to this node
final String localNodeId = event.state().nodes().getLocalNodeId();
RoutingNode localRoutingNode = event.state().getRoutingNodes().node(localNodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2195,14 +2195,8 @@ protected void afterAdd() throws IOException {
Collections.sort(writtenOperations, (a, b) -> a.location.compareTo(b.location));
assertFalse(translog.isOpen());
final Checkpoint checkpoint = Checkpoint.read(config.getTranslogPath().resolve(Translog.CHECKPOINT_FILE_NAME));
Iterator<LocationOperation> iterator = writtenOperations.iterator();
while (iterator.hasNext()) {
LocationOperation next = iterator.next();
if (checkpoint.offset < (next.location.translogLocation + next.location.size)) {
// drop all that haven't been synced
iterator.remove();
}
}
// drop all that haven't been synced
writtenOperations.removeIf(next -> checkpoint.offset < (next.location.translogLocation + next.location.size));
try (Translog tlog =
new Translog(config, translogUUID, createTranslogDeletionPolicy(),
() -> SequenceNumbers.NO_OPS_PERFORMED, primaryTerm::get);
Expand Down

0 comments on commit 171e097

Please sign in to comment.