Skip to content

Commit 27aabb1

Browse files
committed
Polish "Refact iterator of Map with Java 8 forEach"
Closes gh-1451
1 parent dab7a7f commit 27aabb1

File tree

20 files changed

+32
-40
lines changed

20 files changed

+32
-40
lines changed

spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ public MutablePropertyValues(@Nullable Map<?, ?> original) {
8787
// There is no replacement of existing property values.
8888
if (original != null) {
8989
this.propertyValueList = new ArrayList<>(original.size());
90-
original.forEach(
91-
(attrName, attrValue)
92-
-> this.propertyValueList.add(new PropertyValue(attrName.toString(), attrValue))
93-
);
90+
original.forEach((attrName, attrValue) -> this.propertyValueList.add(
91+
new PropertyValue(attrName.toString(), attrValue)));
9492
}
9593
else {
9694
this.propertyValueList = new ArrayList<>(0);
@@ -152,10 +150,8 @@ public MutablePropertyValues addPropertyValues(@Nullable PropertyValues other) {
152150
*/
153151
public MutablePropertyValues addPropertyValues(@Nullable Map<?, ?> other) {
154152
if (other != null) {
155-
other.forEach(
156-
(attrName, attrValue)
157-
-> addPropertyValue(new PropertyValue(attrName.toString(), attrValue))
158-
);
153+
other.forEach((attrName, attrValue) -> addPropertyValue(
154+
new PropertyValue(attrName.toString(), attrValue)));
159155
}
160156
return this;
161157
}

spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ protected void copyCustomEditorsTo(PropertyEditorRegistry target, @Nullable Stri
457457
String actualPropertyName =
458458
(nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null);
459459
if (this.customEditors != null) {
460-
this.customEditors.forEach((clazz, propertyEditor) -> target.registerCustomEditor(clazz, propertyEditor));
460+
this.customEditors.forEach(target::registerCustomEditor);
461461
}
462462
if (this.customEditorsForPath != null) {
463463
for (Map.Entry<String, CustomEditorHolder> entry : this.customEditorsForPath.entrySet()) {

spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void addArgumentValues(@Nullable ConstructorArgumentValues other) {
7777
);
7878
other.genericArgumentValues.stream()
7979
.filter(valueHolder -> !this.genericArgumentValues.contains(valueHolder))
80-
.forEach(valueHolder -> addOrMergeGenericArgumentValue(valueHolder));
80+
.forEach(valueHolder -> addOrMergeGenericArgumentValue(valueHolder.copy()));
8181
}
8282
}
8383

spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717
package org.springframework.beans.factory.config;
1818

1919
import java.beans.PropertyEditor;
20-
import java.util.Arrays;
2120
import java.util.Map;
2221

2322
import org.apache.commons.logging.Log;
@@ -141,7 +140,9 @@ public void setCustomEditors(Map<Class<?>, Class<? extends PropertyEditor>> cust
141140
@Override
142141
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
143142
if (this.propertyEditorRegistrars != null) {
144-
Arrays.stream(this.propertyEditorRegistrars).forEach(beanFactory::addPropertyEditorRegistrar);
143+
for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) {
144+
beanFactory.addPropertyEditorRegistrar(propertyEditorRegistrar);
145+
}
145146
}
146147
if (this.customEditors != null) {
147148
this.customEditors.forEach(beanFactory::registerCustomEditor);

spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ private void loadBeanDefinitionsFromImportedResources(
351351
}
352352

353353
private void loadBeanDefinitionsFromRegistrars(Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> registrars) {
354-
registrars.forEach((registrar, metadata) -> registrar.registerBeanDefinitions(metadata, this.registry));
354+
registrars.forEach((registrar, metadata) ->
355+
registrar.registerBeanDefinitions(metadata, this.registry));
355356
}
356357

357358

spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ protected void registerBeans() {
544544
}
545545

546546
if (!this.beans.isEmpty()) {
547-
this.beans.forEach((beanName, instance) -> registerBeanNameOrInstance(instance, beanName));
547+
this.beans.forEach((beanName, instance) ->
548+
registerBeanNameOrInstance(instance, beanName));
548549
}
549550
}
550551

0 commit comments

Comments
 (0)