From 69bc19e0ca6925b7d526942afd18e95b4e28fa8f Mon Sep 17 00:00:00 2001 From: igor-suhorukov Date: Sat, 24 Mar 2018 09:19:03 +0300 Subject: [PATCH 1/2] Use lambdas for map entry iteration where possible See gh-12626 --- .../condition/ConditionsReportEndpoint.java | 11 +++--- ...CompositeHealthIndicatorConfiguration.java | 5 +-- ...eReactiveHealthIndicatorConfiguration.java | 5 +-- ...ourceHealthIndicatorAutoConfiguration.java | 8 ++--- .../boot/actuate/env/EnvironmentEndpoint.java | 11 +++--- .../AutoConfigurationSorter.java | 9 +++-- ...ImportAutoConfigurationImportSelector.java | 6 ++-- .../cache/CacheConfigurations.java | 11 +++--- .../condition/AbstractNestedCondition.java | 9 ++--- .../condition/BeanTypeRegistry.java | 22 ++++-------- .../condition/ConditionEvaluationReport.java | 31 ++++++++-------- .../condition/OnBeanCondition.java | 8 ++--- .../condition/OnPropertyCondition.java | 9 +++-- .../NoSuchBeanDefinitionFailureAnalyzer.java | 9 ++--- .../jersey/JerseyAutoConfiguration.java | 5 +-- .../session/SessionStoreMappings.java | 19 ++++------ .../web/servlet/WebMvcAutoConfiguration.java | 5 +-- .../WebServicesAutoConfiguration.java | 5 +-- .../init/ProjectGenerationRequest.java | 10 +----- .../AnnotatedNodeASTTransformation.java | 11 ++---- .../devtools/settings/DevToolsSettings.java | 8 ++--- .../AutoConfigureAnnotationProcessor.java | 29 +++++++-------- ...SimpleConfigurationMetadataRepository.java | 12 ++----- ...figurationMetadataAnnotationProcessor.java | 36 ++++++------------- .../TypeElementMembers.java | 10 +++--- .../configurationprocessor/TypeUtils.java | 4 +-- .../gradle/tasks/buildinfo/BuildInfo.java | 5 +-- .../loader/tools/BuildPropertiesWriter.java | 14 +++----- .../PropertiesMergingResourceTransformer.java | 9 +++-- .../springframework/boot/maven/Verify.java | 11 +++--- .../boot/logging/LoggingSystem.java | 10 +++--- 31 files changed, 125 insertions(+), 232 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java index 00822ebce1..d4d4be0363 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java @@ -123,15 +123,14 @@ public class ConditionsReportEndpoint { this.negativeMatches = new LinkedHashMap<>(); this.exclusions = report.getExclusions(); this.unconditionalClasses = report.getUnconditionalClasses(); - for (Map.Entry entry : report - .getConditionAndOutcomesBySource().entrySet()) { - if (entry.getValue().isFullMatch()) { - add(this.positiveMatches, entry.getKey(), entry.getValue()); + report.getConditionAndOutcomesBySource().forEach((key, value) -> { + if (value.isFullMatch()) { + add(this.positiveMatches, key, value); } else { - add(this.negativeMatches, entry.getKey(), entry.getValue()); + add(this.negativeMatches, key, value); } - } + }); this.parentId = context.getParent() == null ? null : context.getParent().getId(); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java index e1608a9790..c197d4a1a1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java @@ -44,10 +44,7 @@ public abstract class CompositeHealthIndicatorConfiguration entry : beans.entrySet()) { - composite.addHealthIndicator(entry.getKey(), - createHealthIndicator(entry.getValue())); - } + beans.forEach((key, value) -> composite.addHealthIndicator(key, createHealthIndicator(value))); return composite; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java index e753442300..00f83d1975 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java @@ -43,10 +43,7 @@ public abstract class CompositeReactiveHealthIndicatorConfiguration entry : beans.entrySet()) { - composite.addHealthIndicator(entry.getKey(), - createHealthIndicator(entry.getValue())); - } + beans.forEach((key, value) -> composite.addHealthIndicator(key, createHealthIndicator(value))); return composite; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java index e80938c862..a8112e902c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java @@ -84,11 +84,11 @@ public class DataSourceHealthIndicatorAutoConfiguration extends return null; } Map dataSources = new LinkedHashMap<>(); - for (Map.Entry entry : candidates.entrySet()) { - if (!(entry.getValue() instanceof AbstractRoutingDataSource)) { - dataSources.put(entry.getKey(), entry.getValue()); + candidates.forEach((key, value) -> { + if (!(value instanceof AbstractRoutingDataSource)) { + dataSources.put(key, value); } - } + }); return dataSources; } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java index f380cdbddc..e0183282e0 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java @@ -120,13 +120,10 @@ public class EnvironmentEndpoint { private PropertySummaryDescriptor getPropertySummaryDescriptor( Map descriptors) { - for (Map.Entry entry : descriptors.entrySet()) { - if (entry.getValue() != null) { - return new PropertySummaryDescriptor(entry.getKey(), - entry.getValue().getValue()); - } - } - return null; + return descriptors.entrySet().stream(). + filter((entry) -> entry.getValue() != null). + map((entry) -> new PropertySummaryDescriptor(entry.getKey(), entry.getValue().getValue())). + findFirst().orElse(null); } private Map getPropertySourceDescriptors( diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java index 92bf33a3ed..f883ad891d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java @@ -142,12 +142,11 @@ class AutoConfigurationSorter { public Set getClassesRequestedAfter(String className) { Set rtn = new LinkedHashSet<>(); rtn.addAll(get(className).getAfter()); - for (Map.Entry entry : this.classes - .entrySet()) { - if (entry.getValue().getBefore().contains(className)) { - rtn.add(entry.getKey()); + this.classes.forEach((key, value) -> { + if (value.getBefore().contains(className)) { + rtn.add(key); } - } + }); return rtn; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java index 5857da091a..7e18f430f5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java @@ -74,9 +74,9 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec AnnotationAttributes attributes) { List candidates = new ArrayList<>(); Map, List> annotations = getAnnotations(metadata); - for (Map.Entry, List> entry : annotations.entrySet()) { - collectCandidateConfigurations(entry.getKey(), entry.getValue(), candidates); - } + annotations.forEach((key, value) -> { + collectCandidateConfigurations(key, value, candidates); + }); return candidates; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java index 22fce136ca..441dc1170b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java @@ -57,13 +57,10 @@ final class CacheConfigurations { } public static CacheType getType(String configurationClassName) { - for (Map.Entry> entry : MAPPINGS.entrySet()) { - if (entry.getValue().getName().equals(configurationClassName)) { - return entry.getKey(); - } - } - throw new IllegalStateException( - "Unknown configuration class " + configurationClassName); + return MAPPINGS.entrySet().stream().filter((entry) -> + entry.getValue().getName().equals(configurationClassName)). + map(Map.Entry::getKey).findFirst(). + orElseThrow(() -> new IllegalStateException("Unknown configuration class " + configurationClassName)); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AbstractNestedCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AbstractNestedCondition.java index 7e487fad9e..fcd3f06762 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AbstractNestedCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AbstractNestedCondition.java @@ -159,13 +159,8 @@ public abstract class AbstractNestedCondition extends SpringBootCondition public List getMatchOutcomes() { List outcomes = new ArrayList<>(); - for (Map.Entry> entry : this.memberConditions - .entrySet()) { - AnnotationMetadata metadata = entry.getKey(); - List conditions = entry.getValue(); - outcomes.add(new MemberOutcomes(this.context, metadata, conditions) - .getUltimateOutcome()); - } + this.memberConditions.forEach((metadata, conditions) -> + outcomes.add(new MemberOutcomes(this.context, metadata, conditions).getUltimateOutcome())); return Collections.unmodifiableList(outcomes); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java index 058dee91ec..223c12e006 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -112,13 +113,9 @@ final class BeanTypeRegistry implements SmartInitializingSingleton { */ Set getNamesForType(Class type) { updateTypesIfNecessary(); - Set matches = new LinkedHashSet<>(); - for (Map.Entry> entry : this.beanTypes.entrySet()) { - if (entry.getValue() != null && type.isAssignableFrom(entry.getValue())) { - matches.add(entry.getKey()); - } - } - return matches; + return this.beanTypes.entrySet().stream().filter((entry) -> entry.getValue() != null && + type.isAssignableFrom(entry.getValue())). + map(Map.Entry::getKey).collect(Collectors.toCollection(LinkedHashSet::new)); } /** @@ -132,14 +129,9 @@ final class BeanTypeRegistry implements SmartInitializingSingleton { */ Set getNamesForAnnotation(Class annotation) { updateTypesIfNecessary(); - Set matches = new LinkedHashSet<>(); - for (Map.Entry> entry : this.beanTypes.entrySet()) { - if (entry.getValue() != null && AnnotationUtils - .findAnnotation(entry.getValue(), annotation) != null) { - matches.add(entry.getKey()); - } - } - return matches; + return this.beanTypes.entrySet().stream().filter((entry) -> entry.getValue() != null && + AnnotationUtils.findAnnotation(entry.getValue(), annotation) != null). + map(Map.Entry::getKey).collect(Collectors.toCollection(LinkedHashSet::new)); } @Override diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java index 3ab2d21463..603a2f3ec6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java @@ -24,7 +24,6 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; @@ -112,12 +111,11 @@ public final class ConditionEvaluationReport { */ public Map getConditionAndOutcomesBySource() { if (!this.addedAncestorOutcomes) { - for (Map.Entry entry : this.outcomes - .entrySet()) { - if (!entry.getValue().isFullMatch()) { - addNoMatchOutcomeToAncestors(entry.getKey()); + this.outcomes.forEach((key, value) -> { + if (!value.isFullMatch()) { + addNoMatchOutcomeToAncestors(key); } - } + }); this.addedAncestorOutcomes = true; } return Collections.unmodifiableMap(this.outcomes); @@ -125,13 +123,13 @@ public final class ConditionEvaluationReport { private void addNoMatchOutcomeToAncestors(String source) { String prefix = source + "$"; - for (Entry entry : this.outcomes.entrySet()) { - if (entry.getKey().startsWith(prefix)) { + this.outcomes.forEach((key, value) -> { + if (key.startsWith(prefix)) { ConditionOutcome outcome = ConditionOutcome.noMatch(ConditionMessage .forCondition("Ancestor " + source).because("did not match")); - entry.getValue().add(ANCESTOR_CONDITION, outcome); + value.add(ANCESTOR_CONDITION, outcome); } - } + }); } /** @@ -190,16 +188,15 @@ public final class ConditionEvaluationReport { public ConditionEvaluationReport getDelta(ConditionEvaluationReport previousReport) { ConditionEvaluationReport delta = new ConditionEvaluationReport(); - for (Entry entry : this.outcomes.entrySet()) { - ConditionAndOutcomes previous = previousReport.outcomes.get(entry.getKey()); + this.outcomes.forEach((key, value) -> { + ConditionAndOutcomes previous = previousReport.outcomes.get(key); if (previous == null - || previous.isFullMatch() != entry.getValue().isFullMatch()) { - entry.getValue() - .forEach((conditionAndOutcome) -> delta.recordConditionEvaluation( - entry.getKey(), conditionAndOutcome.getCondition(), + || previous.isFullMatch() != value.isFullMatch()) { + value.forEach((conditionAndOutcome) -> delta.recordConditionEvaluation( + key, conditionAndOutcome.getCondition(), conditionAndOutcome.getOutcome())); } - } + }); List newExclusions = new ArrayList<>(this.exclusions); newExclusions.removeAll(previousReport.getExclusions()); delta.recordExclusions(newExclusions); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java index 03cac0b7be..91232033c8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java @@ -166,18 +166,18 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit private void appendMessageForMatches(StringBuilder reason, Map> matches, String description) { if (!matches.isEmpty()) { - for (Map.Entry> match : matches.entrySet()) { + matches.forEach((key, value) -> { if (reason.length() > 0) { reason.append(" and "); } reason.append("found beans "); reason.append(description); reason.append(" '"); - reason.append(match.getKey()); + reason.append(key); reason.append("' "); reason.append( - StringUtils.collectionToDelimitedString(match.getValue(), ", ")); - } + StringUtils.collectionToDelimitedString(value, ", ")); + }); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java index 876d9744e2..2f696a5308 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style; import org.springframework.context.annotation.Condition; @@ -69,8 +68,8 @@ class OnPropertyCondition extends SpringBootCondition { private List annotationAttributesFromMultiValueMap( MultiValueMap multiValueMap) { List> maps = new ArrayList<>(); - for (Entry> entry : multiValueMap.entrySet()) { - for (int i = 0; i < entry.getValue().size(); i++) { + multiValueMap.forEach((key, value) -> { + for (int i = 0; i < value.size(); i++) { Map map; if (i < maps.size()) { map = maps.get(i); @@ -79,9 +78,9 @@ class OnPropertyCondition extends SpringBootCondition { map = new HashMap<>(); maps.add(map); } - map.put(entry.getKey(), entry.getValue().get(i)); + map.put(key, value.get(i)); } - } + }); List annotationAttributes = new ArrayList<>(maps.size()); for (Map map : maps) { annotationAttributes.add(AnnotationAttributes.fromMap(map)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java index 2847602cd9..7b3f2e0d0c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java @@ -30,7 +30,6 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome; -import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.diagnostics.FailureAnalysis; import org.springframework.boot.diagnostics.analyzer.AbstractInjectionFailureAnalyzer; @@ -124,10 +123,8 @@ class NoSuchBeanDefinitionFailureAnalyzer private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause, List results) { - for (Map.Entry entry : this.report - .getConditionAndOutcomesBySource().entrySet()) { - Source source = new Source(entry.getKey()); - ConditionAndOutcomes conditionAndOutcomes = entry.getValue(); + this.report.getConditionAndOutcomesBySource().forEach((key, conditionAndOutcomes) -> { + Source source = new Source(key); if (!conditionAndOutcomes.isFullMatch()) { BeanMethods methods = new BeanMethods(source, cause); for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) { @@ -139,7 +136,7 @@ class NoSuchBeanDefinitionFailureAnalyzer } } } - } + }); } private void collectExcludedAutoConfiguration(NoSuchBeanDefinitionException cause, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java index 13d750faf6..8152bc82ef 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.jersey; import java.util.Arrays; import java.util.EnumSet; import java.util.List; -import java.util.Map.Entry; import javax.annotation.PostConstruct; import javax.servlet.DispatcherType; @@ -181,9 +180,7 @@ public class JerseyAutoConfiguration implements ServletContextAware { } private void addInitParameters(DynamicRegistrationBean registration) { - for (Entry entry : this.jersey.getInit().entrySet()) { - registration.addInitParameter(entry.getKey(), entry.getValue()); - } + this.jersey.getInit().forEach(registration::addInitParameter); } private static String findApplicationPath(ApplicationPath annotation) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionStoreMappings.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionStoreMappings.java index d9565b564c..41b115202c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionStoreMappings.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionStoreMappings.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.session; import java.util.Collections; import java.util.EnumMap; import java.util.Map; +import java.util.Objects; import org.springframework.boot.WebApplicationType; import org.springframework.util.Assert; @@ -82,18 +83,12 @@ final class SessionStoreMappings { static StoreType getType(WebApplicationType webApplicationType, String configurationClassName) { - for (Map.Entry>> storeEntry : MAPPINGS - .entrySet()) { - for (Map.Entry> entry : storeEntry.getValue() - .entrySet()) { - if (entry.getKey() == webApplicationType - && entry.getValue().getName().equals(configurationClassName)) { - return storeEntry.getKey(); - } - } - } - throw new IllegalStateException( - "Unknown configuration class " + configurationClassName); + return MAPPINGS.entrySet().stream().map(entry -> + entry.getValue().entrySet().stream().filter(webAppEntry -> webAppEntry.getKey() == webApplicationType + && webAppEntry.getValue().getName().equals(configurationClassName)). + map(webAppEntry -> entry.getKey()).findFirst().orElse(null)).filter(Objects::nonNull). + findFirst().orElseThrow(() -> + new IllegalStateException("Unknown configuration class " + configurationClassName)); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java index 26e559353a..03338d2844 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.List; import java.util.ListIterator; import java.util.Map; -import java.util.Map.Entry; import java.util.Optional; import javax.servlet.Servlet; @@ -236,9 +235,7 @@ public class WebMvcAutoConfiguration { } Map mediaTypes = this.mvcProperties.getContentnegotiation() .getMediaTypes(); - for (Entry mediaType : mediaTypes.entrySet()) { - configurer.mediaType(mediaType.getKey(), mediaType.getValue()); - } + mediaTypes.forEach(configurer::mediaType); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java index c4db632cee..a99d6be1f7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.webservices; import java.io.IOException; import java.util.Collections; import java.util.List; -import java.util.Map; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -83,9 +82,7 @@ public class WebServicesAutoConfiguration { servlet, urlMapping); WebServicesProperties.Servlet servletProperties = this.properties.getServlet(); registration.setLoadOnStartup(servletProperties.getLoadOnStartup()); - for (Map.Entry entry : servletProperties.getInit().entrySet()) { - registration.addInitParameter(entry.getKey(), entry.getValue()); - } + servletProperties.getInit().forEach(registration::addInitParameter); return registration; } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java index 697c838ee4..6b3c621abf 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java @@ -20,7 +20,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -423,14 +422,7 @@ class ProjectGenerationRequest { private static void filter(Map projects, String tag, String tagValue) { - for (Iterator> it = projects.entrySet() - .iterator(); it.hasNext();) { - Map.Entry entry = it.next(); - String value = entry.getValue().getTags().get(tag); - if (!tagValue.equals(value)) { - it.remove(); - } - } + projects.entrySet().removeIf((entry) -> !tagValue.equals(entry.getValue().getTags().get(tag))); } } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java index bfcfb806b6..69856d326d 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java @@ -19,7 +19,6 @@ package org.springframework.boot.cli.compiler; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Set; import org.codehaus.groovy.ast.ASTNode; @@ -68,14 +67,8 @@ public abstract class AnnotatedNodeASTTransformation implements ASTTransformatio for (ImportNode importNode : module.getStarImports()) { visitAnnotatedNode(importNode, annotationNodes); } - for (Map.Entry entry : module.getStaticImports() - .entrySet()) { - visitAnnotatedNode(entry.getValue(), annotationNodes); - } - for (Map.Entry entry : module.getStaticStarImports() - .entrySet()) { - visitAnnotatedNode(entry.getValue(), annotationNodes); - } + module.getStaticImports().forEach((key, value) -> visitAnnotatedNode(value, annotationNodes)); + module.getStaticStarImports().forEach((key, value) -> visitAnnotatedNode(value, annotationNodes)); for (ClassNode classNode : module.getClasses()) { visitAnnotatedNode(classNode, annotationNodes); classNode.visitContents(classVisitor); diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/settings/DevToolsSettings.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/settings/DevToolsSettings.java index 27b528ce02..ee924d8461 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/settings/DevToolsSettings.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/settings/DevToolsSettings.java @@ -63,13 +63,13 @@ public class DevToolsSettings { private Map getPatterns(Map properties, String prefix) { Map patterns = new LinkedHashMap<>(); - for (Map.Entry entry : properties.entrySet()) { - String name = String.valueOf(entry.getKey()); + properties.forEach((key, value) -> { + String name = String.valueOf(key); if (name.startsWith(prefix)) { - Pattern pattern = Pattern.compile((String) entry.getValue()); + Pattern pattern = Pattern.compile((String) value); patterns.put(name, pattern); } - } + }); return patterns; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java index aae167b12c..d508cd1e24 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java @@ -18,13 +18,13 @@ package org.springframework.boot.autoconfigureprocessor; import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.RoundEnvironment; @@ -34,7 +34,6 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; -import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; @@ -158,23 +157,19 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor { @SuppressWarnings("unchecked") private List getValues(AnnotationMirror annotation) { - List result = new ArrayList<>(); - for (Map.Entry entry : annotation - .getElementValues().entrySet()) { + return annotation .getElementValues().entrySet().stream().filter(entry -> { String attributeName = entry.getKey().getSimpleName().toString(); - if ("name".equals(attributeName) || "value".equals(attributeName)) { - Object value = entry.getValue().getValue(); - if (value instanceof List) { - for (AnnotationValue annotationValue : (List) value) { - result.add(processValue(annotationValue.getValue())); - } - } - else { - result.add(processValue(value)); - } + return "name".equals(attributeName) || "value".equals(attributeName); + }).map((entry) -> { + Object value = entry.getValue().getValue(); + if (value instanceof List) { + return ((List) value).stream(). + map(annotationValue -> processValue(annotationValue.getValue())).collect(Collectors.toList()); } - } - return result; + else { + return Collections.singletonList(processValue(value)); + } + }).flatMap(List::stream).collect(Collectors.toList()); } private Object processValue(Object value) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SimpleConfigurationMetadataRepository.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SimpleConfigurationMetadataRepository.java index 1f4fde8456..376c18f2dc 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SimpleConfigurationMetadataRepository.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SimpleConfigurationMetadataRepository.java @@ -93,17 +93,9 @@ public class SimpleConfigurationMetadataRepository } else { // Merge properties - for (Map.Entry entry : group - .getProperties().entrySet()) { - putIfAbsent(existingGroup.getProperties(), entry.getKey(), - entry.getValue()); - } + group.getProperties().forEach((key, value) -> putIfAbsent(existingGroup.getProperties(), key, value)); // Merge sources - for (Map.Entry entry : group - .getSources().entrySet()) { - putIfAbsent(existingGroup.getSources(), entry.getKey(), - entry.getValue()); - } + group.getSources().forEach((key, value) -> putIfAbsent(existingGroup.getSources(), key, value)); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java index 0f957f07f6..36b9c5a498 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java @@ -36,7 +36,6 @@ import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.lang.model.SourceVersion; import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -282,10 +281,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor private void processSimpleTypes(String prefix, TypeElement element, ExecutableElement source, TypeElementMembers members, Map fieldValues) { - for (Map.Entry entry : members.getPublicGetters() - .entrySet()) { - String name = entry.getKey(); - ExecutableElement getter = entry.getValue(); + members.getPublicGetters().forEach((name, getter) -> { TypeMirror returnType = getter.getReturnType(); ExecutableElement setter = members.getPublicSetter(name, returnType); VariableElement field = members.getFields().get(name); @@ -305,7 +301,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor dataType, sourceType, null, description, defaultValue, (deprecated ? getItemDeprecation(getter) : null))); } - } + }); } private ItemDeprecation getItemDeprecation(ExecutableElement getter) { @@ -325,11 +321,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor private void processSimpleLombokTypes(String prefix, TypeElement element, ExecutableElement source, TypeElementMembers members, Map fieldValues) { - for (Map.Entry entry : members.getFields().entrySet()) { - String name = entry.getKey(); - VariableElement field = entry.getValue(); + members.getFields().forEach((name, field) -> { if (!isLombokField(field, element)) { - continue; + return; } TypeMirror returnType = field.asType(); Element returnTypeElement = this.processingEnv.getTypeUtils() @@ -348,32 +342,27 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor dataType, sourceType, null, description, defaultValue, (deprecated ? new ItemDeprecation() : null))); } - } + }); } private void processNestedTypes(String prefix, TypeElement element, ExecutableElement source, TypeElementMembers members) { - for (Map.Entry entry : members.getPublicGetters() - .entrySet()) { - String name = entry.getKey(); - ExecutableElement getter = entry.getValue(); + members.getPublicGetters().forEach((name, getter) -> { VariableElement field = members.getFields().get(name); processNestedType(prefix, element, source, name, getter, field, getter.getReturnType()); - } + }); } private void processNestedLombokTypes(String prefix, TypeElement element, ExecutableElement source, TypeElementMembers members) { - for (Map.Entry entry : members.getFields().entrySet()) { - String name = entry.getKey(); - VariableElement field = entry.getValue(); + members.getFields().forEach((name, field) -> { if (isLombokField(field, element)) { ExecutableElement getter = members.getPublicGetter(name, field.asType()); processNestedType(prefix, element, source, name, getter, field, field.asType()); } - } + }); } private boolean isLombokField(VariableElement field, TypeElement element) { @@ -544,11 +533,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor private Map getAnnotationElementValues(AnnotationMirror annotation) { Map values = new LinkedHashMap<>(); - for (Map.Entry entry : annotation - .getElementValues().entrySet()) { - values.put(entry.getKey().getSimpleName().toString(), - entry.getValue().getValue()); - } + annotation.getElementValues().forEach((key, value) -> + values.put(key.getSimpleName().toString(), value.getValue())); return values; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java index 9ad4c78409..b0a4850056 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java @@ -78,13 +78,11 @@ class TypeElementMembers { processField(field); } try { - Map fieldValues = this.fieldValuesParser - .getFieldValues(element); - for (Map.Entry entry : fieldValues.entrySet()) { - if (!this.fieldValues.containsKey(entry.getKey())) { - this.fieldValues.put(entry.getKey(), entry.getValue()); + this.fieldValuesParser.getFieldValues(element).forEach((key, value) -> { + if (!this.fieldValues.containsKey(key)) { + this.fieldValues.put(key, value); } - } + }); } catch (Exception ex) { // continue diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java index 18c4fc0b7b..aea2ee9f71 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java @@ -62,9 +62,7 @@ class TypeUtils { static { Map primitives = new HashMap<>(); - for (Map.Entry> entry : PRIMITIVE_WRAPPERS.entrySet()) { - primitives.put(entry.getValue().getName(), entry.getKey()); - } + PRIMITIVE_WRAPPERS.forEach((key, value) -> primitives.put(value.getName(), key)); WRAPPER_TO_PRIMITIVE = primitives; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java index fe9ee4f32a..ab62014981 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import org.gradle.api.Action; import org.gradle.api.Project; @@ -110,9 +109,7 @@ public class BuildInfo extends ConventionTask { private Map coerceToStringValues(Map input) { Map output = new HashMap<>(); - for (Entry entry : input.entrySet()) { - output.put(entry.getKey(), entry.getValue().toString()); - } + input.forEach((key, value) -> output.put(key, value.toString())); return output; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/BuildPropertiesWriter.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/BuildPropertiesWriter.java index 0f67a72819..5d27ebf910 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/BuildPropertiesWriter.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/BuildPropertiesWriter.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.time.Instant; import java.time.format.DateTimeFormatter; import java.util.Map; -import java.util.Map.Entry; import java.util.Properties; /** @@ -79,10 +78,7 @@ public final class BuildPropertiesWriter { DateTimeFormatter.ISO_INSTANT.format(project.getTime())); } if (project.getAdditionalProperties() != null) { - for (Map.Entry entry : project.getAdditionalProperties() - .entrySet()) { - properties.put("build." + entry.getKey(), entry.getValue()); - } + project.getAdditionalProperties().forEach((key, value) -> properties.put("build." + key, value)); } return properties; } @@ -118,11 +114,11 @@ public final class BuildPropertiesWriter { private static void validateAdditionalProperties( Map additionalProperties) { if (additionalProperties != null) { - for (Entry property : additionalProperties.entrySet()) { - if (property.getValue() == null) { - throw new NullAdditionalPropertyValueException(property.getKey()); + additionalProperties.forEach((key, value) -> { + if (value == null) { + throw new NullAdditionalPropertyValueException(key); } - } + }); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java index 7aadfafe05..1fed749db9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java @@ -19,7 +19,6 @@ package org.springframework.boot.maven; import java.io.IOException; import java.io.InputStream; import java.util.List; -import java.util.Map.Entry; import java.util.Properties; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; @@ -64,13 +63,13 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer Properties properties = new Properties(); properties.load(is); is.close(); - for (Entry entry : properties.entrySet()) { - String name = (String) entry.getKey(); - String value = (String) entry.getValue(); + properties.forEach((key, valueObject) -> { + String name = (String) key; + String value = (String) valueObject; String existing = this.data.getProperty(name); this.data.setProperty(name, existing == null ? value : existing + "," + value); - } + }); } @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java index 774aac3158..e9b5469eb2 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java @@ -140,13 +140,10 @@ public final class Verify { } private ZipEntry getEntryStartingWith(String entryName) { - for (Map.Entry entry : this.content.entrySet()) { - if (entry.getKey().startsWith(entryName)) { - return entry.getValue(); - } - } - throw new IllegalStateException( - "Unable to find entry starting with " + entryName); + return this.content.entrySet().stream(). + filter(entry -> entry.getKey().startsWith(entryName)). + map(Map.Entry::getValue).findFirst().orElseThrow(() -> + new IllegalStateException("Unable to find entry starting with " + entryName)); } public boolean hasEntry(String entry) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java index 36f85681a6..9e8cfeafba 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java @@ -156,12 +156,10 @@ public abstract class LoggingSystem { } return get(classLoader, loggingSystem); } - for (Map.Entry entry : SYSTEMS.entrySet()) { - if (ClassUtils.isPresent(entry.getKey(), classLoader)) { - return get(classLoader, entry.getValue()); - } - } - throw new IllegalStateException("No suitable logging system located"); + return SYSTEMS.entrySet().stream(). + filter((entry) -> ClassUtils.isPresent(entry.getKey(), classLoader)). + map(entry -> get(classLoader, entry.getValue())). + findFirst().orElseThrow(() -> new IllegalStateException("No suitable logging system located")); } private static LoggingSystem get(ClassLoader classLoader, String loggingSystemClass) { From 685babc8295d48710b0c93861ca6b1c3e1a90d8d Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 4 Apr 2018 19:35:41 -0700 Subject: [PATCH 2/2] Polish "Use lambdas for map entry iteration where possible" Closes gh-12626 --- .../condition/ConditionsReportEndpoint.java | 28 +++--- ...CompositeHealthIndicatorConfiguration.java | 5 +- ...eReactiveHealthIndicatorConfiguration.java | 5 +- ...ourceHealthIndicatorAutoConfiguration.java | 8 +- .../boot/actuate/env/EnvironmentEndpoint.java | 11 ++- .../AutoConfigurationSorter.java | 12 +-- ...ImportAutoConfigurationImportSelector.java | 7 +- .../cache/CacheConfigurations.java | 11 ++- .../condition/AbstractNestedCondition.java | 5 +- .../condition/BeanTypeRegistry.java | 16 ++-- .../condition/ConditionEvaluationReport.java | 25 +++--- .../condition/OnBeanCondition.java | 3 +- .../NoSuchBeanDefinitionFailureAnalyzer.java | 33 ++++--- .../session/SessionStoreMappings.java | 89 ++++++++++--------- .../WebServicesAutoConfiguration.java | 2 +- .../init/ProjectGenerationRequest.java | 5 +- .../AnnotatedNodeASTTransformation.java | 8 +- .../devtools/settings/DevToolsSettings.java | 2 +- .../AutoConfigureAnnotationProcessor.java | 37 ++++---- ...SimpleConfigurationMetadataRepository.java | 8 +- ...figurationMetadataAnnotationProcessor.java | 4 +- .../TypeElementMembers.java | 6 +- .../configurationprocessor/TypeUtils.java | 3 +- .../loader/tools/BuildPropertiesWriter.java | 7 +- .../PropertiesMergingResourceTransformer.java | 21 +++-- .../springframework/boot/maven/Verify.java | 9 +- .../boot/logging/LoggingSystem.java | 11 +-- 27 files changed, 207 insertions(+), 174 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java index d4d4be0363..76eb49d505 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java @@ -123,29 +123,21 @@ public class ConditionsReportEndpoint { this.negativeMatches = new LinkedHashMap<>(); this.exclusions = report.getExclusions(); this.unconditionalClasses = report.getUnconditionalClasses(); - report.getConditionAndOutcomesBySource().forEach((key, value) -> { - if (value.isFullMatch()) { - add(this.positiveMatches, key, value); - } - else { - add(this.negativeMatches, key, value); - } - }); + report.getConditionAndOutcomesBySource().forEach( + (source, conditionAndOutcomes) -> add(source, conditionAndOutcomes)); this.parentId = context.getParent() == null ? null : context.getParent().getId(); } - private void add(Map map, String source, - ConditionAndOutcomes conditionAndOutcomes) { + private void add(String source, ConditionAndOutcomes conditionAndOutcomes) { String name = ClassUtils.getShortName(source); - map.put(name, new MessageAndConditions(conditionAndOutcomes)); - } - - private void add(MultiValueMap map, String source, - ConditionAndOutcomes conditionAndOutcomes) { - String name = ClassUtils.getShortName(source); - for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) { - map.add(name, new MessageAndCondition(conditionAndOutcome)); + if (conditionAndOutcomes.isFullMatch()) { + conditionAndOutcomes.forEach((conditionAndOutcome) -> this.positiveMatches + .add(name, new MessageAndCondition(conditionAndOutcome))); + } + else { + this.negativeMatches.put(name, + new MessageAndConditions(conditionAndOutcomes)); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java index c197d4a1a1..e232e7007a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.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. @@ -44,7 +44,8 @@ public abstract class CompositeHealthIndicatorConfiguration composite.addHealthIndicator(key, createHealthIndicator(value))); + beans.forEach((name, source) -> composite.addHealthIndicator(name, + createHealthIndicator(source))); return composite; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java index 00f83d1975..227b2f207a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.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. @@ -43,7 +43,8 @@ public abstract class CompositeReactiveHealthIndicatorConfiguration composite.addHealthIndicator(key, createHealthIndicator(value))); + beans.forEach((name, source) -> composite.addHealthIndicator(name, + createHealthIndicator(source))); return composite; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java index a8112e902c..f09924255b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.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. @@ -84,9 +84,9 @@ public class DataSourceHealthIndicatorAutoConfiguration extends return null; } Map dataSources = new LinkedHashMap<>(); - candidates.forEach((key, value) -> { - if (!(value instanceof AbstractRoutingDataSource)) { - dataSources.put(key, value); + candidates.forEach((name, dataSource) -> { + if (!(dataSource instanceof AbstractRoutingDataSource)) { + dataSources.put(name, dataSource); } }); return dataSources; diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java index e0183282e0..f380cdbddc 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java @@ -120,10 +120,13 @@ public class EnvironmentEndpoint { private PropertySummaryDescriptor getPropertySummaryDescriptor( Map descriptors) { - return descriptors.entrySet().stream(). - filter((entry) -> entry.getValue() != null). - map((entry) -> new PropertySummaryDescriptor(entry.getKey(), entry.getValue().getValue())). - findFirst().orElse(null); + for (Map.Entry entry : descriptors.entrySet()) { + if (entry.getValue() != null) { + return new PropertySummaryDescriptor(entry.getKey(), + entry.getValue().getValue()); + } + } + return null; } private Map getPropertySourceDescriptors( diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java index f883ad891d..d31fbd8a3c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java @@ -140,14 +140,14 @@ class AutoConfigurationSorter { } public Set getClassesRequestedAfter(String className) { - Set rtn = new LinkedHashSet<>(); - rtn.addAll(get(className).getAfter()); - this.classes.forEach((key, value) -> { - if (value.getBefore().contains(className)) { - rtn.add(key); + Set classesRequestedAfter = new LinkedHashSet<>(); + classesRequestedAfter.addAll(get(className).getAfter()); + this.classes.forEach((name, autoConfigurationClass) -> { + if (autoConfigurationClass.getBefore().contains(className)) { + classesRequestedAfter.add(name); } }); - return rtn; + return classesRequestedAfter; } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java index 7e18f430f5..0def58b5c0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.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. @@ -74,9 +74,8 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec AnnotationAttributes attributes) { List candidates = new ArrayList<>(); Map, List> annotations = getAnnotations(metadata); - annotations.forEach((key, value) -> { - collectCandidateConfigurations(key, value, candidates); - }); + annotations.forEach((source, sourceAnnotations) -> collectCandidateConfigurations( + source, sourceAnnotations, candidates)); return candidates; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java index 441dc1170b..22fce136ca 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java @@ -57,10 +57,13 @@ final class CacheConfigurations { } public static CacheType getType(String configurationClassName) { - return MAPPINGS.entrySet().stream().filter((entry) -> - entry.getValue().getName().equals(configurationClassName)). - map(Map.Entry::getKey).findFirst(). - orElseThrow(() -> new IllegalStateException("Unknown configuration class " + configurationClassName)); + for (Map.Entry> entry : MAPPINGS.entrySet()) { + if (entry.getValue().getName().equals(configurationClassName)) { + return entry.getKey(); + } + } + throw new IllegalStateException( + "Unknown configuration class " + configurationClassName); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AbstractNestedCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AbstractNestedCondition.java index fcd3f06762..98ebcdb266 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AbstractNestedCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/AbstractNestedCondition.java @@ -159,8 +159,9 @@ public abstract class AbstractNestedCondition extends SpringBootCondition public List getMatchOutcomes() { List outcomes = new ArrayList<>(); - this.memberConditions.forEach((metadata, conditions) -> - outcomes.add(new MemberOutcomes(this.context, metadata, conditions).getUltimateOutcome())); + this.memberConditions.forEach((metadata, conditions) -> outcomes + .add(new MemberOutcomes(this.context, metadata, conditions) + .getUltimateOutcome())); return Collections.unmodifiableList(outcomes); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java index 223c12e006..6852f79cf9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java @@ -113,9 +113,11 @@ final class BeanTypeRegistry implements SmartInitializingSingleton { */ Set getNamesForType(Class type) { updateTypesIfNecessary(); - return this.beanTypes.entrySet().stream().filter((entry) -> entry.getValue() != null && - type.isAssignableFrom(entry.getValue())). - map(Map.Entry::getKey).collect(Collectors.toCollection(LinkedHashSet::new)); + return this.beanTypes.entrySet().stream() + .filter((entry) -> entry.getValue() != null + && type.isAssignableFrom(entry.getValue())) + .map(Map.Entry::getKey) + .collect(Collectors.toCollection(LinkedHashSet::new)); } /** @@ -129,9 +131,11 @@ final class BeanTypeRegistry implements SmartInitializingSingleton { */ Set getNamesForAnnotation(Class annotation) { updateTypesIfNecessary(); - return this.beanTypes.entrySet().stream().filter((entry) -> entry.getValue() != null && - AnnotationUtils.findAnnotation(entry.getValue(), annotation) != null). - map(Map.Entry::getKey).collect(Collectors.toCollection(LinkedHashSet::new)); + return this.beanTypes.entrySet().stream() + .filter((entry) -> entry.getValue() != null && AnnotationUtils + .findAnnotation(entry.getValue(), annotation) != null) + .map(Map.Entry::getKey) + .collect(Collectors.toCollection(LinkedHashSet::new)); } @Override diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java index 603a2f3ec6..128b7cf399 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.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. @@ -111,9 +111,9 @@ public final class ConditionEvaluationReport { */ public Map getConditionAndOutcomesBySource() { if (!this.addedAncestorOutcomes) { - this.outcomes.forEach((key, value) -> { - if (!value.isFullMatch()) { - addNoMatchOutcomeToAncestors(key); + this.outcomes.forEach((source, sourceOutcomes) -> { + if (!sourceOutcomes.isFullMatch()) { + addNoMatchOutcomeToAncestors(source); } }); this.addedAncestorOutcomes = true; @@ -123,11 +123,11 @@ public final class ConditionEvaluationReport { private void addNoMatchOutcomeToAncestors(String source) { String prefix = source + "$"; - this.outcomes.forEach((key, value) -> { - if (key.startsWith(prefix)) { + this.outcomes.forEach((candidateSource, sourceOutcomes) -> { + if (candidateSource.startsWith(prefix)) { ConditionOutcome outcome = ConditionOutcome.noMatch(ConditionMessage .forCondition("Ancestor " + source).because("did not match")); - value.add(ANCESTOR_CONDITION, outcome); + sourceOutcomes.add(ANCESTOR_CONDITION, outcome); } }); } @@ -188,12 +188,13 @@ public final class ConditionEvaluationReport { public ConditionEvaluationReport getDelta(ConditionEvaluationReport previousReport) { ConditionEvaluationReport delta = new ConditionEvaluationReport(); - this.outcomes.forEach((key, value) -> { - ConditionAndOutcomes previous = previousReport.outcomes.get(key); + this.outcomes.forEach((source, sourceOutcomes) -> { + ConditionAndOutcomes previous = previousReport.outcomes.get(source); if (previous == null - || previous.isFullMatch() != value.isFullMatch()) { - value.forEach((conditionAndOutcome) -> delta.recordConditionEvaluation( - key, conditionAndOutcome.getCondition(), + || previous.isFullMatch() != sourceOutcomes.isFullMatch()) { + sourceOutcomes.forEach( + (conditionAndOutcome) -> delta.recordConditionEvaluation(source, + conditionAndOutcome.getCondition(), conditionAndOutcome.getOutcome())); } }); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java index 91232033c8..5b0573ae4a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java @@ -175,8 +175,7 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit reason.append(" '"); reason.append(key); reason.append("' "); - reason.append( - StringUtils.collectionToDelimitedString(value, ", ")); + reason.append(StringUtils.collectionToDelimitedString(value, ", ")); }); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java index 7b3f2e0d0c..aae26aa7d6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.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. @@ -30,6 +30,7 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome; +import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.diagnostics.FailureAnalysis; import org.springframework.boot.diagnostics.analyzer.AbstractInjectionFailureAnalyzer; @@ -123,20 +124,26 @@ class NoSuchBeanDefinitionFailureAnalyzer private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause, List results) { - this.report.getConditionAndOutcomesBySource().forEach((key, conditionAndOutcomes) -> { - Source source = new Source(key); - if (!conditionAndOutcomes.isFullMatch()) { - BeanMethods methods = new BeanMethods(source, cause); - for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) { - if (!conditionAndOutcome.getOutcome().isMatch()) { - for (MethodMetadata method : methods) { - results.add(new AutoConfigurationResult(method, - conditionAndOutcome.getOutcome(), source.isMethod())); - } - } + this.report.getConditionAndOutcomesBySource().forEach( + (source, sourceOutcomes) -> collectReportedConditionOutcomes(cause, + new Source(source), sourceOutcomes, results)); + } + + private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause, + Source source, ConditionAndOutcomes sourceOutcomes, + List results) { + if (sourceOutcomes.isFullMatch()) { + return; + } + BeanMethods methods = new BeanMethods(source, cause); + for (ConditionAndOutcome conditionAndOutcome : sourceOutcomes) { + if (!conditionAndOutcome.getOutcome().isMatch()) { + for (MethodMetadata method : methods) { + results.add(new AutoConfigurationResult(method, + conditionAndOutcome.getOutcome(), source.isMethod())); } } - }); + } } private void collectExcludedAutoConfiguration(NoSuchBeanDefinitionException cause, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionStoreMappings.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionStoreMappings.java index 41b115202c..cc75016040 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionStoreMappings.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionStoreMappings.java @@ -19,10 +19,10 @@ package org.springframework.boot.autoconfigure.session; import java.util.Collections; import java.util.EnumMap; import java.util.Map; -import java.util.Objects; import org.springframework.boot.WebApplicationType; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; /** * Mappings between {@link StoreType} and {@code @Configuration}. @@ -32,63 +32,70 @@ import org.springframework.util.Assert; */ final class SessionStoreMappings { - private static final Map>> MAPPINGS; + private static final Map MAPPINGS; static { - Map>> mappings = new EnumMap<>( - StoreType.class); - mappings.put(StoreType.REDIS, createMapping(RedisSessionConfiguration.class, + Map mappings = new EnumMap<>(StoreType.class); + mappings.put(StoreType.REDIS, new Configurations(RedisSessionConfiguration.class, RedisReactiveSessionConfiguration.class)); - mappings.put(StoreType.MONGODB, createMapping(MongoSessionConfiguration.class, - MongoReactiveSessionConfiguration.class)); - mappings.put(StoreType.JDBC, createMapping(JdbcSessionConfiguration.class)); + mappings.put(StoreType.MONGODB, + new Configurations(MongoSessionConfiguration.class, + MongoReactiveSessionConfiguration.class)); + mappings.put(StoreType.JDBC, + new Configurations(JdbcSessionConfiguration.class, null)); mappings.put(StoreType.HAZELCAST, - createMapping(HazelcastSessionConfiguration.class)); - mappings.put(StoreType.NONE, createMapping(NoOpSessionConfiguration.class, + new Configurations(HazelcastSessionConfiguration.class, null)); + mappings.put(StoreType.NONE, new Configurations(NoOpSessionConfiguration.class, NoOpReactiveSessionConfiguration.class)); MAPPINGS = Collections.unmodifiableMap(mappings); } - static Map> createMapping( - Class servletConfiguration) { - return createMapping(servletConfiguration, null); + private SessionStoreMappings() { } - static Map> createMapping(Class servletConfiguration, - Class reactiveConfiguration) { - Map> mapping = new EnumMap<>( - WebApplicationType.class); - mapping.put(WebApplicationType.SERVLET, servletConfiguration); - if (reactiveConfiguration != null) { - mapping.put(WebApplicationType.REACTIVE, reactiveConfiguration); - } - return mapping; + public static String getConfigurationClass(WebApplicationType webApplicationType, + StoreType sessionStoreType) { + Configurations configurations = MAPPINGS.get(sessionStoreType); + Assert.state(configurations != null, + () -> "Unknown session store type " + sessionStoreType); + return configurations.getConfiguration(webApplicationType); } - private SessionStoreMappings() { + public static StoreType getType(WebApplicationType webApplicationType, + String configurationClass) { + return MAPPINGS.entrySet().stream() + .filter((entry) -> ObjectUtils.nullSafeEquals(configurationClass, + entry.getValue().getConfiguration(webApplicationType))) + .map(Map.Entry::getKey).findFirst() + .orElseThrow(() -> new IllegalStateException( + "Unknown configuration class " + configurationClass)); } - static String getConfigurationClass(WebApplicationType webApplicationType, - StoreType sessionStoreType) { - Map> configurationClasses = MAPPINGS - .get(sessionStoreType); - Assert.state(configurationClasses != null, - () -> "Unknown session store type " + sessionStoreType); - Class configurationClass = configurationClasses.get(webApplicationType); - if (configurationClass == null) { + private static class Configurations { + + private final Class servletConfiguration; + + private final Class reactiveConfiguration; + + Configurations(Class servletConfiguration, Class reactiveConfiguration) { + this.servletConfiguration = servletConfiguration; + this.reactiveConfiguration = reactiveConfiguration; + } + + public String getConfiguration(WebApplicationType webApplicationType) { + switch (webApplicationType) { + case SERVLET: + return getName(this.servletConfiguration); + case REACTIVE: + return getName(this.reactiveConfiguration); + } return null; } - return configurationClass.getName(); - } - static StoreType getType(WebApplicationType webApplicationType, - String configurationClassName) { - return MAPPINGS.entrySet().stream().map(entry -> - entry.getValue().entrySet().stream().filter(webAppEntry -> webAppEntry.getKey() == webApplicationType - && webAppEntry.getValue().getName().equals(configurationClassName)). - map(webAppEntry -> entry.getKey()).findFirst().orElse(null)).filter(Objects::nonNull). - findFirst().orElseThrow(() -> - new IllegalStateException("Unknown configuration class " + configurationClassName)); + private String getName(Class configuration) { + return (configuration == null ? null : configuration.getName()); + } + } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java index a99d6be1f7..3e5e426cc6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.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-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java index 6b3c621abf..aaa394a600 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerationRequest.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. @@ -422,7 +422,8 @@ class ProjectGenerationRequest { private static void filter(Map projects, String tag, String tagValue) { - projects.entrySet().removeIf((entry) -> !tagValue.equals(entry.getValue().getTags().get(tag))); + projects.entrySet().removeIf( + (entry) -> !tagValue.equals(entry.getValue().getTags().get(tag))); } } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java index 69856d326d..1e5b708e68 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.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. @@ -67,8 +67,10 @@ public abstract class AnnotatedNodeASTTransformation implements ASTTransformatio for (ImportNode importNode : module.getStarImports()) { visitAnnotatedNode(importNode, annotationNodes); } - module.getStaticImports().forEach((key, value) -> visitAnnotatedNode(value, annotationNodes)); - module.getStaticStarImports().forEach((key, value) -> visitAnnotatedNode(value, annotationNodes)); + module.getStaticImports().forEach((name, + importNode) -> visitAnnotatedNode(importNode, annotationNodes)); + module.getStaticStarImports().forEach((name, + importNode) -> visitAnnotatedNode(importNode, annotationNodes)); for (ClassNode classNode : module.getClasses()) { visitAnnotatedNode(classNode, annotationNodes); classNode.visitContents(classVisitor); diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/settings/DevToolsSettings.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/settings/DevToolsSettings.java index ee924d8461..e21cacfa16 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/settings/DevToolsSettings.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/settings/DevToolsSettings.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-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java index d508cd1e24..d3d06890f8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.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. @@ -22,9 +22,11 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.RoundEnvironment; @@ -34,6 +36,7 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; @@ -155,21 +158,25 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor { return result.toString(); } - @SuppressWarnings("unchecked") private List getValues(AnnotationMirror annotation) { - return annotation .getElementValues().entrySet().stream().filter(entry -> { - String attributeName = entry.getKey().getSimpleName().toString(); - return "name".equals(attributeName) || "value".equals(attributeName); - }).map((entry) -> { - Object value = entry.getValue().getValue(); - if (value instanceof List) { - return ((List) value).stream(). - map(annotationValue -> processValue(annotationValue.getValue())).collect(Collectors.toList()); - } - else { - return Collections.singletonList(processValue(value)); - } - }).flatMap(List::stream).collect(Collectors.toList()); + return annotation.getElementValues().entrySet().stream() + .filter(this::isNameOrValueAttribute).flatMap(this::getValues) + .collect(Collectors.toList()); + } + + private boolean isNameOrValueAttribute(Entry entry) { + String attributeName = entry.getKey().getSimpleName().toString(); + return "name".equals(attributeName) || "value".equals(attributeName); + } + + @SuppressWarnings("unchecked") + private Stream getValues(Entry entry) { + Object value = entry.getValue().getValue(); + if (value instanceof List) { + return ((List) value).stream() + .map((annotation) -> processValue(annotation.getValue())); + } + return Stream.of(processValue(value)); } private Object processValue(Object value) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SimpleConfigurationMetadataRepository.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SimpleConfigurationMetadataRepository.java index 376c18f2dc..3126338c8b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SimpleConfigurationMetadataRepository.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/SimpleConfigurationMetadataRepository.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. @@ -93,9 +93,11 @@ public class SimpleConfigurationMetadataRepository } else { // Merge properties - group.getProperties().forEach((key, value) -> putIfAbsent(existingGroup.getProperties(), key, value)); + group.getProperties().forEach((name, value) -> putIfAbsent( + existingGroup.getProperties(), name, value)); // Merge sources - group.getSources().forEach((key, value) -> putIfAbsent(existingGroup.getSources(), key, value)); + group.getSources().forEach((name, + value) -> putIfAbsent(existingGroup.getSources(), name, value)); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java index 36b9c5a498..5335de06a5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java @@ -533,8 +533,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor private Map getAnnotationElementValues(AnnotationMirror annotation) { Map values = new LinkedHashMap<>(); - annotation.getElementValues().forEach((key, value) -> - values.put(key.getSimpleName().toString(), value.getValue())); + annotation.getElementValues().forEach((name, value) -> values + .put(name.getSimpleName().toString(), value.getValue())); return values; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java index b0a4850056..b78fbc1074 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java @@ -78,9 +78,9 @@ class TypeElementMembers { processField(field); } try { - this.fieldValuesParser.getFieldValues(element).forEach((key, value) -> { - if (!this.fieldValues.containsKey(key)) { - this.fieldValues.put(key, value); + this.fieldValuesParser.getFieldValues(element).forEach((name, value) -> { + if (!this.fieldValues.containsKey(name)) { + this.fieldValues.put(name, value); } }); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java index aea2ee9f71..45b1d3bfd6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java @@ -62,7 +62,8 @@ class TypeUtils { static { Map primitives = new HashMap<>(); - PRIMITIVE_WRAPPERS.forEach((key, value) -> primitives.put(value.getName(), key)); + PRIMITIVE_WRAPPERS.forEach( + (kind, wrapperClass) -> primitives.put(wrapperClass.getName(), kind)); WRAPPER_TO_PRIMITIVE = primitives; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/BuildPropertiesWriter.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/BuildPropertiesWriter.java index 5d27ebf910..1d8d97d475 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/BuildPropertiesWriter.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/BuildPropertiesWriter.java @@ -78,7 +78,8 @@ public final class BuildPropertiesWriter { DateTimeFormatter.ISO_INSTANT.format(project.getTime())); } if (project.getAdditionalProperties() != null) { - project.getAdditionalProperties().forEach((key, value) -> properties.put("build." + key, value)); + project.getAdditionalProperties() + .forEach((name, value) -> properties.put("build." + name, value)); } return properties; } @@ -114,9 +115,9 @@ public final class BuildPropertiesWriter { private static void validateAdditionalProperties( Map additionalProperties) { if (additionalProperties != null) { - additionalProperties.forEach((key, value) -> { + additionalProperties.forEach((name, value) -> { if (value == null) { - throw new NullAdditionalPropertyValueException(key); + throw new NullAdditionalPropertyValueException(name); } }); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java index 1fed749db9..c617375d64 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.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. @@ -58,18 +58,17 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer } @Override - public void processResource(String resource, InputStream is, + public void processResource(String resource, InputStream inputStream, List relocators) throws IOException { Properties properties = new Properties(); - properties.load(is); - is.close(); - properties.forEach((key, valueObject) -> { - String name = (String) key; - String value = (String) valueObject; - String existing = this.data.getProperty(name); - this.data.setProperty(name, - existing == null ? value : existing + "," + value); - }); + properties.load(inputStream); + inputStream.close(); + properties.forEach((name, value) -> process((String) name, (String) value)); + } + + private void process(String name, String value) { + String existing = this.data.getProperty(name); + this.data.setProperty(name, (existing == null ? value : existing + "," + value)); } @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java index e9b5469eb2..98111f0994 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java @@ -140,10 +140,11 @@ public final class Verify { } private ZipEntry getEntryStartingWith(String entryName) { - return this.content.entrySet().stream(). - filter(entry -> entry.getKey().startsWith(entryName)). - map(Map.Entry::getValue).findFirst().orElseThrow(() -> - new IllegalStateException("Unable to find entry starting with " + entryName)); + return this.content.entrySet().stream() + .filter(entry -> entry.getKey().startsWith(entryName)) + .map(Map.Entry::getValue).findFirst() + .orElseThrow(() -> new IllegalStateException( + "Unable to find entry starting with " + entryName)); } public boolean hasEntry(String entry) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java index 9e8cfeafba..69bedccc46 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.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. @@ -156,10 +156,11 @@ public abstract class LoggingSystem { } return get(classLoader, loggingSystem); } - return SYSTEMS.entrySet().stream(). - filter((entry) -> ClassUtils.isPresent(entry.getKey(), classLoader)). - map(entry -> get(classLoader, entry.getValue())). - findFirst().orElseThrow(() -> new IllegalStateException("No suitable logging system located")); + return SYSTEMS.entrySet().stream() + .filter((entry) -> ClassUtils.isPresent(entry.getKey(), classLoader)) + .map((entry) -> get(classLoader, entry.getValue())).findFirst() + .orElseThrow(() -> new IllegalStateException( + "No suitable logging system located")); } private static LoggingSystem get(ClassLoader classLoader, String loggingSystemClass) {