diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java index e339e716b4..03ec6dd127 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.aop.framework.autoproxy.target; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.apache.commons.logging.Log; @@ -31,7 +30,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.GenericBeanDefinition; @@ -150,11 +148,8 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator // Filter out BeanPostProcessors that are part of the AOP infrastructure, // since those are only meant to apply to beans defined in the original factory. - for (Iterator it = internalBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) { - if (it.next() instanceof AopInfrastructureBean) { - it.remove(); - } - } + internalBeanFactory.getBeanPostProcessors().removeIf(beanPostProcessor -> + beanPostProcessor instanceof AopInfrastructureBean); return internalBeanFactory; } diff --git a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java index ef74f0dd37..8656d9e702 100644 --- a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java +++ b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java @@ -21,7 +21,6 @@ import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -150,24 +149,12 @@ public class CachedIntrospectionResults { * @param classLoader the ClassLoader to clear the cache for */ public static void clearClassLoader(@Nullable ClassLoader classLoader) { - for (Iterator it = acceptedClassLoaders.iterator(); it.hasNext();) { - ClassLoader registeredLoader = it.next(); - if (isUnderneathClassLoader(registeredLoader, classLoader)) { - it.remove(); - } - } - for (Iterator> it = strongClassCache.keySet().iterator(); it.hasNext();) { - Class beanClass = it.next(); - if (isUnderneathClassLoader(beanClass.getClassLoader(), classLoader)) { - it.remove(); - } - } - for (Iterator> it = softClassCache.keySet().iterator(); it.hasNext();) { - Class beanClass = it.next(); - if (isUnderneathClassLoader(beanClass.getClassLoader(), classLoader)) { - it.remove(); - } - } + acceptedClassLoaders.removeIf(registeredLoader -> + isUnderneathClassLoader(registeredLoader, classLoader)); + strongClassCache.keySet().removeIf(beanClass -> + isUnderneathClassLoader(beanClass.getClassLoader(), classLoader)); + softClassCache.keySet().removeIf(beanClass -> + isUnderneathClassLoader(beanClass.getClassLoader(), classLoader)); } /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 07c87795e5..6f5a392c6a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -27,7 +27,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -1338,12 +1337,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @since 4.2 */ public void clearMetadataCache() { - Iterator mergedBeans = this.mergedBeanDefinitions.keySet().iterator(); - while (mergedBeans.hasNext()) { - if (!isBeanEligibleForMetadataCaching(mergedBeans.next())) { - mergedBeans.remove(); - } - } + this.mergedBeanDefinitions.keySet().removeIf(bean -> !isBeanEligibleForMetadataCaching(bean)); } /** diff --git a/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java b/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java index 0e379c8ebf..b21093fb4b 100644 --- a/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.scripting.support; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.apache.commons.logging.Log; @@ -39,7 +38,6 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -225,11 +223,8 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces // Filter out BeanPostProcessors that are part of the AOP infrastructure, // since those are only meant to apply to beans defined in the original factory. - for (Iterator it = this.scriptBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) { - if (it.next() instanceof AopInfrastructureBean) { - it.remove(); - } - } + this.scriptBeanFactory.getBeanPostProcessors().removeIf(beanPostProcessor -> + beanPostProcessor instanceof AopInfrastructureBean); } @Override diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java index e7744e3e77..7d943d44c6 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.net.UnknownHostException; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -175,13 +174,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati void purgeExpiredRegistries() { long now = System.currentTimeMillis(); - Iterator> iterator = this.remoteRegistries.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry entry = iterator.next(); - if (entry.getValue().isExpired(now)) { - iterator.remove(); - } - } + this.remoteRegistries.entrySet().removeIf(entry -> entry.getValue().isExpired(now)); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java index f187441794..fc190243da 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.web.reactive.result.condition; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -168,12 +167,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition result = new LinkedHashSet<>(expressions); - for (Iterator iterator = result.iterator(); iterator.hasNext();) { - ConsumeMediaTypeExpression expression = iterator.next(); - if (!expression.match(exchange)) { - iterator.remove(); - } - } + result.removeIf(expression -> !expression.match(exchange)); return (result.isEmpty()) ? null : new ConsumesRequestCondition(result); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java index 4e28666f63..b9a799a189 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.web.reactive.result.condition; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -192,12 +191,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition result = new LinkedHashSet<>(expressions); - for (Iterator iterator = result.iterator(); iterator.hasNext();) { - ProduceMediaTypeExpression expression = iterator.next(); - if (!expression.match(exchange)) { - iterator.remove(); - } - } + result.removeIf(expression -> !expression.match(exchange)); return (result.isEmpty()) ? null : new ProducesRequestCondition(result, this.contentTypeResolver); }