Browse Source

Use Map#forEach instead of Map#entrySet#forEach

See gh-1449
pull/1454/merge
diguage 8 years ago committed by Stephane Nicoll
parent
commit
2efa06237a
  1. 13
      spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java
  2. 11
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
  3. 2
      spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java
  4. 3
      spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java
  5. 6
      spring-web/src/main/java/org/springframework/web/util/UriUtils.java
  6. 9
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java
  7. 16
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java
  8. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java
  9. 4
      spring-webmvc/src/test/java/org/springframework/web/servlet/view/BaseViewTests.java
  10. 11
      spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java

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

@ -265,10 +265,10 @@ public abstract class BeanFactoryUtils { @@ -265,10 +265,10 @@ public abstract class BeanFactoryUtils {
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
Map<String, T> 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 { @@ -314,11 +314,10 @@ public abstract class BeanFactoryUtils {
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
Map<String, T> 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);
}
});
}

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

@ -1187,12 +1187,11 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp @@ -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<? extends PropertyEditor> editorClass = entry.getValue();
registry.registerCustomEditor(requiredType, BeanUtils.instantiateClass(editorClass));
});
}
this.customEditors.forEach(
(requiredType, editorClass)
-> registry.registerCustomEditor(requiredType, BeanUtils.instantiateClass(editorClass))
);
}
}

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

@ -48,7 +48,7 @@ public class BindingAwareConcurrentModel extends ConcurrentModel { @@ -48,7 +48,7 @@ public class BindingAwareConcurrentModel extends ConcurrentModel {
@Override
public void putAll(Map<? extends String, ?> map) {
map.entrySet().forEach(e -> removeBindingResultIfNecessary(e.getKey(), e.getValue()));
map.forEach(this::removeBindingResultIfNecessary);
super.putAll(map);
}

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

@ -195,8 +195,7 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa @@ -195,8 +195,7 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa
*/
public LinkedMultiValueMap<K, V> deepCopy() {
LinkedMultiValueMap<K, V> 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;
}

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

@ -194,9 +194,9 @@ public abstract class UriUtils { @@ -194,9 +194,9 @@ public abstract class UriUtils {
*/
public static Map<String, String> encodeUriVariables(Map<String, ?> uriVariables) {
Map<String, String> 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;
}

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

@ -175,10 +175,11 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder { @@ -175,10 +175,11 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder {
MultiValueMap<String, HttpCookie> 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() {

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

@ -224,10 +224,10 @@ class ControllerMethodResolver { @@ -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 { @@ -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)));
}
});

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

@ -93,7 +93,7 @@ public class ReactorNettyWebSocketClient extends WebSocketClientSupport implemen @@ -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) {

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

@ -281,8 +281,8 @@ public class BaseViewTests { @@ -281,8 +281,8 @@ public class BaseViewTests {
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private void checkContainsAll(Map expected, Map<String, Object> 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))
);
}

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

@ -84,8 +84,9 @@ public class InternalResourceViewTests { @@ -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 { @@ -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 { @@ -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 { @@ -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));
}
}

Loading…
Cancel
Save