Skip to content

Commit 1b9e12f

Browse files
committed
Polish "Use Java 8 forEach method on Map"
Closes gh-1404
1 parent 13dc0cd commit 1b9e12f

File tree

7 files changed

+18
-24
lines changed

7 files changed

+18
-24
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java

Lines changed: 2 additions & 2 deletions
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.
@@ -268,7 +268,7 @@ public static <T> Map<String, T> beansOfTypeIncludingAncestors(ListableBeanFacto
268268
String beanName = entry.getKey();
269269
if (!result.containsKey(beanName) && !hbf.containsLocalBean(beanName)) {
270270
result.put(beanName, entry.getValue());
271-
}
271+
}
272272
});
273273
}
274274
}

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ public abstract class ClassUtils {
106106
primitiveWrapperTypeMap.put(Integer.class, int.class);
107107
primitiveWrapperTypeMap.put(Long.class, long.class);
108108
primitiveWrapperTypeMap.put(Short.class, short.class);
109-
110-
primitiveWrapperTypeMap.entrySet().forEach(entry -> {
111-
primitiveTypeToWrapperMap.put(entry.getValue(), entry.getKey());
112-
registerCommonClasses(entry.getKey());
109+
110+
primitiveWrapperTypeMap.forEach((key, value) -> {
111+
primitiveTypeToWrapperMap.put(value, key);
112+
registerCommonClasses(key);
113113
});
114114

115115
Set<Class<?>> primitiveTypes = new HashSet<>(32);

spring-core/src/main/java/org/springframework/util/CollectionUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ public static <K, V> MultiValueMap<K, V> toMultiValueMap(Map<K, List<V>> map) {
354354
public static <K, V> MultiValueMap<K, V> unmodifiableMultiValueMap(MultiValueMap<? extends K, ? extends V> map) {
355355
Assert.notNull(map, "'map' must not be null");
356356
Map<K, List<V>> result = new LinkedHashMap<>(map.size());
357-
map.entrySet().forEach(entry -> {
358-
List<? extends V> values = Collections.unmodifiableList(entry.getValue());
359-
result.put(entry.getKey(), (List<V>) values);
357+
map.forEach((key, value) -> {
358+
List<? extends V> values = Collections.unmodifiableList(value);
359+
result.put(key, (List<V>) values);
360360
});
361361
Map<K, List<V>> unmodifiableMap = Collections.unmodifiableMap(result);
362362
return toMultiValueMap(unmodifiableMap);
@@ -431,13 +431,13 @@ public void set(K key, V value) {
431431

432432
@Override
433433
public void setAll(Map<K, V> values) {
434-
values.entrySet().forEach(entry -> set(entry.getKey(), entry.getValue()));
434+
values.forEach(this::set);
435435
}
436436

437437
@Override
438438
public Map<K, V> toSingleValueMap() {
439439
LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<>(this.map.size());
440-
map.entrySet().forEach(entry -> singleValueMap.put(entry.getKey(), entry.getValue().get(0)));
440+
this.map.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
441441
return singleValueMap;
442442
}
443443

spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ public void putAll(Map<? extends String, ? extends V> map) {
169169
if (map.isEmpty()) {
170170
return;
171171
}
172-
map.entrySet().forEach(entry -> put(entry.getKey(), entry.getValue()));
173-
172+
map.forEach(this::put);
174173
}
175174

176175
@Override

spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ public void set(K key, V value) {
100100

101101
@Override
102102
public void setAll(Map<K, V> values) {
103-
values.entrySet().forEach(entry -> set(entry.getKey(), entry.getValue()));
103+
values.forEach(this::set);
104104
}
105105

106106
@Override
107107
public Map<K, V> toSingleValueMap() {
108108
LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<>(this.targetMap.size());
109-
this.targetMap.entrySet().forEach(entry ->
110-
singleValueMap.put(entry.getKey(), entry.getValue().get(0)));
109+
this.targetMap.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
111110

112111
return singleValueMap;
113112
}

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,8 @@ protected void detectHandlerMethods(final Object handler) {
192192
if (logger.isDebugEnabled()) {
193193
logger.debug(methods.size() + " request handler methods found on " + userType + ": " + methods);
194194
}
195-
196-
methods.entrySet().forEach(entry -> {
197-
Method invocableMethod = AopUtils.selectInvocableMethod(entry.getKey(), userType);
198-
T mapping = entry.getValue();
195+
methods.forEach((key, mapping) -> {
196+
Method invocableMethod = AopUtils.selectInvocableMethod(key, userType);
199197
registerHandlerMethod(handler, invocableMethod, mapping);
200198
});
201199
}

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMapping.java

Lines changed: 2 additions & 4 deletions
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.
@@ -114,9 +114,7 @@ protected void registerHandlers(Map<String, Object> urlMap) throws BeansExceptio
114114
logger.warn("Neither 'urlMap' nor 'mappings' set on SimpleUrlHandlerMapping");
115115
}
116116
else {
117-
urlMap.entrySet().forEach(entry -> {
118-
String url = entry.getKey();
119-
Object handler = entry.getValue();
117+
urlMap.forEach((url, handler) -> {
120118
// Prepend with slash if not already present.
121119
if (!url.startsWith("/")) {
122120
url = "/" + url;

0 commit comments

Comments
 (0)