Refactor iterator of Map with Java8's Map.forEach
See gh-1459
This commit is contained in:
parent
7018804e84
commit
1ef5f61ab2
|
|
@ -21,7 +21,6 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -43,11 +42,10 @@ abstract class PropertiesMarshaller {
|
|||
CandidateComponentsMetadata result = new CandidateComponentsMetadata();
|
||||
Properties props = new Properties();
|
||||
props.load(in);
|
||||
for (Map.Entry<Object, Object> entry : props.entrySet()) {
|
||||
String type = (String) entry.getKey();
|
||||
Set<String> candidates = new HashSet<>(Arrays.asList(((String) entry.getValue()).split(",")));
|
||||
result.add(new ItemMetadata(type, candidates));
|
||||
}
|
||||
props.forEach((type, value) -> {
|
||||
Set<String> candidates = new HashSet<>(Arrays.asList(((String) value).split(",")));
|
||||
result.add(new ItemMetadata((String) type, candidates));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package org.springframework.cache.caffeine;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
|
|
@ -223,9 +222,7 @@ public class CaffeineCacheManager implements CacheManager {
|
|||
* Create the known caches again with the current state of this manager.
|
||||
*/
|
||||
private void refreshKnownCaches() {
|
||||
for (Map.Entry<String, Cache> entry : this.cacheMap.entrySet()) {
|
||||
entry.setValue(createCaffeineCache(entry.getKey()));
|
||||
}
|
||||
this.cacheMap.forEach((key, value) -> createCaffeineCache(key));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,13 +131,12 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
|
|||
*/
|
||||
public MapSqlParameterSource addValues(@Nullable Map<String, ?> values) {
|
||||
if (values != null) {
|
||||
for (Map.Entry<String, ?> entry : values.entrySet()) {
|
||||
this.values.put(entry.getKey(), entry.getValue());
|
||||
if (entry.getValue() instanceof SqlParameterValue) {
|
||||
SqlParameterValue value = (SqlParameterValue) entry.getValue();
|
||||
registerSqlType(entry.getKey(), value.getSqlType());
|
||||
values.forEach((key, value) -> {
|
||||
this.values.put(key, value);
|
||||
if (value instanceof SqlParameterValue) {
|
||||
registerSqlType(key, ((SqlParameterValue) value).getSqlType());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,11 +114,11 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
|
|||
throw new IllegalArgumentException("Property 'targetDataSources' is required");
|
||||
}
|
||||
this.resolvedDataSources = new HashMap<>(this.targetDataSources.size());
|
||||
for (Map.Entry<Object, Object> entry : this.targetDataSources.entrySet()) {
|
||||
Object lookupKey = resolveSpecifiedLookupKey(entry.getKey());
|
||||
DataSource dataSource = resolveSpecifiedDataSource(entry.getValue());
|
||||
this.targetDataSources.forEach((key, value) -> {
|
||||
Object lookupKey = resolveSpecifiedLookupKey(key);
|
||||
DataSource dataSource = resolveSpecifiedDataSource(value);
|
||||
this.resolvedDataSources.put(lookupKey, dataSource);
|
||||
}
|
||||
});
|
||||
if (this.defaultTargetDataSource != null) {
|
||||
this.resolvedDefaultDataSource = resolveSpecifiedDataSource(this.defaultTargetDataSource);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,12 +225,8 @@ public class JmsListenerAnnotationBeanPostProcessor
|
|||
}
|
||||
else {
|
||||
// Non-empty set of methods
|
||||
for (Map.Entry<Method, Set<JmsListener>> entry : annotatedMethods.entrySet()) {
|
||||
Method method = entry.getKey();
|
||||
for (JmsListener listener : entry.getValue()) {
|
||||
processJmsListener(listener, method, bean);
|
||||
}
|
||||
}
|
||||
annotatedMethods.forEach((method, listeners) ->
|
||||
listeners.forEach(listener -> processJmsListener(listener, method, bean)));
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(annotatedMethods.size() + " @JmsListener methods processed on bean '" + beanName +
|
||||
"': " + annotatedMethods);
|
||||
|
|
|
|||
|
|
@ -158,12 +158,10 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B
|
|||
*/
|
||||
public void setTypeIdMappings(Map<String, Class<?>> typeIdMappings) {
|
||||
this.idClassMappings = new HashMap<>();
|
||||
for (Map.Entry<String, Class<?>> entry : typeIdMappings.entrySet()) {
|
||||
String id = entry.getKey();
|
||||
Class<?> clazz = entry.getValue();
|
||||
typeIdMappings.forEach((id, clazz) -> {
|
||||
this.idClassMappings.put(id, clazz);
|
||||
this.classIdMappings.put(clazz, id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -149,11 +149,11 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
|
|||
*/
|
||||
private MessageHeaders(MessageHeaders original, Set<String> keysToIgnore) {
|
||||
this.headers = new HashMap<>(original.headers.size() - keysToIgnore.size());
|
||||
for (Map.Entry<String, Object> entry : original.headers.entrySet()) {
|
||||
if (!keysToIgnore.contains(entry.getKey())) {
|
||||
this.headers.put(entry.getKey(), entry.getValue());
|
||||
original.headers.forEach((key, value) -> {
|
||||
if (!keysToIgnore.contains(key)) {
|
||||
this.headers.put(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -276,11 +276,11 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
|
|||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
Set<String> keysToIgnore = new HashSet<>();
|
||||
for (Map.Entry<String, Object> entry : this.headers.entrySet()) {
|
||||
if (!(entry.getValue() instanceof Serializable)) {
|
||||
keysToIgnore.add(entry.getKey());
|
||||
this.headers.forEach((key, value) -> {
|
||||
if (!(value instanceof Serializable)) {
|
||||
keysToIgnore.add(key);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (keysToIgnore.isEmpty()) {
|
||||
// All entries are serializable -> serialize the regular MessageHeaders instance
|
||||
|
|
|
|||
|
|
@ -288,9 +288,7 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(methods.size() + " message handler methods found on " + userType + ": " + methods);
|
||||
}
|
||||
for (Map.Entry<Method, T> entry : methods.entrySet()) {
|
||||
registerHandlerMethod(handler, entry.getKey(), entry.getValue());
|
||||
}
|
||||
methods.forEach((key, value) -> registerHandlerMethod(handler, key, value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,10 +113,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
|
|||
Assert.notNull(headers, "'headers' must not be null");
|
||||
if (readOnly) {
|
||||
Map<String, List<String>> map = new LinkedMultiValueMap<>(headers.size());
|
||||
for (Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
List<String> values = Collections.unmodifiableList(entry.getValue());
|
||||
map.put(entry.getKey(), values);
|
||||
}
|
||||
headers.forEach((key, value) -> map.put(key, Collections.unmodifiableList(value)));
|
||||
this.headers = Collections.unmodifiableMap(map);
|
||||
}
|
||||
else {
|
||||
|
|
@ -424,9 +421,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
|
|||
|
||||
@Override
|
||||
public void addAll(MultiValueMap<String, String> values) {
|
||||
for (Entry<String, List<String>> entry : values.entrySet()) {
|
||||
addAll(entry.getKey(), entry.getValue());
|
||||
}
|
||||
values.forEach(this::addAll);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -446,17 +441,13 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
|
|||
|
||||
@Override
|
||||
public void setAll(Map<String, String> values) {
|
||||
for (Entry<String, String> entry : values.entrySet()) {
|
||||
set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
values.forEach(this::set);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> toSingleValueMap() {
|
||||
LinkedHashMap<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
|
||||
for (Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
singleValueMap.put(entry.getKey(), entry.getValue().get(0));
|
||||
}
|
||||
headers.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
|
||||
return singleValueMap;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -387,11 +387,11 @@ public class MessageHeaderAccessor {
|
|||
*/
|
||||
public void copyHeaders(@Nullable Map<String, ?> headersToCopy) {
|
||||
if (headersToCopy != null) {
|
||||
for (Map.Entry<String, ?> entry : headersToCopy.entrySet()) {
|
||||
if (!isReadOnly(entry.getKey())) {
|
||||
setHeader(entry.getKey(), entry.getValue());
|
||||
headersToCopy.forEach((key, value) -> {
|
||||
if (!isReadOnly(key)) {
|
||||
setHeader(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -401,11 +401,11 @@ public class MessageHeaderAccessor {
|
|||
*/
|
||||
public void copyHeadersIfAbsent(@Nullable Map<String, ?> headersToCopy) {
|
||||
if (headersToCopy != null) {
|
||||
for (Map.Entry<String, ?> entry : headersToCopy.entrySet()) {
|
||||
if (!isReadOnly(entry.getKey())) {
|
||||
setHeaderIfAbsent(entry.getKey(), entry.getValue());
|
||||
headersToCopy.forEach((key, value) -> {
|
||||
if (!isReadOnly(key)) {
|
||||
setHeaderIfAbsent(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -197,11 +197,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
|||
if (headers == null) {
|
||||
return;
|
||||
}
|
||||
for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) {
|
||||
for (String value : headerEntry.getValue()) {
|
||||
addNativeHeader(headerEntry.getKey(), value);
|
||||
}
|
||||
}
|
||||
headers.forEach((key, values) -> values.forEach(value -> addNativeHeader(key, value)));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
|||
|
|
@ -325,11 +325,11 @@ public abstract class AbstractEntityManagerFactoryBean implements
|
|||
}
|
||||
Map<String, ?> vendorPropertyMap = this.jpaVendorAdapter.getJpaPropertyMap();
|
||||
if (vendorPropertyMap != null) {
|
||||
for (Map.Entry<String, ?> entry : vendorPropertyMap.entrySet()) {
|
||||
if (!this.jpaPropertyMap.containsKey(entry.getKey())) {
|
||||
this.jpaPropertyMap.put(entry.getKey(), entry.getValue());
|
||||
vendorPropertyMap.forEach((key, value) -> {
|
||||
if (!this.jpaPropertyMap.containsKey(key)) {
|
||||
this.jpaPropertyMap.put(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (this.entityManagerFactoryInterface == null) {
|
||||
this.entityManagerFactoryInterface = this.jpaVendorAdapter.getEntityManagerFactoryInterface();
|
||||
|
|
|
|||
|
|
@ -474,9 +474,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
|
|||
context.addPackages(targetPackages);
|
||||
}
|
||||
if (this.castorProperties != null) {
|
||||
for (Map.Entry<String, String> property : this.castorProperties.entrySet()) {
|
||||
context.setProperty(property.getKey(), property.getValue());
|
||||
}
|
||||
this.castorProperties.forEach(context::setProperty);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
|
@ -563,19 +561,13 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
|
|||
marshaller.setSchemaLocation(this.schemaLocation);
|
||||
marshaller.setUseXSITypeAtRoot(this.useXSITypeAtRoot);
|
||||
if (this.doctypes != null) {
|
||||
for (Map.Entry<String, String> doctype : this.doctypes.entrySet()) {
|
||||
marshaller.setDoctype(doctype.getKey(), doctype.getValue());
|
||||
}
|
||||
this.doctypes.forEach(marshaller::setDoctype);
|
||||
}
|
||||
if (this.processingInstructions != null) {
|
||||
for (Map.Entry<String, String> processingInstruction : this.processingInstructions.entrySet()) {
|
||||
marshaller.addProcessingInstruction(processingInstruction.getKey(), processingInstruction.getValue());
|
||||
}
|
||||
this.processingInstructions.forEach(marshaller::addProcessingInstruction);
|
||||
}
|
||||
if (this.namespaceMappings != null) {
|
||||
for (Map.Entry<String, String> entry : this.namespaceMappings.entrySet()) {
|
||||
marshaller.setNamespaceMapping(entry.getKey(), entry.getValue());
|
||||
}
|
||||
this.namespaceMappings.forEach(marshaller::setNamespaceMapping);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -666,9 +658,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
|
|||
unmarshaller.setReuseObjects(this.reuseObjects);
|
||||
unmarshaller.setClearCollections(this.clearCollections);
|
||||
if (this.namespaceToPackageMapping != null) {
|
||||
for (Map.Entry<String, String> mapping : this.namespaceToPackageMapping.entrySet()) {
|
||||
unmarshaller.addNamespaceToPackageMapping(mapping.getKey(), mapping.getValue());
|
||||
}
|
||||
this.namespaceToPackageMapping.forEach(unmarshaller::addNamespaceToPackageMapping);
|
||||
}
|
||||
if (this.entityResolver != null) {
|
||||
unmarshaller.setEntityResolver(this.entityResolver);
|
||||
|
|
|
|||
|
|
@ -469,15 +469,11 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
|
|||
try {
|
||||
if (this.aliases != null) {
|
||||
Map<String, Class<?>> classMap = toClassMap(this.aliases);
|
||||
for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) {
|
||||
xstream.alias(entry.getKey(), entry.getValue());
|
||||
}
|
||||
classMap.forEach(xstream::alias);
|
||||
}
|
||||
if (this.aliasesByType != null) {
|
||||
Map<String, Class<?>> classMap = toClassMap(this.aliasesByType);
|
||||
for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) {
|
||||
xstream.aliasType(entry.getKey(), entry.getValue());
|
||||
}
|
||||
classMap.forEach(xstream::aliasType);
|
||||
}
|
||||
if (this.fieldAliases != null) {
|
||||
for (Map.Entry<String, String> entry : this.fieldAliases.entrySet()) {
|
||||
|
|
@ -543,20 +539,20 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
|
|||
}
|
||||
|
||||
if (this.implicitCollections != null) {
|
||||
for (Map.Entry<Class<?>, String> entry : this.implicitCollections.entrySet()) {
|
||||
String[] collectionFields = StringUtils.commaDelimitedListToStringArray(entry.getValue());
|
||||
this.implicitCollections.forEach((key, fields) -> {
|
||||
String[] collectionFields = StringUtils.commaDelimitedListToStringArray(fields);
|
||||
for (String collectionField : collectionFields) {
|
||||
xstream.addImplicitCollection(entry.getKey(), collectionField);
|
||||
xstream.addImplicitCollection(key, collectionField);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (this.omittedFields != null) {
|
||||
for (Map.Entry<Class<?>, String> entry : this.omittedFields.entrySet()) {
|
||||
String[] fields = StringUtils.commaDelimitedListToStringArray(entry.getValue());
|
||||
this.omittedFields.forEach((key, value) -> {
|
||||
String[] fields = StringUtils.commaDelimitedListToStringArray(value);
|
||||
for (String field : fields) {
|
||||
xstream.omitField(entry.getKey(), field);
|
||||
xstream.omitField(key, field);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.annotatedClasses != null) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import java.util.Enumeration;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import javax.servlet.ServletContext;
|
||||
|
|
@ -182,11 +181,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
|
||||
// parameter
|
||||
Map<String, String[]> parentParams = parentRequest.getParameterMap();
|
||||
for (Map.Entry<String, String[]> parentParam : parentParams.entrySet()) {
|
||||
String paramName = parentParam.getKey();
|
||||
String[] paramValues = parentParam.getValue();
|
||||
request.addParameter(paramName, paramValues);
|
||||
}
|
||||
parentParams.forEach(request::addParameter);
|
||||
|
||||
// cookie
|
||||
Cookie[] parentCookies = parentRequest.getCookies();
|
||||
|
|
@ -314,9 +309,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
}
|
||||
|
||||
private void headers(MockHttpServletRequest request) {
|
||||
for (Entry<String, String> header : this.webRequest.getAdditionalHeaders().entrySet()) {
|
||||
request.addHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
this.webRequest.getAdditionalHeaders().forEach(request::addHeader);
|
||||
}
|
||||
|
||||
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) {
|
||||
for (Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
uriComponents.getQueryParams().forEach((name, values) -> {
|
||||
String urlDecodedName = urlDecode(name);
|
||||
for (String value : entry.getValue()) {
|
||||
values.forEach(value -> {
|
||||
value = (value != null ? urlDecode(value) : "");
|
||||
request.addParameter(urlDecodedName, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
for (NameValuePair param : this.webRequest.getRequestParameters()) {
|
||||
request.addParameter(param.getName(), param.getValue());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.Cookie;
|
||||
|
|
@ -310,9 +309,7 @@ public class MockHttpServletRequestBuilder
|
|||
* @param httpHeaders the headers and values to add
|
||||
*/
|
||||
public MockHttpServletRequestBuilder headers(HttpHeaders httpHeaders) {
|
||||
for (Map.Entry<String, List<String>> entry : httpHeaders.entrySet()) {
|
||||
this.headers.addAll(entry.getKey(), entry.getValue());
|
||||
}
|
||||
httpHeaders.forEach(this.headers::addAll);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -697,12 +694,10 @@ public class MockHttpServletRequestBuilder
|
|||
}
|
||||
|
||||
private void addRequestParams(MockHttpServletRequest request, MultiValueMap<String, String> map) {
|
||||
for (Entry<String, List<String>> entry : map.entrySet()) {
|
||||
for (String value : entry.getValue()) {
|
||||
value = (value != null ? UriUtils.decode(value, StandardCharsets.UTF_8) : null);
|
||||
request.addParameter(UriUtils.decode(entry.getKey(), StandardCharsets.UTF_8), value);
|
||||
}
|
||||
}
|
||||
map.forEach((key, values) -> values.forEach(value -> {
|
||||
value = (value != null ? UriUtils.decode(value, StandardCharsets.UTF_8) : null);
|
||||
request.addParameter(UriUtils.decode(key, StandardCharsets.UTF_8), value);
|
||||
}));
|
||||
}
|
||||
|
||||
private MultiValueMap<String, String> parseFormData(final MediaType mediaType) {
|
||||
|
|
|
|||
|
|
@ -106,9 +106,7 @@ public class MethodMapTransactionAttributeSource
|
|||
*/
|
||||
protected void initMethodMap(@Nullable Map<String, TransactionAttribute> methodMap) {
|
||||
if (methodMap != null) {
|
||||
for (Map.Entry<String, TransactionAttribute> entry : methodMap.entrySet()) {
|
||||
addTransactionalMethod(entry.getKey(), entry.getValue());
|
||||
}
|
||||
methodMap.forEach(this::addTransactionalMethod);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,9 +61,7 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
|
|||
* @see TransactionAttributeEditor
|
||||
*/
|
||||
public void setNameMap(Map<String, TransactionAttribute> nameMap) {
|
||||
for (Map.Entry<String, TransactionAttribute> entry : nameMap.entrySet()) {
|
||||
addTransactionalMethod(entry.getKey(), entry.getValue());
|
||||
}
|
||||
nameMap.forEach(this::addTransactionalMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue