From 2e5d752e15164b331ad48bcdcb61c174f880498c Mon Sep 17 00:00:00 2001 From: Min Ho Pak Date: Tue, 21 Oct 2014 12:25:38 +0900 Subject: [PATCH] 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 --- .../beans/factory/annotation/BeanFactoryAnnotationUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java index 9637abc94b..f5f10c7792 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java @@ -79,13 +79,14 @@ public class BeanFactoryAnnotationUtils { private static T qualifiedBeanOfType(ConfigurableListableBeanFactory bf, Class beanType, String qualifier) { Map candidateBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, beanType); T matchingBean = null; - for (String beanName : candidateBeans.keySet()) { + for (Map.Entry 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) {