Use enhanced for loop where feasible

See gh-31916
This commit is contained in:
Yanming Zhou 2023-12-28 15:15:07 +08:00 committed by Stéphane Nicoll
parent ed1bfb8177
commit 4a450c6fab
6 changed files with 10 additions and 17 deletions

View File

@ -201,9 +201,8 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
List<BeanReference> beanReferences = new ArrayList<>();
List<Element> declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS);
for (int i = METHOD_INDEX; i < declareParents.size(); i++) {
Element declareParentsElement = declareParents.get(i);
beanDefinitions.add(parseDeclareParents(declareParentsElement, parserContext));
for (Element declareParent : declareParents) {
beanDefinitions.add(parseDeclareParents(declareParent, parserContext));
}
// We have to parse "advice" and all the advice kinds in one loop, to get the

View File

@ -23,7 +23,6 @@ import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -268,8 +267,8 @@ public class GenericBean<T> {
public void setCustomEnumSetMismatch(Set<String> customEnumSet) {
this.customEnumSet = new HashSet<>(customEnumSet.size());
for (Iterator<String> iterator = customEnumSet.iterator(); iterator.hasNext(); ) {
this.customEnumSet.add(CustomEnum.valueOf(iterator.next()));
for (String customEnumName : customEnumSet) {
this.customEnumSet.add(CustomEnum.valueOf(customEnumName));
}
}

View File

@ -24,7 +24,6 @@ import java.rmi.MarshalException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -1224,8 +1223,7 @@ public abstract class AbstractAopProxyTests {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
ReflectiveMethodInvocation rmi = (ReflectiveMethodInvocation) invocation;
for (Iterator<String> it = rmi.getUserAttributes().keySet().iterator(); it.hasNext(); ){
Object key = it.next();
for (Object key : rmi.getUserAttributes().keySet()) {
assertThat(rmi.getUserAttributes().get(key)).isEqualTo(expectedValues.get(key));
}
rmi.getUserAttributes().putAll(valuesToAdd);

View File

@ -186,8 +186,8 @@ class CommonsPool2TargetSourceTests {
pooledInstances[9] = targetSource.getTarget();
// release all objects
for (int i = 0; i < pooledInstances.length; i++) {
targetSource.releaseTarget(pooledInstances[i]);
for (Object pooledInstance : pooledInstances) {
targetSource.releaseTarget(pooledInstance);
}
}

View File

@ -607,8 +607,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
// Restructure the resized reference array
if (resizing) {
Reference<K, V>[] restructured = createReferenceArray(restructureSize);
for (int i = 0; i < this.references.length; i++) {
ref = this.references[i];
for (Reference<K, V> reference : this.references) {
ref = reference;
while (ref != null) {
if (!toPurge.contains(ref)) {
Entry<K, V> entry = ref.get();

View File

@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.concurrent.CompletableFuture;
import org.eclipse.jetty.client.ContentResponse;
@ -172,9 +171,7 @@ public class JettyXhrTransport extends AbstractXhrTransport implements Lifecycle
private static HttpHeaders toHttpHeaders(HttpFields httpFields) {
HttpHeaders responseHeaders = new HttpHeaders();
Iterator<String> names = httpFields.getFieldNamesCollection().iterator();
while (names.hasNext()) {
String name = names.next();
for (String name : httpFields.getFieldNamesCollection()) {
Enumeration<String> values = httpFields.getValues(name);
while (values.hasMoreElements()) {
String value = values.nextElement();