From be837ccb4bcf7ebd32b21e810c88db88a6bf2e8e Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Fri, 6 Jul 2018 23:14:42 +0200 Subject: [PATCH] Use PropertySources.stream() where possible Closes gh-13724 --- .../EnvironmentEndpointDocumentationTests.java | 4 +--- .../context/properties/CompositePropertySources.java | 6 ++---- .../boot/context/properties/FilteredPropertySources.java | 6 ++---- .../properties/source/ConfigurationPropertySources.java | 7 +++---- ...InvalidConfigurationPropertyValueFailureAnalyzer.java | 9 ++++----- .../SpringApplicationJsonEnvironmentPostProcessor.java | 6 ++---- 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/EnvironmentEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/EnvironmentEndpointDocumentationTests.java index c6452af10d..59b3bf677c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/EnvironmentEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/EnvironmentEndpointDocumentationTests.java @@ -22,7 +22,6 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -156,8 +155,7 @@ public class EnvironmentEndpointDocumentationTests @Override protected void customizePropertySources( MutablePropertySources propertySources) { - StreamSupport - .stream(environment.getPropertySources().spliterator(), false) + environment.getPropertySources().stream() .filter(this::includedPropertySource) .forEach(propertySources::addLast); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/CompositePropertySources.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/CompositePropertySources.java index b7e416430f..645c9aa20a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/CompositePropertySources.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/CompositePropertySources.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. @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySources; @@ -42,8 +41,7 @@ final class CompositePropertySources implements PropertySources { @Override public Iterator> iterator() { - return this.propertySources.stream() - .flatMap((sources) -> StreamSupport.stream(sources.spliterator(), false)) + return this.propertySources.stream().flatMap(PropertySources::stream) .collect(Collectors.toList()).iterator(); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/FilteredPropertySources.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/FilteredPropertySources.java index b213f5cf21..56f54fddb0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/FilteredPropertySources.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/FilteredPropertySources.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. @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import java.util.stream.StreamSupport; import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySources; @@ -59,8 +58,7 @@ final class FilteredPropertySources implements PropertySources { @Override public Iterator> iterator() { - return StreamSupport.stream(this.delegate.spliterator(), false) - .filter(this::included).iterator(); + return this.delegate.stream().filter(this::included).iterator(); } private boolean included(PropertySource propertySource) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertySources.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertySources.java index 23ef8b3915..8168aed508 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertySources.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertySources.java @@ -18,13 +18,13 @@ package org.springframework.boot.context.properties.source; import java.util.Collections; import java.util.stream.Stream; -import java.util.stream.StreamSupport; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource.StubPropertySource; +import org.springframework.core.env.PropertySources; import org.springframework.core.env.PropertySourcesPropertyResolver; import org.springframework.util.Assert; @@ -136,9 +136,8 @@ public final class ConfigurationPropertySources { } private static Stream> streamPropertySources( - Iterable> sources) { - return StreamSupport.stream(sources.spliterator(), false) - .flatMap(ConfigurationPropertySources::flatten) + PropertySources sources) { + return sources.stream().flatMap(ConfigurationPropertySources::flatten) .filter(ConfigurationPropertySources::isIncluded); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java index b58b1aeee1..ade8e65ff9 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java @@ -16,11 +16,9 @@ package org.springframework.boot.diagnostics.analyzer; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.stream.StreamSupport; import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException; @@ -74,9 +72,10 @@ class InvalidConfigurationPropertyValueFailureAnalyzer } private Stream> getPropertySources() { - Iterable> sources = (this.environment != null - ? this.environment.getPropertySources() : Collections.emptyList()); - return StreamSupport.stream(sources.spliterator(), false) + if (this.environment == null) { + return Stream.empty(); + } + return this.environment.getPropertySources().stream() .filter((source) -> !ConfigurationPropertySources .isAttachedConfigurationPropertySource(source)); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java index afff3dc634..7f412ebba9 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java @@ -20,7 +20,6 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; -import java.util.stream.StreamSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -92,9 +91,8 @@ public class SpringApplicationJsonEnvironmentPostProcessor public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { MutablePropertySources propertySources = environment.getPropertySources(); - StreamSupport.stream(propertySources.spliterator(), false) - .map(JsonPropertyValue::get).filter(Objects::nonNull).findFirst() - .ifPresent((v) -> processJson(environment, v)); + propertySources.stream().map(JsonPropertyValue::get).filter(Objects::nonNull) + .findFirst().ifPresent((v) -> processJson(environment, v)); } private void processJson(ConfigurableEnvironment environment,