Browse Source

Use enhanced for loop where feasible

See gh-31916
pull/31920/head
Yanming Zhou 2 years ago committed by Stéphane Nicoll
parent
commit
4a450c6fab
  1. 5
      spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java
  2. 5
      spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/GenericBean.java
  3. 4
      spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java
  4. 4
      spring-context/src/test/java/org/springframework/aop/target/CommonsPool2TargetSourceTests.java
  5. 4
      spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java
  6. 5
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/JettyXhrTransport.java

5
spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java

@ -201,9 +201,8 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { @@ -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

5
spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/GenericBean.java

@ -23,7 +23,6 @@ import java.util.EnumMap; @@ -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> { @@ -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));
}
}

4
spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java

@ -24,7 +24,6 @@ import java.rmi.MarshalException; @@ -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 { @@ -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);

4
spring-context/src/test/java/org/springframework/aop/target/CommonsPool2TargetSourceTests.java

@ -186,8 +186,8 @@ class CommonsPool2TargetSourceTests { @@ -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);
}
}

4
spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java

@ -607,8 +607,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -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();

5
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/JettyXhrTransport.java

@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream; @@ -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 @@ -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();

Loading…
Cancel
Save