Skip to content

Commit 451b419

Browse files
committed
Polish "Use Map#forEach instead of Map#entrySet#forEach"
Closes gh-1449
1 parent 2efa062 commit 451b419

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ 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-
269268
parentResult.forEach((beanName, beanType) -> {
270269
if (!result.containsKey(beanName) && !hbf.containsLocalBean(beanName)) {
271270
result.put(beanName, beanType);
@@ -314,7 +313,6 @@ public static <T> Map<String, T> beansOfTypeIncludingAncestors(
314313
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
315314
Map<String, T> parentResult = beansOfTypeIncludingAncestors(
316315
(ListableBeanFactory) hbf.getParentBeanFactory(), type, includeNonSingletons, allowEagerInit);
317-
318316
parentResult.forEach((beanName, beanType) -> {
319317
if (!result.containsKey(beanName) && !hbf.containsLocalBean(beanName)) {
320318
result.put(beanName, beanType);

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,11 +1187,9 @@ protected void registerCustomEditors(PropertyEditorRegistry registry) {
11871187
}
11881188
}
11891189
if (!this.customEditors.isEmpty()) {
1190-
this.customEditors.forEach(
1191-
(requiredType, editorClass)
1192-
-> registry.registerCustomEditor(requiredType, BeanUtils.instantiateClass(editorClass))
1193-
);
1194-
}
1190+
this.customEditors.forEach((requiredType, editorClass) ->
1191+
registry.registerCustomEditor(requiredType, BeanUtils.instantiateClass(editorClass)));
1192+
}
11951193
}
11961194

11971195

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,10 @@ 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) ->
179-
values.forEach(value -> {
180-
HttpCookie cookie = new HttpCookie(name, value);
181-
requestCookies.add(name, cookie);
182-
}));
178+
this.cookies.forEach((name, values) -> values.forEach(value -> {
179+
HttpCookie cookie = new HttpCookie(name, value);
180+
requestCookies.add(name, cookie);
181+
}));
183182
}
184183

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

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

Lines changed: 3 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.
@@ -281,9 +281,8 @@ public void attributeCSVParsingIgoresTrailingComma() {
281281
*/
282282
@SuppressWarnings({ "rawtypes", "unchecked" })
283283
private void checkContainsAll(Map expected, Map<String, Object> actual) {
284-
expected.forEach(
285-
(k, v) -> assertEquals("Values for model key '" + k + "' must match", expected.get(k), actual.get(k))
286-
);
284+
expected.forEach((k, v) -> assertEquals("Values for model key '" + k
285+
+ "' must match", expected.get(k), actual.get(k)));
287286
}
288287

289288

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 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.
@@ -84,10 +84,8 @@ public int getMinorVersion() {
8484
view.render(model, request, response);
8585
assertEquals(url, response.getForwardedUrl());
8686

87-
88-
model.forEach(
89-
(key, value) -> assertEquals("Values for model key '" + key + "' must match", value, request.getAttribute(key))
90-
);
87+
model.forEach((key, value) -> assertEquals("Values for model key '" + key
88+
+ "' must match", value, request.getAttribute(key)));
9189
}
9290

9391
@Test

0 commit comments

Comments
 (0)