Use Collection.removeIf() where possible (#1747)

Use Collection.removeIf() where possible

Issue: SPR-16622
This commit is contained in:
Christoph Dreis
2018-03-22 11:36:11 +01:00
committed by Juergen Hoeller
parent e0de9126ed
commit d3a0a8e007
7 changed files with 19 additions and 67 deletions

View File

@@ -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));
}
/**

View File

@@ -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));
}
/**