Merge pull request #12528 from igor-suhorukov
* pr/12528: Polish "Iterate map by using lambda function" Iterate map by using lambda function
This commit is contained in:
@@ -112,13 +112,11 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
|
||||
Map<String, Object> beans = getConfigurationPropertiesBeans(context,
|
||||
beanFactoryMetadata);
|
||||
Map<String, ConfigurationPropertiesBeanDescriptor> beanDescriptors = new HashMap<>();
|
||||
for (Map.Entry<String, Object> entry : beans.entrySet()) {
|
||||
String beanName = entry.getKey();
|
||||
Object bean = entry.getValue();
|
||||
beans.forEach((beanName, bean) -> {
|
||||
String prefix = extractPrefix(context, beanFactoryMetadata, beanName);
|
||||
beanDescriptors.put(beanName, new ConfigurationPropertiesBeanDescriptor(
|
||||
prefix, sanitize(prefix, safeSerialize(mapper, bean, prefix))));
|
||||
}
|
||||
});
|
||||
return new ContextConfigurationProperties(beanDescriptors,
|
||||
context.getParent() == null ? null : context.getParent().getId());
|
||||
}
|
||||
@@ -229,10 +227,8 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> sanitize(String prefix, Map<String, Object> map) {
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
map.forEach((key, value) -> {
|
||||
String qualifiedKey = (prefix.isEmpty() ? prefix : prefix + ".") + key;
|
||||
Object value = entry.getValue();
|
||||
if (value instanceof Map) {
|
||||
map.put(key, sanitize(qualifiedKey, (Map<String, Object>) value));
|
||||
}
|
||||
@@ -244,7 +240,7 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
|
||||
value = this.sanitizer.sanitize(qualifiedKey, value);
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,9 +34,7 @@ public abstract class AbstractHealthAggregator implements HealthAggregator {
|
||||
@Override
|
||||
public final Health aggregate(Map<String, Health> healths) {
|
||||
List<Status> statusCandidates = new ArrayList<>();
|
||||
for (Map.Entry<String, Health> entry : healths.entrySet()) {
|
||||
statusCandidates.add(entry.getValue().getStatus());
|
||||
}
|
||||
healths.values().forEach((health) -> statusCandidates.add(health.getStatus()));
|
||||
Status status = aggregateStatus(statusCandidates);
|
||||
Map<String, Object> details = aggregateDetails(healths);
|
||||
return new Health.Builder(status, details).build();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -197,40 +196,39 @@ public class CloudFoundryVcapEnvironmentPostProcessor
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void flatten(Properties properties, Map<String, Object> input, String path) {
|
||||
for (Entry<String, Object> entry : input.entrySet()) {
|
||||
String key = getFullKey(path, entry.getKey());
|
||||
Object value = entry.getValue();
|
||||
input.forEach((key, value) -> {
|
||||
String name = getPropertyName(path, key);
|
||||
if (value instanceof Map) {
|
||||
// Need a compound key
|
||||
flatten(properties, (Map<String, Object>) value, key);
|
||||
flatten(properties, (Map<String, Object>) value, name);
|
||||
}
|
||||
else if (value instanceof Collection) {
|
||||
// Need a compound key
|
||||
Collection<Object> collection = (Collection<Object>) value;
|
||||
properties.put(key,
|
||||
properties.put(name,
|
||||
StringUtils.collectionToCommaDelimitedString(collection));
|
||||
int count = 0;
|
||||
for (Object item : collection) {
|
||||
String itemKey = "[" + (count++) + "]";
|
||||
flatten(properties, Collections.singletonMap(itemKey, item), key);
|
||||
flatten(properties, Collections.singletonMap(itemKey, item), name);
|
||||
}
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
properties.put(key, value);
|
||||
properties.put(name, value);
|
||||
}
|
||||
else if (value instanceof Number) {
|
||||
properties.put(key, value.toString());
|
||||
properties.put(name, value.toString());
|
||||
}
|
||||
else if (value instanceof Boolean) {
|
||||
properties.put(key, value.toString());
|
||||
properties.put(name, value.toString());
|
||||
}
|
||||
else {
|
||||
properties.put(key, value == null ? "" : value);
|
||||
properties.put(name, value == null ? "" : value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String getFullKey(String path, String key) {
|
||||
private String getPropertyName(String path, String key) {
|
||||
if (!StringUtils.hasText(path)) {
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -126,10 +126,8 @@ public class SpringApplicationJsonEnvironmentPostProcessor
|
||||
|
||||
private void flatten(String prefix, Map<String, Object> result,
|
||||
Map<String, Object> map) {
|
||||
prefix = (prefix == null ? "" : prefix + ".");
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
extract(prefix + entry.getKey(), result, entry.getValue());
|
||||
}
|
||||
String namePrefix = (prefix == null ? "" : prefix + ".");
|
||||
map.forEach((key, value) -> extract(namePrefix + key, result, value));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -23,14 +23,11 @@ import java.net.InetSocketAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.http.MimeTypes;
|
||||
import org.eclipse.jetty.server.AbstractConnector;
|
||||
@@ -249,11 +246,8 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
|
||||
}
|
||||
|
||||
private void addLocaleMappings(WebAppContext context) {
|
||||
for (Map.Entry<Locale, Charset> entry : getLocaleCharsetMappings().entrySet()) {
|
||||
Locale locale = entry.getKey();
|
||||
Charset charset = entry.getValue();
|
||||
context.addLocaleEncoding(locale.toString(), charset.toString());
|
||||
}
|
||||
getLocaleCharsetMappings().forEach((locale, charset) -> context
|
||||
.addLocaleEncoding(locale.toString(), charset.toString()));
|
||||
}
|
||||
|
||||
private File getTempDirectory() {
|
||||
|
||||
@@ -30,8 +30,6 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContainerInitializer;
|
||||
@@ -234,12 +232,9 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
|
||||
}
|
||||
|
||||
private void addLocaleMappings(TomcatEmbeddedContext context) {
|
||||
for (Map.Entry<Locale, Charset> entry : getLocaleCharsetMappings().entrySet()) {
|
||||
Locale locale = entry.getKey();
|
||||
Charset charset = entry.getValue();
|
||||
context.addLocaleEncodingMappingParameter(locale.toString(),
|
||||
charset.toString());
|
||||
}
|
||||
getLocaleCharsetMappings()
|
||||
.forEach((locale, charset) -> context.addLocaleEncodingMappingParameter(
|
||||
locale.toString(), charset.toString()));
|
||||
}
|
||||
|
||||
private void configureTldSkipPatterns(TomcatEmbeddedContext context) {
|
||||
@@ -267,10 +262,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
|
||||
jspServlet.setName("jsp");
|
||||
jspServlet.setServletClass(getJsp().getClassName());
|
||||
jspServlet.addInitParameter("fork", "false");
|
||||
for (Entry<String, String> initParameter : getJsp().getInitParameters()
|
||||
.entrySet()) {
|
||||
jspServlet.addInitParameter(initParameter.getKey(), initParameter.getValue());
|
||||
}
|
||||
getJsp().getInitParameters().forEach(jspServlet::addInitParameter);
|
||||
jspServlet.setLoadOnStartup(3);
|
||||
context.addChild(jspServlet);
|
||||
context.addServletMappingDecoded("*.jsp", "jsp");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -69,10 +69,8 @@ class FileSessionPersistence implements SessionPersistenceManager {
|
||||
private void save(Map<String, PersistentSession> sessionData,
|
||||
ObjectOutputStream stream) throws IOException {
|
||||
Map<String, Serializable> session = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, PersistentSession> entry : sessionData.entrySet()) {
|
||||
session.put(entry.getKey(),
|
||||
new SerializablePersistentSession(entry.getValue()));
|
||||
}
|
||||
sessionData.forEach((key, value) -> session.put(key,
|
||||
new SerializablePersistentSession(value)));
|
||||
stream.writeObject(session);
|
||||
}
|
||||
|
||||
@@ -104,13 +102,12 @@ class FileSessionPersistence implements SessionPersistenceManager {
|
||||
Map<String, SerializablePersistentSession> session = readSession(stream);
|
||||
long time = System.currentTimeMillis();
|
||||
Map<String, PersistentSession> result = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, SerializablePersistentSession> entry : session
|
||||
.entrySet()) {
|
||||
PersistentSession entrySession = entry.getValue().getPersistentSession();
|
||||
session.forEach((key, value) -> {
|
||||
PersistentSession entrySession = value.getPersistentSession();
|
||||
if (entrySession.getExpiration().getTime() > time) {
|
||||
result.put(entry.getKey(), entrySession);
|
||||
result.put(key, entrySession);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,15 +20,12 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContainerInitializer;
|
||||
@@ -331,11 +328,8 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
|
||||
}
|
||||
|
||||
private void addLocaleMappings(DeploymentInfo deployment) {
|
||||
for (Map.Entry<Locale, Charset> entry : getLocaleCharsetMappings().entrySet()) {
|
||||
Locale locale = entry.getKey();
|
||||
Charset charset = entry.getValue();
|
||||
deployment.addLocaleCharsetMapping(locale.toString(), charset.toString());
|
||||
}
|
||||
getLocaleCharsetMappings().forEach((locale, charset) -> deployment
|
||||
.addLocaleCharsetMapping(locale.toString(), charset.toString()));
|
||||
}
|
||||
|
||||
private void registerServletContainerInitializerToDriveServletContextInitializers(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -244,9 +244,7 @@ public final class MimeMappings implements Iterable<MimeMappings.Mapping> {
|
||||
public MimeMappings(Map<String, String> mappings) {
|
||||
Assert.notNull(mappings, "Mappings must not be null");
|
||||
this.map = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, String> entry : mappings.entrySet()) {
|
||||
add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
mappings.forEach(this::add);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,11 +79,10 @@ public class ServletContextInitializerBeans
|
||||
addServletContextInitializerBeans(beanFactory);
|
||||
addAdaptableBeans(beanFactory);
|
||||
List<ServletContextInitializer> sortedInitializers = new ArrayList<>();
|
||||
for (Map.Entry<?, List<ServletContextInitializer>> entry : this.initializers
|
||||
.entrySet()) {
|
||||
AnnotationAwareOrderComparator.sort(entry.getValue());
|
||||
sortedInitializers.addAll(entry.getValue());
|
||||
}
|
||||
this.initializers.values().forEach((contextInitializers) -> {
|
||||
AnnotationAwareOrderComparator.sort(contextInitializers);
|
||||
sortedInitializers.addAll(contextInitializers);
|
||||
});
|
||||
this.sortedList = Collections.unmodifiableList(sortedInitializers);
|
||||
}
|
||||
|
||||
|
||||
@@ -384,12 +384,12 @@ public class ServletWebServerApplicationContext extends GenericWebApplicationCon
|
||||
}
|
||||
|
||||
public void restore() {
|
||||
for (Map.Entry<String, Scope> entry : this.scopes.entrySet()) {
|
||||
this.scopes.forEach((key, value) -> {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Restoring user defined scope " + entry.getKey());
|
||||
logger.info("Restoring user defined scope " + key);
|
||||
}
|
||||
this.beanFactory.registerScope(entry.getKey(), entry.getValue());
|
||||
}
|
||||
this.beanFactory.registerScope(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,12 +66,12 @@ public class SystemEnvironmentPropertySourceEnvironmentPostProcessorTests {
|
||||
.getPropertySources().get("systemEnvironment");
|
||||
Map<String, Object> originalMap = (Map<String, Object>) original.getSource();
|
||||
Map<String, Object> replacedMap = replaced.getSource();
|
||||
for (Map.Entry<String, Object> entry : originalMap.entrySet()) {
|
||||
Object actual = replacedMap.get(entry.getKey());
|
||||
assertThat(actual).isEqualTo(entry.getValue());
|
||||
assertThat(replaced.getOrigin(entry.getKey()))
|
||||
originalMap.forEach((key, value) -> {
|
||||
Object actual = replacedMap.get(key);
|
||||
assertThat(actual).isEqualTo(value);
|
||||
assertThat(replaced.getOrigin(key))
|
||||
.isInstanceOf(SystemEnvironmentOrigin.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -44,8 +44,6 @@ import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
@@ -866,12 +864,9 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
AbstractServletWebServerFactory factory = getFactory();
|
||||
this.webServer = factory.getWebServer();
|
||||
Map<String, String> configuredMimeMappings = getActualMimeMappings();
|
||||
Set<Entry<String, String>> entrySet = configuredMimeMappings.entrySet();
|
||||
Collection<MimeMappings.Mapping> expectedMimeMappings = getExpectedMimeMappings();
|
||||
for (Entry<String, String> entry : entrySet) {
|
||||
assertThat(expectedMimeMappings)
|
||||
.contains(new MimeMappings.Mapping(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
configuredMimeMappings.forEach((key, value) -> assertThat(expectedMimeMappings).
|
||||
contains(new MimeMappings.Mapping(key, value)));
|
||||
for (MimeMappings.Mapping mapping : expectedMimeMappings) {
|
||||
assertThat(configuredMimeMappings).containsEntry(mapping.getExtension(),
|
||||
mapping.getMimeType());
|
||||
|
||||
Reference in New Issue
Block a user