diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java index d66adc843cc5f66a4e8891da6c9ca0e83d0f17b3..d21944041d06a2f69b0bb9fffbba9e482a37da24 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -20,8 +20,10 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.aopalliance.aop.Advice; @@ -136,11 +138,11 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig private final Map advisedBeans = new ConcurrentHashMap(64); - // using a ConcurrentHashMap as a Set - private final Map targetSourcedBeans = new ConcurrentHashMap(16); + private final Set targetSourcedBeans = + Collections.newSetFromMap(new ConcurrentHashMap(16)); - // using a ConcurrentHashMap as a Set - private final Map earlyProxyReferences = new ConcurrentHashMap(16); + private final Set earlyProxyReferences = + Collections.newSetFromMap(new ConcurrentHashMap(16)); private final Map> proxyTypes = new ConcurrentHashMap>(16); @@ -262,14 +264,14 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException { Object cacheKey = getCacheKey(bean.getClass(), beanName); - this.earlyProxyReferences.put(cacheKey, Boolean.TRUE); + this.earlyProxyReferences.add(cacheKey); return wrapIfNecessary(bean, beanName, cacheKey); } public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { Object cacheKey = getCacheKey(beanClass, beanName); - if (beanName == null || !this.targetSourcedBeans.containsKey(beanName)) { + if (beanName == null || !this.targetSourcedBeans.contains(beanName)) { if (this.advisedBeans.containsKey(cacheKey)) { return null; } @@ -285,7 +287,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig if (beanName != null) { TargetSource targetSource = getCustomTargetSource(beanClass, beanName); if (targetSource != null) { - this.targetSourcedBeans.put(beanName, Boolean.TRUE); + this.targetSourcedBeans.add(beanName); Object[] specificInterceptors = getAdvicesAndAdvisorsForBean(beanClass, beanName, targetSource); Object proxy = createProxy(beanClass, beanName, specificInterceptors, targetSource); this.proxyTypes.put(cacheKey, proxy.getClass()); @@ -318,7 +320,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean != null) { Object cacheKey = getCacheKey(bean.getClass(), beanName); - if (!this.earlyProxyReferences.containsKey(cacheKey)) { + if (!this.earlyProxyReferences.contains(cacheKey)) { return wrapIfNecessary(bean, beanName, cacheKey); } } @@ -344,7 +346,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig * @return a proxy wrapping the bean, or the raw bean instance as-is */ protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) { - if (beanName != null && this.targetSourcedBeans.containsKey(beanName)) { + if (beanName != null && this.targetSourcedBeans.contains(beanName)) { return bean; } if (Boolean.FALSE.equals(this.advisedBeans.get(cacheKey))) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java index 4e945234860bac7aa6e8f6dea79bac2eb925667b..6876beda486114a16e911c49c67967917b82905c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -20,8 +20,9 @@ import java.beans.PropertyDescriptor; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.springframework.beans.BeansException; @@ -90,9 +91,9 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP /** * Cache for validated bean names, skipping re-validation for the same bean - * (using a ConcurrentHashMap as a Set) */ - private final Map validatedBeanNames = new ConcurrentHashMap(64); + private final Set validatedBeanNames = + Collections.newSetFromMap(new ConcurrentHashMap(64)); /** @@ -139,7 +140,7 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { - if (!this.validatedBeanNames.containsKey(beanName)) { + if (!this.validatedBeanNames.contains(beanName)) { if (!shouldSkip(this.beanFactory, beanName)) { List invalidProperties = new ArrayList(); for (PropertyDescriptor pd : pds) { @@ -151,7 +152,7 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName)); } } - this.validatedBeanNames.put(beanName, Boolean.TRUE); + this.validatedBeanNames.add(beanName); } return pvs; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java index 9dbcb9becbbe2cf77291c4780d24c071a77a2a85..9a57d1d805b5410ed241f03b322bd95b6a515572 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -16,9 +16,10 @@ package org.springframework.beans.factory.config; +import java.util.Collections; import java.util.Enumeration; -import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.springframework.beans.BeansException; @@ -72,9 +73,8 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer { /** * Contains names of beans that have overrides - * (using a ConcurrentHashMap as a Set) */ - private Map beanNames = new ConcurrentHashMap(16); + private final Set beanNames = Collections.newSetFromMap(new ConcurrentHashMap(16)); /** @@ -130,7 +130,7 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer { } String beanName = key.substring(0, separatorIndex); String beanProperty = key.substring(separatorIndex+1); - this.beanNames.put(beanName, Boolean.TRUE); + this.beanNames.add(beanName); applyPropertyValue(factory, beanName, beanProperty, value); if (logger.isDebugEnabled()) { logger.debug("Property '" + key + "' set to value [" + value + "]"); @@ -161,7 +161,7 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer { * the named bean */ public boolean hasPropertyOverridesFor(String beanName) { - return this.beanNames.containsKey(beanName); + return this.beanNames.contains(beanName); } } 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 9e97ba2fafa827e01760424b5b7da1048d47c186..6e23d449a9a0c4a36a0b93bcd5d9f53e12ac22bd 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 @@ -24,6 +24,7 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -161,9 +162,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp /** * Names of beans that have already been created at least once - * (using a ConcurrentHashMap as a Set) */ - private final Map alreadyCreated = new ConcurrentHashMap(64); + private final Set alreadyCreated = Collections.newSetFromMap(new ConcurrentHashMap(64)); /** Names of beans that are currently in creation */ private final ThreadLocal prototypesCurrentlyInCreation = @@ -1379,7 +1379,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @param beanName the name of the bean */ protected void markBeanAsCreated(String beanName) { - this.alreadyCreated.put(beanName, Boolean.TRUE); + this.alreadyCreated.add(beanName); } /** @@ -1390,7 +1390,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * at this point already */ protected boolean isBeanEligibleForMetadataCaching(String beanName) { - return this.alreadyCreated.containsKey(beanName); + return this.alreadyCreated.contains(beanName); } /** @@ -1400,7 +1400,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @return {@code true} if actually removed, {@code false} otherwise */ protected boolean removeSingletonIfCreatedForTypeCheckOnly(String beanName) { - if (!this.alreadyCreated.containsKey(beanName)) { + if (!this.alreadyCreated.contains(beanName)) { removeSingleton(beanName); return true; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java index cbf7c872ffd8860c193ff183cb54bf90fd403661..71d2ac891fff0296ab847b6985e33bf1fa2154e8 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -16,6 +16,7 @@ package org.springframework.beans.factory.support; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -92,11 +93,13 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements /** Set of registered singletons, containing the bean names in registration order */ private final Set registeredSingletons = new LinkedHashSet(64); - /** Names of beans that are currently in creation (using a ConcurrentHashMap as a Set) */ - private final Map singletonsCurrentlyInCreation = new ConcurrentHashMap(16); + /** Names of beans that are currently in creation */ + private final Set singletonsCurrentlyInCreation = + Collections.newSetFromMap(new ConcurrentHashMap(16)); - /** Names of beans currently excluded from in creation checks (using a ConcurrentHashMap as a Set) */ - private final Map inCreationCheckExclusions = new ConcurrentHashMap(16); + /** Names of beans currently excluded from in creation checks */ + private final Set inCreationCheckExclusions = + Collections.newSetFromMap(new ConcurrentHashMap(16)); /** List of suppressed Exceptions, available for associating related causes */ private Set suppressedExceptions; @@ -290,7 +293,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements public void setCurrentlyInCreation(String beanName, boolean inCreation) { Assert.notNull(beanName, "Bean name must not be null"); if (!inCreation) { - this.inCreationCheckExclusions.put(beanName, Boolean.TRUE); + this.inCreationCheckExclusions.add(beanName); } else { this.inCreationCheckExclusions.remove(beanName); @@ -299,7 +302,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements public boolean isCurrentlyInCreation(String beanName) { Assert.notNull(beanName, "Bean name must not be null"); - return (!this.inCreationCheckExclusions.containsKey(beanName) && isActuallyInCreation(beanName)); + return (!this.inCreationCheckExclusions.contains(beanName) && isActuallyInCreation(beanName)); } protected boolean isActuallyInCreation(String beanName) { @@ -312,18 +315,18 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements * @param beanName the name of the bean */ public boolean isSingletonCurrentlyInCreation(String beanName) { - return this.singletonsCurrentlyInCreation.containsKey(beanName); + return this.singletonsCurrentlyInCreation.contains(beanName); } /** * Callback before singleton creation. - *

Default implementation register the singleton as currently in creation. + *

The default implementation register the singleton as currently in creation. * @param beanName the name of the singleton about to be created * @see #isSingletonCurrentlyInCreation */ protected void beforeSingletonCreation(String beanName) { - if (!this.inCreationCheckExclusions.containsKey(beanName) && - this.singletonsCurrentlyInCreation.put(beanName, Boolean.TRUE) != null) { + if (!this.inCreationCheckExclusions.contains(beanName) && + !this.singletonsCurrentlyInCreation.add(beanName)) { throw new BeanCurrentlyInCreationException(beanName); } } @@ -335,7 +338,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements * @see #isSingletonCurrentlyInCreation */ protected void afterSingletonCreation(String beanName) { - if (!this.inCreationCheckExclusions.containsKey(beanName) && + if (!this.inCreationCheckExclusions.contains(beanName) && !this.singletonsCurrentlyInCreation.remove(beanName)) { throw new IllegalStateException("Singleton '" + beanName + "' isn't currently in creation"); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java index 64d0555d4913419dcbd635df630e8020b058bae9..1fabd479489364452e9b32642921e4dae112336d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java @@ -18,7 +18,8 @@ package org.springframework.beans.factory.support; import java.lang.reflect.Member; import java.lang.reflect.Method; -import java.util.Map; +import java.util.Collections; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.springframework.beans.MutablePropertyValues; @@ -48,14 +49,14 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public class RootBeanDefinition extends AbstractBeanDefinition { - // using a ConcurrentHashMap as a Set - private final Map externallyManagedConfigMembers = new ConcurrentHashMap(0); + private final Set externallyManagedConfigMembers = + Collections.newSetFromMap(new ConcurrentHashMap(0)); - // using a ConcurrentHashMap as a Set - private final Map externallyManagedInitMethods = new ConcurrentHashMap(0); + private final Set externallyManagedInitMethods = + Collections.newSetFromMap(new ConcurrentHashMap(0)); - // using a ConcurrentHashMap as a Set - private final Map externallyManagedDestroyMethods = new ConcurrentHashMap(0); + private final Set externallyManagedDestroyMethods = + Collections.newSetFromMap(new ConcurrentHashMap(0)); private BeanDefinitionHolder decoratedDefinition; @@ -299,27 +300,27 @@ public class RootBeanDefinition extends AbstractBeanDefinition { public void registerExternallyManagedConfigMember(Member configMember) { - this.externallyManagedConfigMembers.put(configMember, Boolean.TRUE); + this.externallyManagedConfigMembers.add(configMember); } public boolean isExternallyManagedConfigMember(Member configMember) { - return this.externallyManagedConfigMembers.containsKey(configMember); + return this.externallyManagedConfigMembers.contains(configMember); } public void registerExternallyManagedInitMethod(String initMethod) { - this.externallyManagedInitMethods.put(initMethod, Boolean.TRUE); + this.externallyManagedInitMethods.add(initMethod); } public boolean isExternallyManagedInitMethod(String initMethod) { - return this.externallyManagedInitMethods.containsKey(initMethod); + return this.externallyManagedInitMethods.contains(initMethod); } public void registerExternallyManagedDestroyMethod(String destroyMethod) { - this.externallyManagedDestroyMethods.put(destroyMethod, Boolean.TRUE); + this.externallyManagedDestroyMethods.add(destroyMethod); } public boolean isExternallyManagedDestroyMethod(String destroyMethod) { - return this.externallyManagedDestroyMethods.containsKey(destroyMethod); + return this.externallyManagedDestroyMethods.contains(destroyMethod); } public void setDecoratedDefinition(BeanDefinitionHolder decoratedDefinition) { diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java index 699f2aa8a2797b30b672c0903aff8ca6f9f7ec66..89e7ad9c2b281aca6aa7fdf66346c5452bd45f92 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,9 +19,9 @@ package org.springframework.web.bind.annotation.support; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -65,8 +65,8 @@ public class HandlerMethodResolver { private final Set sessionAttributeTypes = new HashSet(); - // using a ConcurrentHashMap as a Set - private final Map actualSessionAttributeNames = new ConcurrentHashMap(4); + private final Set actualSessionAttributeNames = + Collections.newSetFromMap(new ConcurrentHashMap(4)); /** @@ -154,7 +154,7 @@ public class HandlerMethodResolver { public boolean isSessionAttribute(String attrName, Class attrType) { if (this.sessionAttributeNames.contains(attrName) || this.sessionAttributeTypes.contains(attrType)) { - this.actualSessionAttributeNames.put(attrName, Boolean.TRUE); + this.actualSessionAttributeNames.add(attrName); return true; } else { @@ -163,7 +163,7 @@ public class HandlerMethodResolver { } public Set getActualSessionAttributeNames() { - return this.actualSessionAttributeNames.keySet(); + return this.actualSessionAttributeNames; } } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java index bd14d2dc2170a4fd37e589734c975c9eab5d09b7..2430c66d32f3525a16d2a3981fe902e1dbf6bc3c 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,6 +17,7 @@ package org.springframework.web.method.annotation; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -50,8 +51,8 @@ public class SessionAttributesHandler { private final Set> attributeTypes = new HashSet>(); - // using a ConcurrentHashMap as a Set - private final Map knownAttributeNames = new ConcurrentHashMap(4); + private final Set knownAttributeNames = + Collections.newSetFromMap(new ConcurrentHashMap(4)); private final SessionAttributeStore sessionAttributeStore; @@ -74,7 +75,7 @@ public class SessionAttributesHandler { } for (String attributeName : this.attributeNames) { - this.knownAttributeNames.put(attributeName, Boolean.TRUE); + this.knownAttributeNames.add(attributeName); } } @@ -100,7 +101,7 @@ public class SessionAttributesHandler { public boolean isHandlerSessionAttribute(String attributeName, Class attributeType) { Assert.notNull(attributeName, "Attribute name must not be null"); if (this.attributeNames.contains(attributeName) || this.attributeTypes.contains(attributeType)) { - this.knownAttributeNames.put(attributeName, Boolean.TRUE); + this.knownAttributeNames.add(attributeName); return true; } else { @@ -134,7 +135,7 @@ public class SessionAttributesHandler { */ public Map retrieveAttributes(WebRequest request) { Map attributes = new HashMap(); - for (String name : this.knownAttributeNames.keySet()) { + for (String name : this.knownAttributeNames) { Object value = this.sessionAttributeStore.retrieveAttribute(request, name); if (value != null) { attributes.put(name, value); @@ -150,7 +151,7 @@ public class SessionAttributesHandler { * @param request the current request */ public void cleanupAttributes(WebRequest request) { - for (String attributeName : this.knownAttributeNames.keySet()) { + for (String attributeName : this.knownAttributeNames) { this.sessionAttributeStore.cleanupAttribute(request, attributeName); } }