Skip to content

Commit 2efa062

Browse files
diguagesnicoll
authored andcommitted
Use Map#forEach instead of Map#entrySet#forEach
See spring-projectsgh-1449
1 parent 424bc75 commit 2efa062

File tree

10 files changed

+38
-39
lines changed

10 files changed

+38
-39
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ public static <T> Map<String, T> beansOfTypeIncludingAncestors(ListableBeanFacto
265265
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
266266
Map<String, T> parentResult = beansOfTypeIncludingAncestors(
267267
(ListableBeanFactory) hbf.getParentBeanFactory(), type);
268-
parentResult.entrySet().forEach(entry -> {
269-
String beanName = entry.getKey();
268+
269+
parentResult.forEach((beanName, beanType) -> {
270270
if (!result.containsKey(beanName) && !hbf.containsLocalBean(beanName)) {
271-
result.put(beanName, entry.getValue());
271+
result.put(beanName, beanType);
272272
}
273273
});
274274
}
@@ -314,11 +314,10 @@ public static <T> Map<String, T> beansOfTypeIncludingAncestors(
314314
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
315315
Map<String, T> parentResult = beansOfTypeIncludingAncestors(
316316
(ListableBeanFactory) hbf.getParentBeanFactory(), type, includeNonSingletons, allowEagerInit);
317-
318-
parentResult.entrySet().forEach(entry -> {
319-
String beanName = entry.getKey();
317+
318+
parentResult.forEach((beanName, beanType) -> {
320319
if (!result.containsKey(beanName) && !hbf.containsLocalBean(beanName)) {
321-
result.put(beanName, entry.getValue());
320+
result.put(beanName, beanType);
322321
}
323322
});
324323
}

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,12 +1187,11 @@ protected void registerCustomEditors(PropertyEditorRegistry registry) {
11871187
}
11881188
}
11891189
if (!this.customEditors.isEmpty()) {
1190-
this.customEditors.entrySet().forEach(entry -> {
1191-
Class<?> requiredType = entry.getKey();
1192-
Class<? extends PropertyEditor> editorClass = entry.getValue();
1193-
registry.registerCustomEditor(requiredType, BeanUtils.instantiateClass(editorClass));
1194-
});
1195-
}
1190+
this.customEditors.forEach(
1191+
(requiredType, editorClass)
1192+
-> registry.registerCustomEditor(requiredType, BeanUtils.instantiateClass(editorClass))
1193+
);
1194+
}
11961195
}
11971196

11981197

spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Object put(String key, Object value) {
4848

4949
@Override
5050
public void putAll(Map<? extends String, ?> map) {
51-
map.entrySet().forEach(e -> removeBindingResultIfNecessary(e.getKey(), e.getValue()));
51+
map.forEach(this::removeBindingResultIfNecessary);
5252
super.putAll(map);
5353
}
5454

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ public Set<Entry<K, List<V>>> entrySet() {
195195
*/
196196
public LinkedMultiValueMap<K, V> deepCopy() {
197197
LinkedMultiValueMap<K, V> copy = new LinkedMultiValueMap<>(this.targetMap.size());
198-
this.targetMap.entrySet().forEach(entry ->
199-
copy.put(entry.getKey(), new LinkedList<>(entry.getValue())));
198+
this.targetMap.forEach((k, v) -> copy.put(k, new LinkedList<>(v)));
200199

201200
return copy;
202201
}

spring-web/src/main/java/org/springframework/web/util/UriUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ public static String encode(String source, Charset charset) {
194194
*/
195195
public static Map<String, String> encodeUriVariables(Map<String, ?> uriVariables) {
196196
Map<String, String> result = new LinkedHashMap<>(uriVariables.size());
197-
uriVariables.entrySet().stream().forEach(entry -> {
198-
String stringValue = (entry.getValue() != null ? entry.getValue().toString() : "");
199-
result.put(entry.getKey(), encode(stringValue, StandardCharsets.UTF_8));
197+
uriVariables.forEach((key, value) -> {
198+
String stringValue = (value != null ? value.toString() : "");
199+
result.put(key, encode(stringValue, StandardCharsets.UTF_8));
200200
});
201201
return result;
202202
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ public Mono<Void> writeTo(ClientHttpRequest request, ExchangeStrategies strategi
175175

176176
MultiValueMap<String, HttpCookie> requestCookies = request.getCookies();
177177
if (!this.cookies.isEmpty()) {
178-
this.cookies.forEach((name, values) -> values.forEach(value -> {
179-
HttpCookie cookie = new HttpCookie(name, value);
180-
requestCookies.add(name, cookie);
181-
}));
178+
this.cookies.forEach(( name , values) ->
179+
values.forEach(value -> {
180+
HttpCookie cookie = new HttpCookie(name, value);
181+
requestCookies.add(name, cookie);
182+
}));
182183
}
183184

184185
return this.inserter.insert(request, new BodyInserter.Context() {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ public List<SyncInvocableHandlerMethod> getInitBinderMethods(HandlerMethod handl
224224
Class<?> handlerType = handlerMethod.getBeanType();
225225

226226
// Global methods first
227-
this.initBinderAdviceCache.entrySet().forEach(entry -> {
228-
if (entry.getKey().isApplicableToBeanType(handlerType)) {
229-
Object bean = entry.getKey().resolveBean();
230-
entry.getValue().forEach(method -> result.add(getInitBinderMethod(bean, method)));
227+
this.initBinderAdviceCache.forEach((adviceBean, methods) -> {
228+
if (adviceBean.isApplicableToBeanType(handlerType)) {
229+
Object bean = adviceBean.resolveBean();
230+
methods.forEach(method -> result.add(getInitBinderMethod(bean, method)));
231231
}
232232
});
233233

@@ -257,10 +257,10 @@ public List<InvocableHandlerMethod> getModelAttributeMethods(HandlerMethod handl
257257
Class<?> handlerType = handlerMethod.getBeanType();
258258

259259
// Global methods first
260-
this.modelAttributeAdviceCache.entrySet().forEach(entry -> {
261-
if (entry.getKey().isApplicableToBeanType(handlerType)) {
262-
Object bean = entry.getKey().resolveBean();
263-
entry.getValue().forEach(method -> result.add(createAttributeMethod(bean, method)));
260+
this.modelAttributeAdviceCache.forEach((adviceBean, methods) -> {
261+
if (adviceBean.isApplicableToBeanType(handlerType)) {
262+
Object bean = adviceBean.resolveBean();
263+
methods.forEach(method -> result.add(createAttributeMethod(bean, method)));
264264
}
265265
});
266266

spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Mono<Void> execute(URI url, HttpHeaders headers, WebSocketHandler handler
9393
}
9494

9595
private void setNettyHeaders(HttpHeaders headers, io.netty.handler.codec.http.HttpHeaders nettyHeaders) {
96-
headers.keySet().stream().forEach(key -> nettyHeaders.set(key, headers.get(key)));
96+
headers.forEach(nettyHeaders::set);
9797
}
9898

9999
private HttpHeaders toHttpHeaders(HttpClientResponse response) {

spring-webmvc/src/test/java/org/springframework/web/servlet/view/BaseViewTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ public void attributeCSVParsingIgoresTrailingComma() {
281281
*/
282282
@SuppressWarnings({ "rawtypes", "unchecked" })
283283
private void checkContainsAll(Map expected, Map<String, Object> actual) {
284-
expected.keySet().stream().forEach(
285-
key -> assertEquals("Values for model key '" + key + "' must match", expected.get(key), actual.get(key))
284+
expected.forEach(
285+
(k, v) -> assertEquals("Values for model key '" + k + "' must match", expected.get(k), actual.get(k))
286286
);
287287
}
288288

spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public int getMinorVersion() {
8484
view.render(model, request, response);
8585
assertEquals(url, response.getForwardedUrl());
8686

87-
model.keySet().stream().forEach(
88-
key -> assertEquals("Values for model key '" + key + "' must match", model.get(key), request.getAttribute(key))
87+
88+
model.forEach(
89+
(key, value) -> assertEquals("Values for model key '" + key + "' must match", value, request.getAttribute(key))
8990
);
9091
}
9192

@@ -101,7 +102,7 @@ public void alwaysInclude() throws Exception {
101102
view.render(model, request, response);
102103
assertEquals(url, response.getIncludedUrl());
103104

104-
model.keySet().stream().forEach(key -> verify(request).setAttribute(key, model.get(key)));
105+
model.forEach((key, value) -> verify(request).setAttribute(key, value));
105106
}
106107

107108
@Test
@@ -116,7 +117,7 @@ public void includeOnAttribute() throws Exception {
116117
view.render(model, request, response);
117118
assertEquals(url, response.getIncludedUrl());
118119

119-
model.keySet().stream().forEach(key -> verify(request).setAttribute(key, model.get(key)));
120+
model.forEach((key, value) -> verify(request).setAttribute(key, value));
120121
}
121122

122123
@Test
@@ -132,7 +133,7 @@ public void includeOnCommitted() throws Exception {
132133
view.render(model, request, response);
133134
assertEquals(url, response.getIncludedUrl());
134135

135-
model.keySet().stream().forEach(key -> verify(request).setAttribute(key, model.get(key)));
136+
model.forEach((k, v) -> verify(request).setAttribute(k, v));
136137
}
137138

138139
}

0 commit comments

Comments
 (0)