From 78534a753db33c21f779e477adba0b8614dddcab Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 19 Mar 2018 08:00:36 -0400 Subject: [PATCH] Polish "Iterate map by using lambda function" See gh-12528 --- .../health/AbstractHealthAggregator.java | 4 ++-- ...udFoundryVcapEnvironmentPostProcessor.java | 22 +++++++++---------- .../jetty/JettyServletWebServerFactory.java | 4 ++-- .../tomcat/TomcatServletWebServerFactory.java | 5 +++-- .../undertow/FileSessionPersistence.java | 6 ++--- .../UndertowServletWebServerFactory.java | 4 ++-- .../boot/web/server/MimeMappings.java | 2 +- .../ServletContextInitializerBeans.java | 2 +- ...tySourceEnvironmentPostProcessorTests.java | 2 +- 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java index 6b689e03c8..a4f67bd573 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java @@ -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,7 +34,7 @@ public abstract class AbstractHealthAggregator implements HealthAggregator { @Override public final Health aggregate(Map healths) { List statusCandidates = new ArrayList<>(); - healths.values().forEach(health -> statusCandidates.add(health.getStatus())); + healths.values().forEach((health) -> statusCandidates.add(health.getStatus())); Status status = aggregateStatus(statusCandidates); Map details = aggregateDetails(healths); return new Health.Builder(status, details).build(); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java index a6b5c4f9d3..200fad0c62 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java @@ -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. @@ -196,39 +196,39 @@ public class CloudFoundryVcapEnvironmentPostProcessor @SuppressWarnings("unchecked") private void flatten(Properties properties, Map input, String path) { - input.forEach((entryKey, value) -> { - String key = getFullKey(path, entryKey); + input.forEach((key, value) -> { + String name = getPropertyName(path, key); if (value instanceof Map) { // Need a compound key - flatten(properties, (Map) value, key); + flatten(properties, (Map) value, name); } else if (value instanceof Collection) { // Need a compound key Collection collection = (Collection) 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; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java index 7d44b8340b..8bb8581689 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java @@ -246,8 +246,8 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor } private void addLocaleMappings(WebAppContext context) { - getLocaleCharsetMappings().forEach((locale, charset) -> - context.addLocaleEncoding(locale.toString(), charset.toString())); + getLocaleCharsetMappings().forEach((locale, charset) -> context + .addLocaleEncoding(locale.toString(), charset.toString())); } private File getTempDirectory() { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java index 7913b40474..e2ed862799 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java @@ -232,8 +232,9 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto } private void addLocaleMappings(TomcatEmbeddedContext context) { - getLocaleCharsetMappings().forEach((locale, charset) -> - context.addLocaleEncodingMappingParameter(locale.toString(), charset.toString())); + getLocaleCharsetMappings() + .forEach((locale, charset) -> context.addLocaleEncodingMappingParameter( + locale.toString(), charset.toString())); } private void configureTldSkipPatterns(TomcatEmbeddedContext context) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistence.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistence.java index 136546600a..f95af43583 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistence.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistence.java @@ -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,8 +69,8 @@ class FileSessionPersistence implements SessionPersistenceManager { private void save(Map sessionData, ObjectOutputStream stream) throws IOException { Map session = new LinkedHashMap<>(); - sessionData.forEach((key, value) -> - session.put(key, new SerializablePersistentSession(value))); + sessionData.forEach((key, value) -> session.put(key, + new SerializablePersistentSession(value))); stream.writeObject(session); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java index 11372b07e1..4424986e12 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java @@ -328,8 +328,8 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac } private void addLocaleMappings(DeploymentInfo deployment) { - getLocaleCharsetMappings().forEach((locale, charset) -> - deployment.addLocaleCharsetMapping(locale.toString(), charset.toString())); + getLocaleCharsetMappings().forEach((locale, charset) -> deployment + .addLocaleCharsetMapping(locale.toString(), charset.toString())); } private void registerServletContainerInitializerToDriveServletContextInitializers( diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java index f1b4f2c0c8..35c0403c31 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java @@ -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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java index 3bcb1d4a81..02396c273c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java @@ -79,7 +79,7 @@ public class ServletContextInitializerBeans addServletContextInitializerBeans(beanFactory); addAdaptableBeans(beanFactory); List sortedInitializers = new ArrayList<>(); - this.initializers.values().forEach(contextInitializers -> { + this.initializers.values().forEach((contextInitializers) -> { AnnotationAwareOrderComparator.sort(contextInitializers); sortedInitializers.addAll(contextInitializers); }); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/SystemEnvironmentPropertySourceEnvironmentPostProcessorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/SystemEnvironmentPropertySourceEnvironmentPostProcessorTests.java index 9f410b55ae..2d6b3bf171 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/SystemEnvironmentPropertySourceEnvironmentPostProcessorTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/SystemEnvironmentPropertySourceEnvironmentPostProcessorTests.java @@ -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.