diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java index c69dad3929..30d99fb739 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java @@ -265,10 +265,10 @@ public abstract class BeanFactoryUtils { if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) { Map parentResult = beansOfTypeIncludingAncestors( (ListableBeanFactory) hbf.getParentBeanFactory(), type); - parentResult.entrySet().forEach(entry -> { - String beanName = entry.getKey(); + + parentResult.forEach((beanName, beanType) -> { if (!result.containsKey(beanName) && !hbf.containsLocalBean(beanName)) { - result.put(beanName, entry.getValue()); + result.put(beanName, beanType); } }); } @@ -314,11 +314,10 @@ public abstract class BeanFactoryUtils { if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) { Map parentResult = beansOfTypeIncludingAncestors( (ListableBeanFactory) hbf.getParentBeanFactory(), type, includeNonSingletons, allowEagerInit); - - parentResult.entrySet().forEach(entry -> { - String beanName = entry.getKey(); + + parentResult.forEach((beanName, beanType) -> { if (!result.containsKey(beanName) && !hbf.containsLocalBean(beanName)) { - result.put(beanName, entry.getValue()); + result.put(beanName, beanType); } }); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 43de826052..e2c3b570f6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -1187,12 +1187,11 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } } if (!this.customEditors.isEmpty()) { - this.customEditors.entrySet().forEach(entry -> { - Class requiredType = entry.getKey(); - Class editorClass = entry.getValue(); - registry.registerCustomEditor(requiredType, BeanUtils.instantiateClass(editorClass)); - }); - } + this.customEditors.forEach( + (requiredType, editorClass) + -> registry.registerCustomEditor(requiredType, BeanUtils.instantiateClass(editorClass)) + ); + } } diff --git a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java index c0de3cd080..caf52d03eb 100644 --- a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java +++ b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java @@ -48,7 +48,7 @@ public class BindingAwareConcurrentModel extends ConcurrentModel { @Override public void putAll(Map map) { - map.entrySet().forEach(e -> removeBindingResultIfNecessary(e.getKey(), e.getValue())); + map.forEach(this::removeBindingResultIfNecessary); super.putAll(map); } diff --git a/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java b/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java index dbcdbabaef..38c42d4d10 100644 --- a/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java +++ b/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java @@ -195,8 +195,7 @@ public class LinkedMultiValueMap implements MultiValueMap, Serializa */ public LinkedMultiValueMap deepCopy() { LinkedMultiValueMap copy = new LinkedMultiValueMap<>(this.targetMap.size()); - this.targetMap.entrySet().forEach(entry -> - copy.put(entry.getKey(), new LinkedList<>(entry.getValue()))); + this.targetMap.forEach((k, v) -> copy.put(k, new LinkedList<>(v))); return copy; } diff --git a/spring-web/src/main/java/org/springframework/web/util/UriUtils.java b/spring-web/src/main/java/org/springframework/web/util/UriUtils.java index 2144b74c70..244af0d448 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriUtils.java @@ -194,9 +194,9 @@ public abstract class UriUtils { */ public static Map encodeUriVariables(Map uriVariables) { Map result = new LinkedHashMap<>(uriVariables.size()); - uriVariables.entrySet().stream().forEach(entry -> { - String stringValue = (entry.getValue() != null ? entry.getValue().toString() : ""); - result.put(entry.getKey(), encode(stringValue, StandardCharsets.UTF_8)); + uriVariables.forEach((key, value) -> { + String stringValue = (value != null ? value.toString() : ""); + result.put(key, encode(stringValue, StandardCharsets.UTF_8)); }); return result; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java index 4afeb41f27..319cd58b77 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java @@ -175,10 +175,11 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder { MultiValueMap requestCookies = request.getCookies(); if (!this.cookies.isEmpty()) { - this.cookies.forEach((name, values) -> values.forEach(value -> { - HttpCookie cookie = new HttpCookie(name, value); - requestCookies.add(name, cookie); - })); + this.cookies.forEach(( name , values) -> + values.forEach(value -> { + HttpCookie cookie = new HttpCookie(name, value); + requestCookies.add(name, cookie); + })); } return this.inserter.insert(request, new BodyInserter.Context() { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java index 84b3af1cf9..e503658edb 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java @@ -224,10 +224,10 @@ class ControllerMethodResolver { Class handlerType = handlerMethod.getBeanType(); // Global methods first - this.initBinderAdviceCache.entrySet().forEach(entry -> { - if (entry.getKey().isApplicableToBeanType(handlerType)) { - Object bean = entry.getKey().resolveBean(); - entry.getValue().forEach(method -> result.add(getInitBinderMethod(bean, method))); + this.initBinderAdviceCache.forEach((adviceBean, methods) -> { + if (adviceBean.isApplicableToBeanType(handlerType)) { + Object bean = adviceBean.resolveBean(); + methods.forEach(method -> result.add(getInitBinderMethod(bean, method))); } }); @@ -257,10 +257,10 @@ class ControllerMethodResolver { Class handlerType = handlerMethod.getBeanType(); // Global methods first - this.modelAttributeAdviceCache.entrySet().forEach(entry -> { - if (entry.getKey().isApplicableToBeanType(handlerType)) { - Object bean = entry.getKey().resolveBean(); - entry.getValue().forEach(method -> result.add(createAttributeMethod(bean, method))); + this.modelAttributeAdviceCache.forEach((adviceBean, methods) -> { + if (adviceBean.isApplicableToBeanType(handlerType)) { + Object bean = adviceBean.resolveBean(); + methods.forEach(method -> result.add(createAttributeMethod(bean, method))); } }); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java index e5fe8b9775..e60cfc6cf6 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java @@ -93,7 +93,7 @@ public class ReactorNettyWebSocketClient extends WebSocketClientSupport implemen } private void setNettyHeaders(HttpHeaders headers, io.netty.handler.codec.http.HttpHeaders nettyHeaders) { - headers.keySet().stream().forEach(key -> nettyHeaders.set(key, headers.get(key))); + headers.forEach(nettyHeaders::set); } private HttpHeaders toHttpHeaders(HttpClientResponse response) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/BaseViewTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/BaseViewTests.java index b8da8153a8..a2fbcb071c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/BaseViewTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/BaseViewTests.java @@ -281,8 +281,8 @@ public class BaseViewTests { */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void checkContainsAll(Map expected, Map actual) { - expected.keySet().stream().forEach( - key -> assertEquals("Values for model key '" + key + "' must match", expected.get(key), actual.get(key)) + expected.forEach( + (k, v) -> assertEquals("Values for model key '" + k + "' must match", expected.get(k), actual.get(k)) ); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java index 5c5854c130..69aac91192 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java @@ -84,8 +84,9 @@ public class InternalResourceViewTests { view.render(model, request, response); assertEquals(url, response.getForwardedUrl()); - model.keySet().stream().forEach( - key -> assertEquals("Values for model key '" + key + "' must match", model.get(key), request.getAttribute(key)) + + model.forEach( + (key, value) -> assertEquals("Values for model key '" + key + "' must match", value, request.getAttribute(key)) ); } @@ -101,7 +102,7 @@ public class InternalResourceViewTests { view.render(model, request, response); assertEquals(url, response.getIncludedUrl()); - model.keySet().stream().forEach(key -> verify(request).setAttribute(key, model.get(key))); + model.forEach((key, value) -> verify(request).setAttribute(key, value)); } @Test @@ -116,7 +117,7 @@ public class InternalResourceViewTests { view.render(model, request, response); assertEquals(url, response.getIncludedUrl()); - model.keySet().stream().forEach(key -> verify(request).setAttribute(key, model.get(key))); + model.forEach((key, value) -> verify(request).setAttribute(key, value)); } @Test @@ -132,7 +133,7 @@ public class InternalResourceViewTests { view.render(model, request, response); assertEquals(url, response.getIncludedUrl()); - model.keySet().stream().forEach(key -> verify(request).setAttribute(key, model.get(key))); + model.forEach((k, v) -> verify(request).setAttribute(k, v)); } }