Skip to content

Commit cc6cf88

Browse files
committed
Stop using ObjectProvider<List> and ObjectProvider<Collection>
Closes gh-14467
1 parent 5323095 commit cc6cf88

File tree

43 files changed

+245
-330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+245
-330
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.endpoint.jmx;
1818

19-
import java.util.Collection;
20-
import java.util.Collections;
19+
import java.util.stream.Collectors;
2120

2221
import javax.management.MBeanServer;
2322

@@ -75,11 +74,11 @@ public JmxEndpointAutoConfiguration(ApplicationContext applicationContext,
7574
@ConditionalOnMissingBean(JmxEndpointsSupplier.class)
7675
public JmxEndpointDiscoverer jmxAnnotationEndpointDiscoverer(
7776
ParameterValueMapper parameterValueMapper,
78-
ObjectProvider<Collection<OperationInvokerAdvisor>> invokerAdvisors,
79-
ObjectProvider<Collection<EndpointFilter<ExposableJmxEndpoint>>> filters) {
77+
ObjectProvider<OperationInvokerAdvisor> invokerAdvisors,
78+
ObjectProvider<EndpointFilter<ExposableJmxEndpoint>> filters) {
8079
return new JmxEndpointDiscoverer(this.applicationContext, parameterValueMapper,
81-
invokerAdvisors.getIfAvailable(Collections::emptyList),
82-
filters.getIfAvailable(Collections::emptyList));
80+
invokerAdvisors.orderedStream().collect(Collectors.toList()),
81+
filters.orderedStream().collect(Collectors.toList()));
8382
}
8483

8584
@Bean

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collection;
2121
import java.util.Collections;
2222
import java.util.List;
23+
import java.util.stream.Collectors;
2324

2425
import org.springframework.beans.factory.ObjectProvider;
2526
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
@@ -95,12 +96,12 @@ public EndpointMediaTypes endpointMediaTypes() {
9596
public WebEndpointDiscoverer webEndpointDiscoverer(
9697
ParameterValueMapper parameterValueMapper,
9798
EndpointMediaTypes endpointMediaTypes, PathMapper webEndpointPathMapper,
98-
ObjectProvider<Collection<OperationInvokerAdvisor>> invokerAdvisors,
99-
ObjectProvider<Collection<EndpointFilter<ExposableWebEndpoint>>> filters) {
99+
ObjectProvider<OperationInvokerAdvisor> invokerAdvisors,
100+
ObjectProvider<EndpointFilter<ExposableWebEndpoint>> filters) {
100101
return new WebEndpointDiscoverer(this.applicationContext, parameterValueMapper,
101102
endpointMediaTypes, webEndpointPathMapper,
102-
invokerAdvisors.getIfAvailable(Collections::emptyList),
103-
filters.getIfAvailable(Collections::emptyList));
103+
invokerAdvisors.orderedStream().collect(Collectors.toList()),
104+
filters.orderedStream().collect(Collectors.toList()));
104105
}
105106

106107
@Bean
@@ -144,10 +145,10 @@ static class WebEndpointServletConfiguration {
144145
@ConditionalOnMissingBean(ServletEndpointsSupplier.class)
145146
public ServletEndpointDiscoverer servletEndpointDiscoverer(
146147
ApplicationContext applicationContext, PathMapper webEndpointPathMapper,
147-
ObjectProvider<Collection<EndpointFilter<ExposableServletEndpoint>>> filters) {
148+
ObjectProvider<EndpointFilter<ExposableServletEndpoint>> filters) {
148149
return new ServletEndpointDiscoverer(applicationContext,
149150
webEndpointPathMapper,
150-
filters.getIfAvailable(Collections::emptyList));
151+
filters.orderedStream().collect(Collectors.toList()));
151152
}
152153

153154
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.info;
1818

19-
import java.util.Collections;
20-
import java.util.List;
19+
import java.util.stream.Collectors;
2120

2221
import org.springframework.beans.factory.ObjectProvider;
2322
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
@@ -42,9 +41,9 @@ public class InfoEndpointAutoConfiguration {
4241
@Bean
4342
@ConditionalOnMissingBean
4443
@ConditionalOnEnabledEndpoint
45-
public InfoEndpoint infoEndpoint(
46-
ObjectProvider<List<InfoContributor>> infoContributors) {
47-
return new InfoEndpoint(infoContributors.getIfAvailable(Collections::emptyList));
44+
public InfoEndpoint infoEndpoint(ObjectProvider<InfoContributor> infoContributors) {
45+
return new InfoEndpoint(
46+
infoContributors.orderedStream().collect(Collectors.toList()));
4847
}
4948

5049
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Collection;
2020
import java.util.LinkedHashMap;
2121
import java.util.Map;
22+
import java.util.stream.Collectors;
2223

2324
import javax.sql.DataSource;
2425

@@ -73,9 +74,10 @@ public class DataSourceHealthIndicatorAutoConfiguration extends
7374

7475
public DataSourceHealthIndicatorAutoConfiguration(
7576
ObjectProvider<Map<String, DataSource>> dataSources,
76-
ObjectProvider<Collection<DataSourcePoolMetadataProvider>> metadataProviders) {
77+
ObjectProvider<DataSourcePoolMetadataProvider> metadataProviders) {
7778
this.dataSources = filterDataSources(dataSources.getIfAvailable());
78-
this.metadataProviders = metadataProviders.getIfAvailable();
79+
this.metadataProviders = metadataProviders.orderedStream()
80+
.collect(Collectors.toList());
7981
}
8082

8183
private Map<String, DataSource> filterDataSources(

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/scheduling/ScheduledTasksEndpointAutoConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.scheduling;
1818

19-
import java.util.Collections;
20-
import java.util.List;
19+
import java.util.stream.Collectors;
2120

2221
import org.springframework.beans.factory.ObjectProvider;
2322
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
@@ -41,8 +40,9 @@ public class ScheduledTasksEndpointAutoConfiguration {
4140
@ConditionalOnMissingBean
4241
@ConditionalOnEnabledEndpoint
4342
public ScheduledTasksEndpoint scheduledTasksEndpoint(
44-
ObjectProvider<List<ScheduledTaskHolder>> holders) {
45-
return new ScheduledTasksEndpoint(holders.getIfAvailable(Collections::emptyList));
43+
ObjectProvider<ScheduledTaskHolder> holders) {
44+
return new ScheduledTasksEndpoint(
45+
holders.orderedStream().collect(Collectors.toList()));
4646
}
4747

4848
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementChildContextConfiguration.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.web.jersey;
1818

19-
import java.util.Collections;
20-
import java.util.List;
19+
import java.util.stream.Stream;
2120

2221
import org.glassfish.jersey.server.ResourceConfig;
2322
import org.glassfish.jersey.servlet.ServletContainer;
@@ -48,12 +47,11 @@
4847
@ConditionalOnMissingClass("org.springframework.web.servlet.DispatcherServlet")
4948
public class JerseyManagementChildContextConfiguration {
5049

51-
private final List<ResourceConfigCustomizer> resourceConfigCustomizers;
50+
private final Stream<ResourceConfigCustomizer> resourceConfigCustomizers;
5251

5352
public JerseyManagementChildContextConfiguration(
54-
ObjectProvider<List<ResourceConfigCustomizer>> resourceConfigCustomizers) {
55-
this.resourceConfigCustomizers = resourceConfigCustomizers
56-
.getIfAvailable(Collections::emptyList);
53+
ObjectProvider<ResourceConfigCustomizer> resourceConfigCustomizers) {
54+
this.resourceConfigCustomizers = resourceConfigCustomizers.orderedStream();
5755
}
5856

5957
@Bean
@@ -65,9 +63,8 @@ public ServletRegistrationBean<ServletContainer> jerseyServletRegistration() {
6563
@Bean
6664
public ResourceConfig endpointResourceConfig() {
6765
ResourceConfig resourceConfig = new ResourceConfig();
68-
for (ResourceConfigCustomizer customizer : this.resourceConfigCustomizers) {
69-
customizer.customize(resourceConfig);
70-
}
66+
this.resourceConfigCustomizers
67+
.forEach((customizer) -> customizer.customize(resourceConfig));
7168
return resourceConfig;
7269
}
7370

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.web.mappings;
1818

19-
import java.util.Collection;
20-
import java.util.Collections;
19+
import java.util.stream.Collectors;
2120

2221
import org.springframework.beans.factory.ObjectProvider;
2322
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
@@ -50,9 +49,9 @@ public class MappingsEndpointAutoConfiguration {
5049
@Bean
5150
@ConditionalOnEnabledEndpoint
5251
public MappingsEndpoint mappingsEndpoint(ApplicationContext applicationContext,
53-
ObjectProvider<Collection<MappingDescriptionProvider>> descriptionProviders) {
52+
ObjectProvider<MappingDescriptionProvider> descriptionProviders) {
5453
return new MappingsEndpoint(
55-
descriptionProviders.getIfAvailable(Collections::emptyList),
54+
descriptionProviders.orderedStream().collect(Collectors.toList()),
5655
applicationContext);
5756
}
5857

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.boot.autoconfigure.admin;
1818

19-
import java.util.List;
20-
2119
import javax.management.MalformedObjectNameException;
2220

2321
import org.springframework.beans.factory.ObjectProvider;
@@ -57,13 +55,13 @@ public class SpringApplicationAdminJmxAutoConfiguration {
5755
*/
5856
private static final String DEFAULT_JMX_NAME = "org.springframework.boot:type=Admin,name=SpringApplication";
5957

60-
private final List<MBeanExporter> mbeanExporters;
58+
private final Iterable<MBeanExporter> mbeanExporters;
6159

6260
private final Environment environment;
6361

6462
public SpringApplicationAdminJmxAutoConfiguration(
65-
ObjectProvider<List<MBeanExporter>> mbeanExporters, Environment environment) {
66-
this.mbeanExporters = mbeanExporters.getIfAvailable();
63+
ObjectProvider<MBeanExporter> mbeanExporters, Environment environment) {
64+
this.mbeanExporters = mbeanExporters;
6765
this.environment = environment;
6866
}
6967

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAnnotationDrivenConfiguration.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.amqp;
1818

19-
import java.util.List;
19+
import java.util.stream.Collectors;
2020

2121
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
2222
import org.springframework.amqp.rabbit.config.DirectRabbitListenerContainerFactory;
@@ -47,13 +47,13 @@ class RabbitAnnotationDrivenConfiguration {
4747

4848
private final ObjectProvider<MessageRecoverer> messageRecoverer;
4949

50-
private final ObjectProvider<List<RabbitRetryTemplateCustomizer>> retryTemplateCustomizers;
50+
private final ObjectProvider<RabbitRetryTemplateCustomizer> retryTemplateCustomizers;
5151

5252
private final RabbitProperties properties;
5353

5454
RabbitAnnotationDrivenConfiguration(ObjectProvider<MessageConverter> messageConverter,
5555
ObjectProvider<MessageRecoverer> messageRecoverer,
56-
ObjectProvider<List<RabbitRetryTemplateCustomizer>> retryTemplateCustomizers,
56+
ObjectProvider<RabbitRetryTemplateCustomizer> retryTemplateCustomizers,
5757
RabbitProperties properties) {
5858
this.messageConverter = messageConverter;
5959
this.messageRecoverer = messageRecoverer;
@@ -67,8 +67,8 @@ public SimpleRabbitListenerContainerFactoryConfigurer simpleRabbitListenerContai
6767
SimpleRabbitListenerContainerFactoryConfigurer configurer = new SimpleRabbitListenerContainerFactoryConfigurer();
6868
configurer.setMessageConverter(this.messageConverter.getIfUnique());
6969
configurer.setMessageRecoverer(this.messageRecoverer.getIfUnique());
70-
configurer.setRetryTemplateCustomizers(
71-
this.retryTemplateCustomizers.getIfAvailable());
70+
configurer.setRetryTemplateCustomizers(this.retryTemplateCustomizers
71+
.orderedStream().collect(Collectors.toList()));
7272
configurer.setRabbitProperties(this.properties);
7373
return configurer;
7474
}
@@ -90,8 +90,8 @@ public DirectRabbitListenerContainerFactoryConfigurer directRabbitListenerContai
9090
DirectRabbitListenerContainerFactoryConfigurer configurer = new DirectRabbitListenerContainerFactoryConfigurer();
9191
configurer.setMessageConverter(this.messageConverter.getIfUnique());
9292
configurer.setMessageRecoverer(this.messageRecoverer.getIfUnique());
93-
configurer.setRetryTemplateCustomizers(
94-
this.retryTemplateCustomizers.getIfAvailable());
93+
configurer.setRetryTemplateCustomizers(this.retryTemplateCustomizers
94+
.orderedStream().collect(Collectors.toList()));
9595
configurer.setRabbitProperties(this.properties);
9696
return configurer;
9797
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.boot.autoconfigure.amqp;
1818

1919
import java.time.Duration;
20-
import java.util.List;
20+
import java.util.stream.Collectors;
2121

2222
import com.rabbitmq.client.Channel;
2323

@@ -161,11 +161,11 @@ protected static class RabbitTemplateConfiguration {
161161

162162
private final ObjectProvider<MessageConverter> messageConverter;
163163

164-
private final ObjectProvider<List<RabbitRetryTemplateCustomizer>> retryTemplateCustomizers;
164+
private final ObjectProvider<RabbitRetryTemplateCustomizer> retryTemplateCustomizers;
165165

166166
public RabbitTemplateConfiguration(RabbitProperties properties,
167167
ObjectProvider<MessageConverter> messageConverter,
168-
ObjectProvider<List<RabbitRetryTemplateCustomizer>> retryTemplateCustomizers) {
168+
ObjectProvider<RabbitRetryTemplateCustomizer> retryTemplateCustomizers) {
169169
this.properties = properties;
170170
this.messageConverter = messageConverter;
171171
this.retryTemplateCustomizers = retryTemplateCustomizers;
@@ -185,8 +185,9 @@ public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
185185
RabbitProperties.Template properties = this.properties.getTemplate();
186186
if (properties.getRetry().isEnabled()) {
187187
template.setRetryTemplate(new RetryTemplateFactory(
188-
this.retryTemplateCustomizers.getIfAvailable())
189-
.createRetryTemplate(properties.getRetry(),
188+
this.retryTemplateCustomizers.orderedStream()
189+
.collect(Collectors.toList())).createRetryTemplate(
190+
properties.getRetry(),
190191
RabbitRetryTemplateCustomizer.Target.SENDER));
191192
}
192193
map.from(properties::getReceiveTimeout).whenNonNull().as(Duration::toMillis)

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.cache;
1818

19-
import java.util.List;
19+
import java.util.stream.Collectors;
2020

2121
import org.springframework.beans.factory.InitializingBean;
2222
import org.springframework.beans.factory.ObjectProvider;
@@ -67,8 +67,9 @@ public class CacheAutoConfiguration {
6767
@Bean
6868
@ConditionalOnMissingBean
6969
public CacheManagerCustomizers cacheManagerCustomizers(
70-
ObjectProvider<List<CacheManagerCustomizer<?>>> customizers) {
71-
return new CacheManagerCustomizers(customizers.getIfAvailable());
70+
ObjectProvider<CacheManagerCustomizer<?>> customizers) {
71+
return new CacheManagerCustomizers(
72+
customizers.orderedStream().collect(Collectors.toList()));
7273
}
7374

7475
@Bean

0 commit comments

Comments
 (0)