diff --git a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java index 6d084e2384b..8e6b5839c7e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java @@ -87,9 +87,8 @@ public class MutablePropertyValues implements PropertyValues, Serializable { // There is no replacement of existing property values. if (original != null) { this.propertyValueList = new ArrayList<>(original.size()); - for (Map.Entry entry : original.entrySet()) { - this.propertyValueList.add(new PropertyValue(entry.getKey().toString(), entry.getValue())); - } + original.forEach((attrName, attrValue) -> this.propertyValueList.add( + new PropertyValue(attrName.toString(), attrValue))); } else { this.propertyValueList = new ArrayList<>(0); @@ -151,9 +150,8 @@ public class MutablePropertyValues implements PropertyValues, Serializable { */ public MutablePropertyValues addPropertyValues(@Nullable Map other) { if (other != null) { - for (Map.Entry entry : other.entrySet()) { - addPropertyValue(new PropertyValue(entry.getKey().toString(), entry.getValue())); - } + other.forEach((attrName, attrValue) -> addPropertyValue( + new PropertyValue(attrName.toString(), attrValue))); } return this; } diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java index 7a16a30b582..1fe6fbe932e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java @@ -457,9 +457,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { String actualPropertyName = (nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null); if (this.customEditors != null) { - for (Map.Entry, PropertyEditor> entry : this.customEditors.entrySet()) { - target.registerCustomEditor(entry.getKey(), entry.getValue()); - } + this.customEditors.forEach(target::registerCustomEditor); } if (this.customEditorsForPath != null) { for (Map.Entry entry : this.customEditorsForPath.entrySet()) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java index e9aced9f9ed..33d354b6e21 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java @@ -72,14 +72,12 @@ public class ConstructorArgumentValues { */ public void addArgumentValues(@Nullable ConstructorArgumentValues other) { if (other != null) { - for (Map.Entry entry : other.indexedArgumentValues.entrySet()) { - addOrMergeIndexedArgumentValue(entry.getKey(), entry.getValue().copy()); - } - for (ValueHolder valueHolder : other.genericArgumentValues) { - if (!this.genericArgumentValues.contains(valueHolder)) { - addOrMergeGenericArgumentValue(valueHolder.copy()); - } - } + other.indexedArgumentValues.forEach( + (index, argValue) -> addOrMergeIndexedArgumentValue(index, argValue.copy()) + ); + other.genericArgumentValues.stream() + .filter(valueHolder -> !this.genericArgumentValues.contains(valueHolder)) + .forEach(valueHolder -> addOrMergeGenericArgumentValue(valueHolder.copy())); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java index a0dafe9631b..56d5b6feb2e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2017 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. @@ -145,11 +145,7 @@ public class CustomEditorConfigurer implements BeanFactoryPostProcessor, Ordered } } if (this.customEditors != null) { - for (Map.Entry, Class> entry : this.customEditors.entrySet()) { - Class requiredType = entry.getKey(); - Class propertyEditorClass = entry.getValue(); - beanFactory.registerCustomEditor(requiredType, propertyEditorClass); - } + this.customEditors.forEach(beanFactory::registerCustomEditor); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java index c0e054bcb2e..3b36eef8ca2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -18,7 +18,6 @@ package org.springframework.beans.factory.config; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Map.Entry; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; @@ -123,9 +122,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean output, Map map) { - for (Entry entry : map.entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); + map.forEach((key, value) -> { Object existing = output.get(key); if (value instanceof Map && existing instanceof Map) { // Inner cast required by Eclipse IDE. @@ -136,7 +133,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean map = (Map) object; - for (Entry entry : map.entrySet()) { - Object value = entry.getValue(); + map.forEach((key, value) -> { if (value instanceof Map) { value = asMap(value); } - Object key = entry.getKey(); if (key instanceof CharSequence) { result.put(key.toString(), value); } @@ -215,7 +213,7 @@ public abstract class YamlProcessor { // It has to be a map key in this case result.put("[" + key.toString() + "]", value); } - } + }); return result; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java index 26f0c410625..1ed60c804d2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java @@ -169,9 +169,7 @@ class BeanDefinitionValueResolver { else if (value instanceof ManagedProperties) { Properties original = (Properties) value; Properties copy = new Properties(); - for (Map.Entry propEntry : original.entrySet()) { - Object propKey = propEntry.getKey(); - Object propValue = propEntry.getValue(); + original.forEach((propKey, propValue) -> { if (propKey instanceof TypedStringValue) { propKey = evaluate((TypedStringValue) propKey); } @@ -184,7 +182,7 @@ class BeanDefinitionValueResolver { "Error converting Properties key/value pair for " + argName + ": resolved to null"); } copy.put(propKey, propValue); - } + }); return copy; } else if (value instanceof TypedStringValue) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 638bee35e7f..e06e99470d9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -1225,9 +1225,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto private FactoryAwareOrderSourceProvider createFactoryAwareOrderSourceProvider(Map beans) { IdentityHashMap instancesToBeanNames = new IdentityHashMap<>(); - for (Map.Entry entry : beans.entrySet()) { - instancesToBeanNames.put(entry.getValue(), entry.getKey()); - } + beans.forEach((beanName, instance) -> instancesToBeanNames.put(instance, beanName)); return new FactoryAwareOrderSourceProvider(instancesToBeanNames); } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java index 0dd7ee28595..cc83daa3d4c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java @@ -111,9 +111,7 @@ public class CustomMapEditor extends PropertyEditorSupport { // Convert Map elements. Map source = (Map) value; Map target = createMap(this.mapType, source.size()); - for (Map.Entry entry : source.entrySet()) { - target.put(convertKey(entry.getKey()), convertValue(entry.getValue())); - } + source.forEach((key, val) -> target.put(convertKey(key), convertValue(val))); super.setValue(target); } else { diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java index c525caf4369..71b2b173617 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -57,9 +57,7 @@ public class NameMatchCacheOperationSource implements CacheOperationSource, Seri * @see CacheOperation */ public void setNameMap(Map> nameMap) { - for (Map.Entry> entry : nameMap.entrySet()) { - addCacheMethod(entry.getKey(), entry.getValue()); - } + nameMap.forEach(this::addCacheMethod); } /** diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java index c205c72e67a..9e9680c9afa 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java @@ -351,9 +351,8 @@ class ConfigurationClassBeanDefinitionReader { } private void loadBeanDefinitionsFromRegistrars(Map registrars) { - for (Map.Entry entry : registrars.entrySet()) { - entry.getKey().registerBeanDefinitions(entry.getValue(), this.registry); - } + registrars.forEach((registrar, metadata) -> + registrar.registerBeanDefinitions(metadata, this.registry)); } diff --git a/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java index 58727cd22a0..bffbebd7767 100644 --- a/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java +++ b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java @@ -75,13 +75,12 @@ public class CandidateComponentsIndex { private static MultiValueMap parseIndex(List content) { MultiValueMap index = new LinkedMultiValueMap<>(); for (Properties entry : content) { - for (Map.Entry entries : entry.entrySet()) { - String type = (String) entries.getKey(); - String[] stereotypes = ((String) entries.getValue()).split(","); + entry.forEach((type, values) -> { + String[] stereotypes = ((String) values).split(","); for (String stereotype : stereotypes) { - index.add(stereotype, type); + index.add(stereotype, (String) type); } - } + }); } return index; } diff --git a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java index 7c9c0fd2b81..ff43af3a3a2 100644 --- a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java @@ -132,8 +132,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor private void startBeans(boolean autoStartupOnly) { Map lifecycleBeans = getLifecycleBeans(); Map phases = new HashMap<>(); - for (Map.Entry entry : lifecycleBeans.entrySet()) { - Lifecycle bean = entry.getValue(); + lifecycleBeans.forEach((beanName, bean) -> { if (!autoStartupOnly || (bean instanceof SmartLifecycle && ((SmartLifecycle) bean).isAutoStartup())) { int phase = getPhase(bean); LifecycleGroup group = phases.get(phase); @@ -141,9 +140,9 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor group = new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, autoStartupOnly); phases.put(phase, group); } - group.add(entry.getKey(), bean); + group.add(beanName, bean); } - } + }); if (!phases.isEmpty()) { List keys = new ArrayList<>(phases.keySet()); Collections.sort(keys); @@ -187,16 +186,15 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor private void stopBeans() { Map lifecycleBeans = getLifecycleBeans(); Map phases = new HashMap<>(); - for (Map.Entry entry : lifecycleBeans.entrySet()) { - Lifecycle bean = entry.getValue(); + lifecycleBeans.forEach((beanName, bean) -> { int shutdownOrder = getPhase(bean); LifecycleGroup group = phases.get(shutdownOrder); if (group == null) { group = new LifecycleGroup(shutdownOrder, this.timeoutPerShutdownPhase, lifecycleBeans, false); phases.put(shutdownOrder, group); } - group.add(entry.getKey(), bean); - } + group.add(beanName, bean); + }); if (!phases.isEmpty()) { List keys = new ArrayList<>(phases.keySet()); Collections.sort(keys, Collections.reverseOrder()); diff --git a/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java index 86205af7dee..9efe2b141f6 100644 --- a/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -87,9 +87,7 @@ public class StaticMessageSource extends AbstractMessageSource { */ public void addMessages(Map messages, Locale locale) { Assert.notNull(messages, "Messages Map must not be null"); - for (Map.Entry entry : messages.entrySet()) { - addMessage(entry.getKey(), locale, entry.getValue()); - } + messages.forEach((code, msg) -> addMessage(code, locale, msg)); } diff --git a/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java b/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java index d914082c16a..467a828e74b 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java @@ -367,17 +367,16 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo List notificationListeners = new ArrayList<>(listeners.size()); - for (Map.Entry entry : listeners.entrySet()) { + listeners.forEach((key, listener) -> { // Get the listener from the map value. - NotificationListenerBean bean = new NotificationListenerBean(entry.getValue()); + NotificationListenerBean bean = new NotificationListenerBean(listener); // Get the ObjectName from the map key. - Object key = entry.getKey(); if (key != null && !WILDCARD.equals(key)) { // This listener is mapped to a specific ObjectName. - bean.setMappedObjectName(entry.getKey()); + bean.setMappedObjectName(key); } notificationListeners.add(bean); - } + }); this.notificationListeners = notificationListeners.toArray(new NotificationListenerBean[notificationListeners.size()]); @@ -545,9 +544,8 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo } if (!this.beans.isEmpty()) { - for (Map.Entry entry : this.beans.entrySet()) { - registerBeanNameOrInstance(entry.getValue(), entry.getKey()); - } + this.beans.forEach((beanName, instance) -> + registerBeanNameOrInstance(instance, beanName)); } } @@ -1008,9 +1006,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo * from the {@link MBeanServer}. */ private void unregisterNotificationListeners() { - for (Map.Entry entry : this.registeredNotificationListeners.entrySet()) { - NotificationListenerBean bean = entry.getKey(); - ObjectName[] mappedObjectNames = entry.getValue(); + this.registeredNotificationListeners.forEach((bean, mappedObjectNames) -> { for (ObjectName mappedObjectName : mappedObjectNames) { try { this.server.removeNotificationListener(mappedObjectName, bean.getNotificationListener(), @@ -1022,7 +1018,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo } } } - } + }); this.registeredNotificationListeners.clear(); } diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java index b341147b0d5..9269126e40e 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -53,9 +53,8 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef } public void setNotificationInfoMappings(Map notificationInfoMappings) { - for (Map.Entry entry : notificationInfoMappings.entrySet()) { - this.notificationInfoMappings.put(entry.getKey(), extractNotificationMetadata(entry.getValue())); - } + notificationInfoMappings.forEach((beanKey, result) -> + this.notificationInfoMappings.put(beanKey, extractNotificationMetadata(result))); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java index d3121e850b5..8fcfb298f6d 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java @@ -315,12 +315,8 @@ public class ScheduledAnnotationBeanPostProcessor } else { // Non-empty set of methods - for (Map.Entry> entry : annotatedMethods.entrySet()) { - Method method = entry.getKey(); - for (Scheduled scheduled : entry.getValue()) { - processScheduled(scheduled, method, bean); - } - } + annotatedMethods.forEach((method, scheduledMethods) -> + scheduledMethods.forEach(scheduled -> processScheduled(scheduled, method, bean))); if (logger.isDebugEnabled()) { logger.debug(annotatedMethods.size() + " @Scheduled methods processed on bean '" + beanName + "': " + annotatedMethods); diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java index 22235131a54..8c19d64545a 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-201 the original author or authors. + * Copyright 2002-2017 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. @@ -114,9 +114,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean */ public void setTriggerTasks(Map triggerTasks) { this.triggerTasks = new ArrayList<>(); - for (Map.Entry task : triggerTasks.entrySet()) { - addTriggerTask(new TriggerTask(task.getKey(), task.getValue())); - } + triggerTasks.forEach((task, trigger) -> addTriggerTask(new TriggerTask(task, trigger))); } /** @@ -145,9 +143,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean */ public void setCronTasks(Map cronTasks) { this.cronTasks = new ArrayList<>(); - for (Map.Entry task : cronTasks.entrySet()) { - addCronTask(task.getKey(), task.getValue()); - } + cronTasks.forEach(this::addCronTask); } /** @@ -176,9 +172,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean */ public void setFixedRateTasks(Map fixedRateTasks) { this.fixedRateTasks = new ArrayList<>(); - for (Map.Entry task : fixedRateTasks.entrySet()) { - addFixedRateTask(task.getKey(), task.getValue()); - } + fixedRateTasks.forEach(this::addFixedRateTask); } /** @@ -207,9 +201,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean */ public void setFixedDelayTasks(Map fixedDelayTasks) { this.fixedDelayTasks = new ArrayList<>(); - for (Map.Entry task : fixedDelayTasks.entrySet()) { - addFixedDelayTask(task.getKey(), task.getValue()); - } + fixedDelayTasks.forEach(this::addFixedDelayTask); } /** diff --git a/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java b/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java index 8c93cc361e2..8ab6387b5bd 100644 --- a/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java +++ b/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java @@ -126,12 +126,11 @@ public class ConcurrentModel extends ConcurrentHashMap implement */ public ConcurrentModel mergeAttributes(@Nullable Map attributes) { if (attributes != null) { - for (Map.Entry entry : attributes.entrySet()) { - String key = entry.getKey(); + attributes.forEach((key, value) -> { if (!containsKey(key)) { - put(key, entry.getValue()); + put(key, value); } - } + }); } return this; } diff --git a/spring-context/src/main/java/org/springframework/ui/ModelMap.java b/spring-context/src/main/java/org/springframework/ui/ModelMap.java index 2bfa930b32b..04c7a69bbc5 100644 --- a/spring-context/src/main/java/org/springframework/ui/ModelMap.java +++ b/spring-context/src/main/java/org/springframework/ui/ModelMap.java @@ -126,12 +126,11 @@ public class ModelMap extends LinkedHashMap { */ public ModelMap mergeAttributes(@Nullable Map attributes) { if (attributes != null) { - for (Map.Entry entry : attributes.entrySet()) { - String key = entry.getKey(); + attributes.forEach((key, value) -> { if (!containsKey(key)) { - put(key, entry.getValue()); + put(key, value); } - } + }); } return this; } diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java index 241f22c29ef..7ed2ca0e45f 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java @@ -287,9 +287,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter } } - for (Map.Entry entry : this.validationPropertyMap.entrySet()) { - configuration.addProperty(entry.getKey(), entry.getValue()); - } + this.validationPropertyMap.forEach(configuration::addProperty); // Allow for custom post-processing before we actually build the ValidatorFactory. postProcessConfiguration(configuration); diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java index 7781a3da698..8a28f4c9d21 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java @@ -215,16 +215,14 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. arguments.add(getResolvableField(objectName, field)); // Using a TreeMap for alphabetical ordering of attribute names Map attributesToExpose = new TreeMap<>(); - for (Map.Entry entry : descriptor.getAttributes().entrySet()) { - String attributeName = entry.getKey(); - Object attributeValue = entry.getValue(); + descriptor.getAttributes().forEach((attributeName, attributeValue) -> { if (!internalAnnotationAttributes.contains(attributeName)) { if (attributeValue instanceof String) { attributeValue = new ResolvableAttribute(attributeValue.toString()); } attributesToExpose.put(attributeName, attributeValue); } - } + }); arguments.addAll(attributesToExpose.values()); return arguments.toArray(new Object[arguments.size()]); } diff --git a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java index d6c55115aba..41b35d14e4b 100644 --- a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java +++ b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 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. @@ -46,9 +46,7 @@ public class BindingAwareModelMap extends ExtendedModelMap { @Override public void putAll(Map map) { - for (Map.Entry entry : map.entrySet()) { - removeBindingResultIfNecessary(entry.getKey(), entry.getValue()); - } + map.forEach(this::removeBindingResultIfNecessary); super.putAll(map); } diff --git a/spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java b/spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java index b1ff3b7e009..fce74208111 100644 --- a/spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -118,14 +118,12 @@ public class SimpleAliasRegistry implements AliasRegistry { * @param result the resulting aliases list */ private void retrieveAliases(String name, List result) { - for (Map.Entry entry : this.aliasMap.entrySet()) { - String registeredName = entry.getValue(); + this.aliasMap.forEach((alias, registeredName) -> { if (registeredName.equals(name)) { - String alias = entry.getKey(); result.add(alias); retrieveAliases(alias, result); } - } + }); } /** diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java index c21879ad8dc..bfec3091c50 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java @@ -580,9 +580,7 @@ public class AnnotatedElementUtils { public Object process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) { AnnotationAttributes annotationAttributes = AnnotationUtils.getAnnotationAttributes( annotation, classValuesAsString, nestedAnnotationsAsMap); - for (Map.Entry entry : annotationAttributes.entrySet()) { - attributesMap.add(entry.getKey(), entry.getValue()); - } + annotationAttributes.forEach(attributesMap::add); return CONTINUE; } }); diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/MethodMetadataReadingVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/MethodMetadataReadingVisitor.java index 008e4dd018c..6727f1db933 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/MethodMetadataReadingVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/MethodMetadataReadingVisitor.java @@ -147,9 +147,7 @@ public class MethodMetadataReadingVisitor extends MethodVisitor implements Metho for (AnnotationAttributes annotationAttributes : attributesList) { AnnotationAttributes convertedAttributes = AnnotationReadingVisitorUtils.convertClassValues( "method '" + getMethodName() + "'", this.classLoader, annotationAttributes, classValuesAsString); - for (Map.Entry entry : convertedAttributes.entrySet()) { - allAttributes.add(entry.getKey(), entry.getValue()); - } + convertedAttributes.forEach(allAttributes::add); } } return allAttributes; diff --git a/spring-core/src/main/java/org/springframework/util/MimeType.java b/spring-core/src/main/java/org/springframework/util/MimeType.java index 58f16a0d7a3..982db7cd942 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeType.java +++ b/spring-core/src/main/java/org/springframework/util/MimeType.java @@ -175,12 +175,10 @@ public class MimeType implements Comparable, Serializable { this.subtype = subtype.toLowerCase(Locale.ENGLISH); if (!CollectionUtils.isEmpty(parameters)) { Map map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH); - for (Map.Entry entry : parameters.entrySet()) { - String attribute = entry.getKey(); - String value = entry.getValue(); + parameters.forEach((attribute, value) -> { checkParameters(attribute, value); map.put(attribute, value); - } + }); this.parameters = Collections.unmodifiableMap(map); } else { @@ -456,12 +454,12 @@ public class MimeType implements Comparable, Serializable { } private void appendTo(Map map, StringBuilder builder) { - for (Map.Entry entry : map.entrySet()) { + map.forEach((key, val) -> { builder.append(';'); - builder.append(entry.getKey()); + builder.append(key); builder.append('='); - builder.append(entry.getValue()); - } + builder.append(val); + }); } /** diff --git a/spring-core/src/main/java/org/springframework/util/xml/SimpleNamespaceContext.java b/spring-core/src/main/java/org/springframework/util/xml/SimpleNamespaceContext.java index 766a2fc2d6e..8d94ed7e9ec 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/SimpleNamespaceContext.java +++ b/spring-core/src/main/java/org/springframework/util/xml/SimpleNamespaceContext.java @@ -99,9 +99,7 @@ public class SimpleNamespaceContext implements NamespaceContext { * The supplied map must consist of string key value pairs. */ public void setBindings(Map bindings) { - for (Map.Entry entry : bindings.entrySet()) { - bindNamespaceUri(entry.getKey(), entry.getValue()); - } + bindings.forEach(this::bindNamespaceUri); } /** diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxEventHandler.java b/spring-core/src/main/java/org/springframework/util/xml/StaxEventHandler.java index 8aa5543bed3..12845be3056 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxEventHandler.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxEventHandler.java @@ -99,11 +99,8 @@ class StaxEventHandler extends AbstractStaxHandler { private List getNamespaces(Map namespaceMapping) { List result = new ArrayList<>(); - for (Map.Entry entry : namespaceMapping.entrySet()) { - String prefix = entry.getKey(); - String namespaceUri = entry.getValue(); - result.add(this.eventFactory.createNamespace(prefix, namespaceUri)); - } + namespaceMapping.forEach((prefix, namespaceUri) -> + result.add(this.eventFactory.createNamespace(prefix, namespaceUri))); return result; } diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java index b04d1412e97..f3947f8da1c 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -369,9 +369,7 @@ public class GenericConversionServiceTests { watch.start("convert 4,000,000 manually"); for (int i = 0; i < 4000000; i++) { Map target = new HashMap<>(source.size()); - for (Map.Entry entry : source.entrySet()) { - target.put(entry.getKey(), Integer.valueOf(entry.getValue())); - } + source.forEach((k, v) -> target.put(k, Integer.valueOf(v))); } watch.stop(); // System.out.println(watch.prettyPrint()); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java index f9f849289de..09812dc9bcb 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java @@ -66,17 +66,17 @@ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder { String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE; Map uriVars = (Map) request.getAttribute(attr); if (uriVars != null) { - for (Entry entry : uriVars.entrySet()) { - if (mpvs.contains(entry.getKey())) { + uriVars.forEach((name, value) -> { + if (mpvs.contains(name)) { if (logger.isWarnEnabled()) { - logger.warn("Skipping URI variable '" + entry.getKey() + + logger.warn("Skipping URI variable '" + name + "' since the request contains a bind value with the same name."); } } else { - mpvs.addPropertyValue(entry.getKey(), entry.getValue()); + mpvs.addPropertyValue(name, value); } - } + }); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java index c6ce9f0f4a6..b3c0f1482e1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java @@ -187,11 +187,11 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro } } if (!entityHeaders.isEmpty()) { - for (Map.Entry> entry : entityHeaders.entrySet()) { - if (!outputHeaders.containsKey(entry.getKey())) { - outputHeaders.put(entry.getKey(), entry.getValue()); + entityHeaders.forEach((key, value) -> { + if (!outputHeaders.containsKey(key)) { + outputHeaders.put(key, value); } - } + }); } if (responseEntity instanceof ResponseEntity) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java index e31e9b0d4e7..9a932a71357 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java @@ -889,14 +889,14 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter } List attrMethods = new ArrayList<>(); // Global methods first - for (Entry> entry : this.modelAttributeAdviceCache.entrySet()) { - if (entry.getKey().isApplicableToBeanType(handlerType)) { - Object bean = entry.getKey().resolveBean(); - for (Method method : entry.getValue()) { + this.modelAttributeAdviceCache.forEach((clazz, methodSet) -> { + if (clazz.isApplicableToBeanType(handlerType)) { + Object bean = clazz.resolveBean(); + for (Method method : methodSet) { attrMethods.add(createModelAttributeMethod(binderFactory, bean, method)); } } - } + }); for (Method method : methods) { Object bean = handlerMethod.getBean(); attrMethods.add(createModelAttributeMethod(binderFactory, bean, method)); @@ -921,14 +921,14 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter } List initBinderMethods = new ArrayList<>(); // Global methods first - for (Entry> entry : this.initBinderAdviceCache.entrySet()) { - if (entry.getKey().isApplicableToBeanType(handlerType)) { - Object bean = entry.getKey().resolveBean(); - for (Method method : entry.getValue()) { + this.initBinderAdviceCache.forEach((clazz, methodSet) -> { + if (clazz.isApplicableToBeanType(handlerType)) { + Object bean = clazz.resolveBean(); + for (Method method : methodSet) { initBinderMethods.add(createInitBinderMethod(bean, method)); } } - } + }); for (Method method : methods) { Object bean = handlerMethod.getBean(); initBinderMethods.add(createInitBinderMethod(bean, method)); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java index de293bd0463..7dcaff51fd6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java @@ -196,9 +196,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement */ public void setAttributesMap(@Nullable Map attributes) { if (attributes != null) { - for (Map.Entry entry : attributes.entrySet()) { - addStaticAttribute(entry.getKey(), entry.getValue()); - } + attributes.forEach(this::addStaticAttribute); } } @@ -429,9 +427,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement * @param request current HTTP request */ protected void exposeModelAsRequestAttributes(Map model, HttpServletRequest request) throws Exception { - for (Map.Entry entry : model.entrySet()) { - String modelName = entry.getKey(); - Object modelValue = entry.getValue(); + model.forEach((modelName, modelValue) -> { if (modelValue != null) { request.setAttribute(modelName, modelValue); if (logger.isDebugEnabled()) { @@ -446,7 +442,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement "' from request in view with name '" + getBeanName() + "'"); } } - } + }); } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java index 642d7f442b5..e38e200ab7c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java @@ -487,11 +487,11 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { */ protected Map queryProperties(Map model) { Map result = new LinkedHashMap<>(); - for (Map.Entry entry : model.entrySet()) { - if (isEligibleProperty(entry.getKey(), entry.getValue())) { - result.put(entry.getKey(), entry.getValue()); + model.forEach((name, value) -> { + if (isEligibleProperty(name, value)) { + result.put(name, value); } - } + }); return result; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java index 7656cdd1c0b..85f9d68d397 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -217,13 +217,13 @@ public class MappingJackson2JsonView extends AbstractJackson2View { protected Object filterModel(Map model) { Map result = new HashMap<>(model.size()); Set modelKeys = (!CollectionUtils.isEmpty(this.modelKeys) ? this.modelKeys : model.keySet()); - for (Map.Entry entry : model.entrySet()) { - if (!(entry.getValue() instanceof BindingResult) && modelKeys.contains(entry.getKey()) && - !entry.getKey().equals(JsonView.class.getName()) && - !entry.getKey().equals(FilterProvider.class.getName())) { - result.put(entry.getKey(), entry.getValue()); + model.forEach((clazz, value) -> { + if (!(value instanceof BindingResult) && modelKeys.contains(clazz) && + !clazz.equals(JsonView.class.getName()) && + !clazz.equals(FilterProvider.class.getName())) { + result.put(clazz, value); } - } + }); return (this.extractValueFromSingleKeyModel && result.size() == 1 ? result.values().iterator().next() : result); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/XsltView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/XsltView.java index f4aa01ea0b8..a3629990341 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/XsltView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/XsltView.java @@ -380,9 +380,7 @@ public class XsltView extends AbstractUrlBasedView { * @param transformer the target transformer */ protected final void copyModelParameters(Map model, Transformer transformer) { - for (Map.Entry entry : model.entrySet()) { - transformer.setParameter(entry.getKey(), entry.getValue()); - } + model.forEach(transformer::setParameter); } /**