Better use of key iterator

This commit uses an EntrySet instead of looping over the keys and
retrieving the value in a separate call.

Issue: SPR-12356
This commit is contained in:
Min Ho Pak 2014-10-21 12:25:38 +09:00 committed by Stephane Nicoll
parent 66069333f1
commit 2e5d752e15
1 changed files with 3 additions and 2 deletions

View File

@ -79,13 +79,14 @@ public class BeanFactoryAnnotationUtils {
private static <T> T qualifiedBeanOfType(ConfigurableListableBeanFactory bf, Class<T> beanType, String qualifier) {
Map<String, T> candidateBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, beanType);
T matchingBean = null;
for (String beanName : candidateBeans.keySet()) {
for (Map.Entry<String, T> entry : candidateBeans.entrySet()) {
String beanName = entry.getKey();
if (isQualifierMatch(qualifier, beanName, bf)) {
if (matchingBean != null) {
throw new NoSuchBeanDefinitionException(qualifier, "No unique " + beanType.getSimpleName() +
" bean found for qualifier '" + qualifier + "'");
}
matchingBean = candidateBeans.get(beanName);
matchingBean = entry.getValue();
}
}
if (matchingBean != null) {