Browse Source

Merge pull request #1459 from diguage:lambda-map

* pr/1459:
  Polish "Refactor iterator of Map with Java8's Map.forEach"
  Refactor iterator of Map with Java8's Map.forEach
pull/1458/merge
Stephane Nicoll 8 years ago
parent
commit
5e4e3fbe8b
  1. 10
      spring-context-indexer/src/main/java/org/springframework/context/index/PropertiesMarshaller.java
  2. 2
      spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java
  3. 13
      spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSource.java
  4. 8
      spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java
  5. 9
      spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java
  6. 6
      spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJackson2MessageConverter.java
  7. 16
      spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java
  8. 4
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java
  9. 17
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java
  10. 16
      spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java
  11. 7
      spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java
  12. 8
      spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java
  13. 22
      spring-oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java
  14. 24
      spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java
  15. 20
      spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java
  16. 15
      spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
  17. 4
      spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java
  18. 6
      spring-tx/src/main/java/org/springframework/transaction/interceptor/NameMatchTransactionAttributeSource.java

10
spring-context-indexer/src/main/java/org/springframework/context/index/PropertiesMarshaller.java

@ -21,7 +21,6 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
@ -43,11 +42,10 @@ abstract class PropertiesMarshaller {
CandidateComponentsMetadata result = new CandidateComponentsMetadata(); CandidateComponentsMetadata result = new CandidateComponentsMetadata();
Properties props = new Properties(); Properties props = new Properties();
props.load(in); props.load(in);
for (Map.Entry<Object, Object> entry : props.entrySet()) { props.forEach((type, value) -> {
String type = (String) entry.getKey(); Set<String> candidates = new HashSet<>(Arrays.asList(((String) value).split(",")));
Set<String> candidates = new HashSet<>(Arrays.asList(((String) entry.getValue()).split(","))); result.add(new ItemMetadata((String) type, candidates));
result.add(new ItemMetadata(type, candidates)); });
}
return result; return result;
} }

2
spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

13
spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSource.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -131,13 +131,12 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
*/ */
public MapSqlParameterSource addValues(@Nullable Map<String, ?> values) { public MapSqlParameterSource addValues(@Nullable Map<String, ?> values) {
if (values != null) { if (values != null) {
for (Map.Entry<String, ?> entry : values.entrySet()) { values.forEach((key, value) -> {
this.values.put(entry.getKey(), entry.getValue()); this.values.put(key, value);
if (entry.getValue() instanceof SqlParameterValue) { if (value instanceof SqlParameterValue) {
SqlParameterValue value = (SqlParameterValue) entry.getValue(); registerSqlType(key, ((SqlParameterValue) value).getSqlType());
registerSqlType(entry.getKey(), value.getSqlType());
} }
} });
} }
return this; return this;
} }

8
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java

@ -114,11 +114,11 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
throw new IllegalArgumentException("Property 'targetDataSources' is required"); throw new IllegalArgumentException("Property 'targetDataSources' is required");
} }
this.resolvedDataSources = new HashMap<>(this.targetDataSources.size()); this.resolvedDataSources = new HashMap<>(this.targetDataSources.size());
for (Map.Entry<Object, Object> entry : this.targetDataSources.entrySet()) { this.targetDataSources.forEach((key, value) -> {
Object lookupKey = resolveSpecifiedLookupKey(entry.getKey()); Object lookupKey = resolveSpecifiedLookupKey(key);
DataSource dataSource = resolveSpecifiedDataSource(entry.getValue()); DataSource dataSource = resolveSpecifiedDataSource(value);
this.resolvedDataSources.put(lookupKey, dataSource); this.resolvedDataSources.put(lookupKey, dataSource);
} });
if (this.defaultTargetDataSource != null) { if (this.defaultTargetDataSource != null) {
this.resolvedDefaultDataSource = resolveSpecifiedDataSource(this.defaultTargetDataSource); this.resolvedDefaultDataSource = resolveSpecifiedDataSource(this.defaultTargetDataSource);
} }

9
spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java

@ -225,12 +225,9 @@ public class JmsListenerAnnotationBeanPostProcessor
} }
else { else {
// Non-empty set of methods // Non-empty set of methods
for (Map.Entry<Method, Set<JmsListener>> entry : annotatedMethods.entrySet()) { annotatedMethods.forEach((method, listeners) ->
Method method = entry.getKey(); listeners.forEach(listener ->
for (JmsListener listener : entry.getValue()) { processJmsListener(listener, method, bean)));
processJmsListener(listener, method, bean);
}
}
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(annotatedMethods.size() + " @JmsListener methods processed on bean '" + beanName + logger.debug(annotatedMethods.size() + " @JmsListener methods processed on bean '" + beanName +
"': " + annotatedMethods); "': " + annotatedMethods);

6
spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJackson2MessageConverter.java

@ -158,12 +158,10 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B
*/ */
public void setTypeIdMappings(Map<String, Class<?>> typeIdMappings) { public void setTypeIdMappings(Map<String, Class<?>> typeIdMappings) {
this.idClassMappings = new HashMap<>(); this.idClassMappings = new HashMap<>();
for (Map.Entry<String, Class<?>> entry : typeIdMappings.entrySet()) { typeIdMappings.forEach((id, clazz) -> {
String id = entry.getKey();
Class<?> clazz = entry.getValue();
this.idClassMappings.put(id, clazz); this.idClassMappings.put(id, clazz);
this.classIdMappings.put(clazz, id); this.classIdMappings.put(clazz, id);
} });
} }
@Override @Override

16
spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java

@ -149,11 +149,11 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
*/ */
private MessageHeaders(MessageHeaders original, Set<String> keysToIgnore) { private MessageHeaders(MessageHeaders original, Set<String> keysToIgnore) {
this.headers = new HashMap<>(original.headers.size() - keysToIgnore.size()); this.headers = new HashMap<>(original.headers.size() - keysToIgnore.size());
for (Map.Entry<String, Object> entry : original.headers.entrySet()) { original.headers.forEach((key, value) -> {
if (!keysToIgnore.contains(entry.getKey())) { if (!keysToIgnore.contains(key)) {
this.headers.put(entry.getKey(), entry.getValue()); this.headers.put(key, value);
} }
} });
} }
@ -276,11 +276,11 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
private void writeObject(ObjectOutputStream out) throws IOException { private void writeObject(ObjectOutputStream out) throws IOException {
Set<String> keysToIgnore = new HashSet<>(); Set<String> keysToIgnore = new HashSet<>();
for (Map.Entry<String, Object> entry : this.headers.entrySet()) { this.headers.forEach((key, value) -> {
if (!(entry.getValue() instanceof Serializable)) { if (!(value instanceof Serializable)) {
keysToIgnore.add(entry.getKey()); keysToIgnore.add(key);
} }
} });
if (keysToIgnore.isEmpty()) { if (keysToIgnore.isEmpty()) {
// All entries are serializable -> serialize the regular MessageHeaders instance // All entries are serializable -> serialize the regular MessageHeaders instance

4
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java

@ -288,9 +288,7 @@ public abstract class AbstractMethodMessageHandler<T>
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(methods.size() + " message handler methods found on " + userType + ": " + methods); logger.debug(methods.size() + " message handler methods found on " + userType + ": " + methods);
} }
for (Map.Entry<Method, T> entry : methods.entrySet()) { methods.forEach((key, value) -> registerHandlerMethod(handler, key, value));
registerHandlerMethod(handler, entry.getKey(), entry.getValue());
}
} }
} }

17
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java

@ -113,10 +113,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
Assert.notNull(headers, "'headers' must not be null"); Assert.notNull(headers, "'headers' must not be null");
if (readOnly) { if (readOnly) {
Map<String, List<String>> map = new LinkedMultiValueMap<>(headers.size()); Map<String, List<String>> map = new LinkedMultiValueMap<>(headers.size());
for (Entry<String, List<String>> entry : headers.entrySet()) { headers.forEach((key, value) -> map.put(key, Collections.unmodifiableList(value)));
List<String> values = Collections.unmodifiableList(entry.getValue());
map.put(entry.getKey(), values);
}
this.headers = Collections.unmodifiableMap(map); this.headers = Collections.unmodifiableMap(map);
} }
else { else {
@ -424,9 +421,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
@Override @Override
public void addAll(MultiValueMap<String, String> values) { public void addAll(MultiValueMap<String, String> values) {
for (Entry<String, List<String>> entry : values.entrySet()) { values.forEach(this::addAll);
addAll(entry.getKey(), entry.getValue());
}
} }
/** /**
@ -446,17 +441,13 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
@Override @Override
public void setAll(Map<String, String> values) { public void setAll(Map<String, String> values) {
for (Entry<String, String> entry : values.entrySet()) { values.forEach(this::set);
set(entry.getKey(), entry.getValue());
}
} }
@Override @Override
public Map<String, String> toSingleValueMap() { public Map<String, String> toSingleValueMap() {
LinkedHashMap<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size()); LinkedHashMap<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
for (Entry<String, List<String>> entry : headers.entrySet()) { headers.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
singleValueMap.put(entry.getKey(), entry.getValue().get(0));
}
return singleValueMap; return singleValueMap;
} }

16
spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java

@ -387,11 +387,11 @@ public class MessageHeaderAccessor {
*/ */
public void copyHeaders(@Nullable Map<String, ?> headersToCopy) { public void copyHeaders(@Nullable Map<String, ?> headersToCopy) {
if (headersToCopy != null) { if (headersToCopy != null) {
for (Map.Entry<String, ?> entry : headersToCopy.entrySet()) { headersToCopy.forEach((key, value) -> {
if (!isReadOnly(entry.getKey())) { if (!isReadOnly(key)) {
setHeader(entry.getKey(), entry.getValue()); setHeader(key, value);
} }
} });
} }
} }
@ -401,11 +401,11 @@ public class MessageHeaderAccessor {
*/ */
public void copyHeadersIfAbsent(@Nullable Map<String, ?> headersToCopy) { public void copyHeadersIfAbsent(@Nullable Map<String, ?> headersToCopy) {
if (headersToCopy != null) { if (headersToCopy != null) {
for (Map.Entry<String, ?> entry : headersToCopy.entrySet()) { headersToCopy.forEach((key, value) -> {
if (!isReadOnly(entry.getKey())) { if (!isReadOnly(key)) {
setHeaderIfAbsent(entry.getKey(), entry.getValue()); setHeaderIfAbsent(key, value);
} }
} });
} }
} }

7
spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java

@ -197,11 +197,8 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
if (headers == null) { if (headers == null) {
return; return;
} }
for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) { headers.forEach((key, values) ->
for (String value : headerEntry.getValue()) { values.forEach(value -> addNativeHeader(key, value)));
addNativeHeader(headerEntry.getKey(), value);
}
}
} }
@Nullable @Nullable

8
spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java

@ -325,11 +325,11 @@ public abstract class AbstractEntityManagerFactoryBean implements
} }
Map<String, ?> vendorPropertyMap = this.jpaVendorAdapter.getJpaPropertyMap(); Map<String, ?> vendorPropertyMap = this.jpaVendorAdapter.getJpaPropertyMap();
if (vendorPropertyMap != null) { if (vendorPropertyMap != null) {
for (Map.Entry<String, ?> entry : vendorPropertyMap.entrySet()) { vendorPropertyMap.forEach((key, value) -> {
if (!this.jpaPropertyMap.containsKey(entry.getKey())) { if (!this.jpaPropertyMap.containsKey(key)) {
this.jpaPropertyMap.put(entry.getKey(), entry.getValue()); this.jpaPropertyMap.put(key, value);
} }
} });
} }
if (this.entityManagerFactoryInterface == null) { if (this.entityManagerFactoryInterface == null) {
this.entityManagerFactoryInterface = this.jpaVendorAdapter.getEntityManagerFactoryInterface(); this.entityManagerFactoryInterface = this.jpaVendorAdapter.getEntityManagerFactoryInterface();

22
spring-oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -474,9 +474,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
context.addPackages(targetPackages); context.addPackages(targetPackages);
} }
if (this.castorProperties != null) { if (this.castorProperties != null) {
for (Map.Entry<String, String> property : this.castorProperties.entrySet()) { this.castorProperties.forEach(context::setProperty);
context.setProperty(property.getKey(), property.getValue());
}
} }
return context; return context;
} }
@ -563,19 +561,13 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
marshaller.setSchemaLocation(this.schemaLocation); marshaller.setSchemaLocation(this.schemaLocation);
marshaller.setUseXSITypeAtRoot(this.useXSITypeAtRoot); marshaller.setUseXSITypeAtRoot(this.useXSITypeAtRoot);
if (this.doctypes != null) { if (this.doctypes != null) {
for (Map.Entry<String, String> doctype : this.doctypes.entrySet()) { this.doctypes.forEach(marshaller::setDoctype);
marshaller.setDoctype(doctype.getKey(), doctype.getValue());
}
} }
if (this.processingInstructions != null) { if (this.processingInstructions != null) {
for (Map.Entry<String, String> processingInstruction : this.processingInstructions.entrySet()) { this.processingInstructions.forEach(marshaller::addProcessingInstruction);
marshaller.addProcessingInstruction(processingInstruction.getKey(), processingInstruction.getValue());
}
} }
if (this.namespaceMappings != null) { if (this.namespaceMappings != null) {
for (Map.Entry<String, String> entry : this.namespaceMappings.entrySet()) { this.namespaceMappings.forEach(marshaller::setNamespaceMapping);
marshaller.setNamespaceMapping(entry.getKey(), entry.getValue());
}
} }
} }
@ -666,9 +658,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
unmarshaller.setReuseObjects(this.reuseObjects); unmarshaller.setReuseObjects(this.reuseObjects);
unmarshaller.setClearCollections(this.clearCollections); unmarshaller.setClearCollections(this.clearCollections);
if (this.namespaceToPackageMapping != null) { if (this.namespaceToPackageMapping != null) {
for (Map.Entry<String, String> mapping : this.namespaceToPackageMapping.entrySet()) { this.namespaceToPackageMapping.forEach(unmarshaller::addNamespaceToPackageMapping);
unmarshaller.addNamespaceToPackageMapping(mapping.getKey(), mapping.getValue());
}
} }
if (this.entityResolver != null) { if (this.entityResolver != null) {
unmarshaller.setEntityResolver(this.entityResolver); unmarshaller.setEntityResolver(this.entityResolver);

24
spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java

@ -469,15 +469,11 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
try { try {
if (this.aliases != null) { if (this.aliases != null) {
Map<String, Class<?>> classMap = toClassMap(this.aliases); Map<String, Class<?>> classMap = toClassMap(this.aliases);
for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) { classMap.forEach(xstream::alias);
xstream.alias(entry.getKey(), entry.getValue());
}
} }
if (this.aliasesByType != null) { if (this.aliasesByType != null) {
Map<String, Class<?>> classMap = toClassMap(this.aliasesByType); Map<String, Class<?>> classMap = toClassMap(this.aliasesByType);
for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) { classMap.forEach(xstream::aliasType);
xstream.aliasType(entry.getKey(), entry.getValue());
}
} }
if (this.fieldAliases != null) { if (this.fieldAliases != null) {
for (Map.Entry<String, String> entry : this.fieldAliases.entrySet()) { for (Map.Entry<String, String> entry : this.fieldAliases.entrySet()) {
@ -543,20 +539,20 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
} }
if (this.implicitCollections != null) { if (this.implicitCollections != null) {
for (Map.Entry<Class<?>, String> entry : this.implicitCollections.entrySet()) { this.implicitCollections.forEach((key, fields) -> {
String[] collectionFields = StringUtils.commaDelimitedListToStringArray(entry.getValue()); String[] collectionFields = StringUtils.commaDelimitedListToStringArray(fields);
for (String collectionField : collectionFields) { for (String collectionField : collectionFields) {
xstream.addImplicitCollection(entry.getKey(), collectionField); xstream.addImplicitCollection(key, collectionField);
} }
} });
} }
if (this.omittedFields != null) { if (this.omittedFields != null) {
for (Map.Entry<Class<?>, String> entry : this.omittedFields.entrySet()) { this.omittedFields.forEach((key, value) -> {
String[] fields = StringUtils.commaDelimitedListToStringArray(entry.getValue()); String[] fields = StringUtils.commaDelimitedListToStringArray(value);
for (String field : fields) { for (String field : fields) {
xstream.omitField(entry.getKey(), field); xstream.omitField(key, field);
} }
} });
} }
if (this.annotatedClasses != null) { if (this.annotatedClasses != null) {

20
spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java

@ -26,7 +26,6 @@ import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -182,11 +181,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
// parameter // parameter
Map<String, String[]> parentParams = parentRequest.getParameterMap(); Map<String, String[]> parentParams = parentRequest.getParameterMap();
for (Map.Entry<String, String[]> parentParam : parentParams.entrySet()) { parentParams.forEach(request::addParameter);
String paramName = parentParam.getKey();
String[] paramValues = parentParam.getValue();
request.addParameter(paramName, paramValues);
}
// cookie // cookie
Cookie[] parentCookies = parentRequest.getCookies(); Cookie[] parentCookies = parentRequest.getCookies();
@ -314,9 +309,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
} }
private void headers(MockHttpServletRequest request) { private void headers(MockHttpServletRequest request) {
for (Entry<String, String> header : this.webRequest.getAdditionalHeaders().entrySet()) { this.webRequest.getAdditionalHeaders().forEach(request::addHeader);
request.addHeader(header.getKey(), header.getValue());
}
} }
private MockHttpSession httpSession(MockHttpServletRequest request, final String sessionid) { private MockHttpSession httpSession(MockHttpServletRequest request, final String sessionid) {
@ -359,14 +352,13 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
} }
private void params(MockHttpServletRequest request, UriComponents uriComponents) { private void params(MockHttpServletRequest request, UriComponents uriComponents) {
for (Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) { uriComponents.getQueryParams().forEach((name, values) -> {
String name = entry.getKey();
String urlDecodedName = urlDecode(name); String urlDecodedName = urlDecode(name);
for (String value : entry.getValue()) { values.forEach(value -> {
value = (value != null ? urlDecode(value) : ""); value = (value != null ? urlDecode(value) : "");
request.addParameter(urlDecodedName, value); request.addParameter(urlDecodedName, value);
} });
} });
for (NameValuePair param : this.webRequest.getRequestParameters()) { for (NameValuePair param : this.webRequest.getRequestParameters()) {
request.addParameter(param.getName(), param.getValue()); request.addParameter(param.getName(), param.getValue());
} }

15
spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java

@ -28,7 +28,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
@ -310,9 +309,7 @@ public class MockHttpServletRequestBuilder
* @param httpHeaders the headers and values to add * @param httpHeaders the headers and values to add
*/ */
public MockHttpServletRequestBuilder headers(HttpHeaders httpHeaders) { public MockHttpServletRequestBuilder headers(HttpHeaders httpHeaders) {
for (Map.Entry<String, List<String>> entry : httpHeaders.entrySet()) { httpHeaders.forEach(this.headers::addAll);
this.headers.addAll(entry.getKey(), entry.getValue());
}
return this; return this;
} }
@ -697,12 +694,10 @@ public class MockHttpServletRequestBuilder
} }
private void addRequestParams(MockHttpServletRequest request, MultiValueMap<String, String> map) { private void addRequestParams(MockHttpServletRequest request, MultiValueMap<String, String> map) {
for (Entry<String, List<String>> entry : map.entrySet()) { map.forEach((key, values) -> values.forEach(value -> {
for (String value : entry.getValue()) { value = (value != null ? UriUtils.decode(value, StandardCharsets.UTF_8) : null);
value = (value != null ? UriUtils.decode(value, StandardCharsets.UTF_8) : null); request.addParameter(UriUtils.decode(key, StandardCharsets.UTF_8), value);
request.addParameter(UriUtils.decode(entry.getKey(), StandardCharsets.UTF_8), value); }));
}
}
} }
private MultiValueMap<String, String> parseFormData(final MediaType mediaType) { private MultiValueMap<String, String> parseFormData(final MediaType mediaType) {

4
spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java

@ -106,9 +106,7 @@ public class MethodMapTransactionAttributeSource
*/ */
protected void initMethodMap(@Nullable Map<String, TransactionAttribute> methodMap) { protected void initMethodMap(@Nullable Map<String, TransactionAttribute> methodMap) {
if (methodMap != null) { if (methodMap != null) {
for (Map.Entry<String, TransactionAttribute> entry : methodMap.entrySet()) { methodMap.forEach(this::addTransactionalMethod);
addTransactionalMethod(entry.getKey(), entry.getValue());
}
} }
} }

6
spring-tx/src/main/java/org/springframework/transaction/interceptor/NameMatchTransactionAttributeSource.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -61,9 +61,7 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
* @see TransactionAttributeEditor * @see TransactionAttributeEditor
*/ */
public void setNameMap(Map<String, TransactionAttribute> nameMap) { public void setNameMap(Map<String, TransactionAttribute> nameMap) {
for (Map.Entry<String, TransactionAttribute> entry : nameMap.entrySet()) { nameMap.forEach(this::addTransactionalMethod);
addTransactionalMethod(entry.getKey(), entry.getValue());
}
} }
/** /**

Loading…
Cancel
Save