Use Collection.removeIf() where possible (#1747)
Use Collection.removeIf() where possible Issue: SPR-16622
This commit is contained in:
committed by
Juergen Hoeller
parent
e0de9126ed
commit
d3a0a8e007
@@ -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<BeanPostProcessor> it = internalBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
|
||||
if (it.next() instanceof AopInfrastructureBean) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
internalBeanFactory.getBeanPostProcessors().removeIf(beanPostProcessor ->
|
||||
beanPostProcessor instanceof AopInfrastructureBean);
|
||||
|
||||
return internalBeanFactory;
|
||||
}
|
||||
|
||||
@@ -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<ClassLoader> it = acceptedClassLoaders.iterator(); it.hasNext();) {
|
||||
ClassLoader registeredLoader = it.next();
|
||||
if (isUnderneathClassLoader(registeredLoader, classLoader)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
for (Iterator<Class<?>> it = strongClassCache.keySet().iterator(); it.hasNext();) {
|
||||
Class<?> beanClass = it.next();
|
||||
if (isUnderneathClassLoader(beanClass.getClassLoader(), classLoader)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
for (Iterator<Class<?>> 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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<String> mergedBeans = this.mergedBeanDefinitions.keySet().iterator();
|
||||
while (mergedBeans.hasNext()) {
|
||||
if (!isBeanEligibleForMetadataCaching(mergedBeans.next())) {
|
||||
mergedBeans.remove();
|
||||
}
|
||||
}
|
||||
this.mergedBeanDefinitions.keySet().removeIf(bean -> !isBeanEligibleForMetadataCaching(bean));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<BeanPostProcessor> it = this.scriptBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
|
||||
if (it.next() instanceof AopInfrastructureBean) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
this.scriptBeanFactory.getBeanPostProcessors().removeIf(beanPostProcessor ->
|
||||
beanPostProcessor instanceof AopInfrastructureBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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<Map.Entry<String, UserRegistrySnapshot>> iterator = this.remoteRegistries.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, UserRegistrySnapshot> entry = iterator.next();
|
||||
if (entry.getValue().isExpired(now)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
this.remoteRegistries.entrySet().removeIf(entry -> entry.getValue().isExpired(now));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<Con
|
||||
return this;
|
||||
}
|
||||
Set<ConsumeMediaTypeExpression> result = new LinkedHashSet<>(expressions);
|
||||
for (Iterator<ConsumeMediaTypeExpression> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Pro
|
||||
return this;
|
||||
}
|
||||
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>(expressions);
|
||||
for (Iterator<ProduceMediaTypeExpression> 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user