Loop replace with Collection.removeIf() (#36351)

This commit is contained in:
Igor Suhorukov 2018-12-10 13:26:24 +03:00 committed by Luca Cavanna
parent 6e6e63d01d
commit 0d9e3adc95
5 changed files with 6 additions and 36 deletions

View File

@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -104,13 +103,7 @@ public final class SettingsFilter {
}
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();
}

View File

@ -33,7 +33,6 @@ import org.elasticsearch.common.util.CollectionUtils;
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;
@ -206,12 +205,7 @@ public class ElectMasterService {
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;
}

View File

@ -245,12 +245,7 @@ public abstract class AsyncShardFetch<T extends BaseNodeResponse> implements Rel
}
}
// 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));
}
/**

View File

@ -65,7 +65,6 @@ import java.io.IOException;
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;
@ -135,12 +134,7 @@ public class IndicesStore implements ClusterStateListener, Closeable {
// 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);

View File

@ -2188,14 +2188,8 @@ public class TranslogTests extends ESTestCase {
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();
}
}
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);