Polish code to use method references when possible

This commit is contained in:
Phillip Webb
2022-05-17 19:03:43 -07:00
parent 50e27333d2
commit 350d27fe50
15 changed files with 39 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -56,7 +56,7 @@ public class EnvironmentPostProcessorApplicationListener implements SmartApplica
* {@link EnvironmentPostProcessor} classes loaded via {@code spring.factories}.
*/
public EnvironmentPostProcessorApplicationListener() {
this((classLoader) -> EnvironmentPostProcessorsFactory.fromSpringFactories(classLoader), new DeferredLogs());
this(EnvironmentPostProcessorsFactory::fromSpringFactories, new DeferredLogs());
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -398,8 +398,7 @@ public final class DataSourceBuilder<T extends DataSource> {
Class<T> dataSourceType) {
MappedDataSourceProperties<T> result = null;
result = lookup(classLoader, dataSourceType, result,
"org.springframework.jdbc.datasource.SimpleDriverDataSource",
() -> new SimpleDataSourceProperties());
"org.springframework.jdbc.datasource.SimpleDriverDataSource", SimpleDataSourceProperties::new);
result = lookup(classLoader, dataSourceType, result, "oracle.jdbc.datasource.OracleDataSource",
OracleDataSourceProperties::new);
result = lookup(classLoader, dataSourceType, result, "org.h2.jdbcx.JdbcDataSource",
@@ -660,7 +659,7 @@ public final class DataSourceBuilder<T extends DataSource> {
SimpleDataSourceProperties() {
add(DataSourceProperty.URL, SimpleDriverDataSource::getUrl, SimpleDriverDataSource::setUrl);
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class, (dataSource) -> dataSource.getDriver().getClass(),
(dataSource, driverClass) -> dataSource.setDriverClass(driverClass));
SimpleDriverDataSource::setDriverClass);
add(DataSourceProperty.USERNAME, SimpleDriverDataSource::getUsername, SimpleDriverDataSource::setUsername);
add(DataSourceProperty.PASSWORD, SimpleDriverDataSource::getPassword, SimpleDriverDataSource::setPassword);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -38,7 +38,7 @@ public class SpringBootPropertySource implements PropertySource {
@Override
public void forEach(BiConsumer<String, String> action) {
this.properties.forEach((key, value) -> action.accept(key, value));
this.properties.forEach(action::accept);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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,7 +111,7 @@ public class Instantiator<T> {
*/
public List<T> instantiateTypes(Collection<Class<?>> types) {
Assert.notNull(types, "Types must not be null");
return instantiate(types.stream().map((type) -> TypeSupplier.forType(type)));
return instantiate(types.stream().map(TypeSupplier::forType));
}
private List<T> instantiate(Stream<TypeSupplier> typeSuppliers) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -116,8 +116,8 @@ public class NettyWebServer implements WebServer {
private String getStartedOnMessage(DisposableServer server) {
StringBuilder message = new StringBuilder();
tryAppend(message, "port %s", () -> server.port());
tryAppend(message, "path %s", () -> server.path());
tryAppend(message, "port %s", server::port);
tryAppend(message, "path %s", server::path);
return (message.length() > 0) ? " on " + message : "";
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -295,7 +295,7 @@ public class UndertowWebServer implements WebServer {
logger.info("Commencing graceful shutdown. Waiting for active requests to complete");
this.gracefulShutdownCallback.set(callback);
this.gracefulShutdown.shutdown();
this.gracefulShutdown.addShutdownListener((success) -> notifyGracefulCallback(success));
this.gracefulShutdown.addShutdownListener(this::notifyGracefulCallback);
}
private void notifyGracefulCallback(boolean success) {

View File

@@ -20,6 +20,7 @@ import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;
import org.mockito.invocation.InvocationOnMock;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
@@ -119,7 +120,7 @@ class AliasedConfigurationPropertySourceTests {
private ConfigurationPropertySource mockConfigurationPropertySource() {
ConfigurationPropertySource mock = mock(ConfigurationPropertySource.class);
given(mock.withAliases(any())).willAnswer((invocation) -> invocation.callRealMethod());
given(mock.withAliases(any())).willAnswer(InvocationOnMock::callRealMethod);
return mock;
}