From c19057e117ec8f5bb6802e71ee40232a21cff09d Mon Sep 17 00:00:00 2001 From: Bo Zhang Date: Sun, 4 Aug 2019 21:14:01 +0800 Subject: [PATCH] Simplify conditional statements See gh-17779 --- .../springframework/boot/BeanDefinitionLoader.java | 7 ++----- .../boot/context/ApplicationPidFileWriter.java | 2 +- .../bind/handler/NoUnboundElementsBindHandler.java | 4 +--- .../CollectionToDelimitedStringConverter.java | 7 ++----- .../boot/jdbc/AbstractDataSourceInitializer.java | 7 ++----- .../springframework/boot/logging/DeferredLog.java | 12 ++++++------ .../embedded/undertow/UndertowServletWebServer.java | 5 +---- .../web/embedded/undertow/UndertowWebServer.java | 5 +---- 8 files changed, 16 insertions(+), 33 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java index 487ae326189..760a436ac7b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java @@ -281,11 +281,8 @@ class BeanDefinitionLoader { } // Nested anonymous classes are not eligible for registration, nor are groovy // closures - if (type.getName().matches(".*\\$_.*closure.*") || type.isAnonymousClass() || type.getConstructors() == null - || type.getConstructors().length == 0) { - return false; - } - return true; + return !type.getName().matches(".*\\$_.*closure.*") && !type.isAnonymousClass() + && type.getConstructors() != null && type.getConstructors().length != 0; } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/ApplicationPidFileWriter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/ApplicationPidFileWriter.java index 29dea9e8856..1fa0b65ae39 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/ApplicationPidFileWriter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/ApplicationPidFileWriter.java @@ -160,7 +160,7 @@ public class ApplicationPidFileWriter implements ApplicationListener candidates) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java index 754fce22bfb..b81cc5b8408 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java @@ -99,9 +99,7 @@ public class NoUnboundElementsBindHandler extends AbstractBindHandler { private boolean isUnbound(ConfigurationPropertyName name, ConfigurationPropertyName candidate) { if (name.isAncestorOf(candidate)) { - if (!this.boundNames.contains(candidate) && !isOverriddenCollectionElement(candidate)) { - return true; - } + return !this.boundNames.contains(candidate) && !isOverriddenCollectionElement(candidate); } return false; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/CollectionToDelimitedStringConverter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/CollectionToDelimitedStringConverter.java index 6d6f6d39ae8..66bb03612a3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/CollectionToDelimitedStringConverter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/CollectionToDelimitedStringConverter.java @@ -49,11 +49,8 @@ final class CollectionToDelimitedStringConverter implements ConditionalGenericCo if (targetType == null || sourceElementType == null) { return true; } - if (this.conversionService.canConvert(sourceElementType, targetType) - || sourceElementType.getType().isAssignableFrom(targetType.getType())) { - return true; - } - return false; + return this.conversionService.canConvert(sourceElementType, targetType) + || sourceElementType.getType().isAssignableFrom(targetType.getType()); } @Override diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/AbstractDataSourceInitializer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/AbstractDataSourceInitializer.java index 49eda08e9b2..9696260a974 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/AbstractDataSourceInitializer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/AbstractDataSourceInitializer.java @@ -69,11 +69,8 @@ public abstract class AbstractDataSourceInitializer { if (getMode() == DataSourceInitializationMode.NEVER) { return false; } - if (getMode() == DataSourceInitializationMode.EMBEDDED - && !EmbeddedDatabaseConnection.isEmbedded(this.dataSource)) { - return false; - } - return true; + return getMode() != DataSourceInitializationMode.EMBEDDED + || EmbeddedDatabaseConnection.isEmbedded(this.dataSource); } /** 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 be7bb093185..b7c192f6321 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 @@ -38,42 +38,42 @@ public class DeferredLog implements Log { @Override public boolean isTraceEnabled() { synchronized (this.lines) { - return (this.destination != null) ? this.destination.isTraceEnabled() : true; + return (this.destination == null) || this.destination.isTraceEnabled(); } } @Override public boolean isDebugEnabled() { synchronized (this.lines) { - return (this.destination != null) ? this.destination.isDebugEnabled() : true; + return (this.destination == null) || this.destination.isDebugEnabled(); } } @Override public boolean isInfoEnabled() { synchronized (this.lines) { - return (this.destination != null) ? this.destination.isInfoEnabled() : true; + return (this.destination == null) || this.destination.isInfoEnabled(); } } @Override public boolean isWarnEnabled() { synchronized (this.lines) { - return (this.destination != null) ? this.destination.isWarnEnabled() : true; + return (this.destination == null) || this.destination.isWarnEnabled(); } } @Override public boolean isErrorEnabled() { synchronized (this.lines) { - return (this.destination != null) ? this.destination.isErrorEnabled() : true; + return (this.destination == null) || this.destination.isErrorEnabled(); } } @Override public boolean isFatalEnabled() { synchronized (this.lines) { - return (this.destination != null) ? this.destination.isFatalEnabled() : true; + return (this.destination == null) || this.destination.isFatalEnabled(); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java index 66213ffc7d5..4ddf009a6dd 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java @@ -344,10 +344,7 @@ public class UndertowServletWebServer implements WebServer { return false; } Port other = (Port) obj; - if (this.number != other.number) { - return false; - } - return true; + return this.number == other.number; } @Override 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 4ef89105b11..e8027d0903a 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 @@ -275,10 +275,7 @@ public class UndertowWebServer implements WebServer { return false; } UndertowWebServer.Port other = (UndertowWebServer.Port) obj; - if (this.number != other.number) { - return false; - } - return true; + return this.number == other.number; } @Override