From 0e8faada15caeb680e0de0efd36cb3dabc3765bb Mon Sep 17 00:00:00 2001 From: richard1230 Date: Sun, 26 Apr 2020 15:27:20 +0800 Subject: [PATCH] Simplify some code --- .../java/org/springframework/boot/cloud/CloudPlatform.java | 2 +- .../boot/context/properties/bind/ValueObjectBinder.java | 5 +---- .../java/org/springframework/boot/logging/DeferredLog.java | 1 - .../boot/web/embedded/tomcat/TomcatGracefulShutdown.java | 5 ++--- .../boot/web/embedded/undertow/UndertowWebServer.java | 4 ++-- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java index d55f1f13c022..f74b4135f0c2 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java @@ -149,7 +149,7 @@ public boolean isActive(Environment environment) { */ public boolean isEnforced(Environment environment) { String platform = environment.getProperty("spring.main.cloud-platform"); - return (platform != null) ? name().equalsIgnoreCase(platform) : false; + return name().equalsIgnoreCase(platform); } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java index 0b320a62622d..db31f878e1e9 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java @@ -117,10 +117,7 @@ private T getNewInstanceIfPossible(Binder.Context context, ResolvableType ty } private boolean isEmptyDefaultValueAllowed(Class type) { - if (type.isPrimitive() || type.isEnum() || isAggregate(type) || type.getName().startsWith("java.lang")) { - return false; - } - return true; + return !type.isPrimitive() && !type.isEnum() && !isAggregate(type) && !type.getName().startsWith("java.lang"); } private boolean isAggregate(Class type) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java index b7c192f6321c..4c3b6f21bbe9 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java @@ -232,7 +232,6 @@ private static void logTo(Log log, LogLevel level, Object message, Throwable thr return; case FATAL: log.fatal(message, throwable); - return; } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatGracefulShutdown.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatGracefulShutdown.java index b0f79a93f226..b883275dc9dc 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatGracefulShutdown.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatGracefulShutdown.java @@ -18,6 +18,7 @@ import java.time.Duration; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.apache.catalina.Container; @@ -106,9 +107,7 @@ private boolean active(Container context) { private List getConnectors() { List connectors = new ArrayList<>(); for (Service service : this.tomcat.getServer().findServices()) { - for (Connector connector : service.findConnectors()) { - connectors.add(connector); - } + connectors.addAll(Arrays.asList(service.findConnectors())); } return connectors; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java index 7b07da024759..b023c3af92af 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java @@ -251,11 +251,11 @@ public int getPort() { @Override public boolean shutDownGracefully() { - return (this.gracefulShutdown != null) ? this.gracefulShutdown.shutDownGracefully() : false; + return (this.gracefulShutdown != null) && this.gracefulShutdown.shutDownGracefully(); } boolean inGracefulShutdown() { - return (this.gracefulShutdown != null) ? this.gracefulShutdown.isShuttingDown() : false; + return (this.gracefulShutdown != null) && this.gracefulShutdown.isShuttingDown(); } /**