From c6c3a91f8d7ed0fb627f20d11e30afc0fdb6af49 Mon Sep 17 00:00:00 2001 From: SaberXu Date: Mon, 5 Aug 2019 22:56:13 +0800 Subject: [PATCH 1/2] Simplify if statements See gh-17785 --- .../metadata/ConfigurationMetadata.java | 2 +- .../configurationprocessor/metadata/Metadata.java | 10 ++-------- .../tasks/bundling/LaunchScriptConfiguration.java | 11 ++++------- .../boot/loader/tools/MainClassFinder.java | 5 +---- .../maven/PropertiesMergingResourceTransformer.java | 5 +---- 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java index 4473816db07..048d4e0fb0b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java @@ -165,7 +165,7 @@ public class ConfigurationMetadata { if (o1 == o2) { return true; } - return o1 != null && o2 != null && o1.equals(o2); + return o1 != null && o1.equals(o2); } public static String nestedPrefix(String prefix, String name) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java index 69e3d914cfb..d49030af997 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java @@ -157,10 +157,7 @@ public final class Metadata { if (this.deprecation == null && itemMetadata.getDeprecation() != null) { return false; } - if (this.deprecation != null && !this.deprecation.equals(itemMetadata.getDeprecation())) { - return false; - } - return true; + return this.deprecation == null || this.deprecation.equals(itemMetadata.getDeprecation()); } public MetadataItemCondition ofType(Class dataType) { @@ -342,10 +339,7 @@ public final class Metadata { if (this.value != null && !this.value.equals(valueHint.getValue())) { return false; } - if (this.description != null && !this.description.equals(valueHint.getDescription())) { - return false; - } - return true; + return this.description == null || this.description.equals(valueHint.getDescription()); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LaunchScriptConfiguration.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LaunchScriptConfiguration.java index 147c19a876f..c084cecaa50 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LaunchScriptConfiguration.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LaunchScriptConfiguration.java @@ -106,17 +106,14 @@ public class LaunchScriptConfiguration implements Serializable { return false; } if (this.script == null) { - if (other.script != null) { - return false; - } + return other.script == null; } else if (!this.script.equals(other.script)) { return false; } - else if (!equalContents(this.script, other.script)) { - return false; + else { + return equalContents(this.script, other.script); } - return true; } private boolean equalContents(File one, File two) { @@ -132,7 +129,7 @@ public class LaunchScriptConfiguration implements Serializable { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((this.properties == null) ? 0 : this.properties.hashCode()); + result = prime * result + this.properties.hashCode(); result = prime * result + ((this.script == null) ? 0 : this.script.hashCode()); return result; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java index a4488836201..cfe20c14b74 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java @@ -381,10 +381,7 @@ public abstract class MainClassFinder { return false; } MainClass other = (MainClass) obj; - if (!this.name.equals(other.name)) { - return false; - } - return true; + return this.name.equals(other.name); } @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java index 1ba1186c787..3d5141f1558 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java @@ -52,10 +52,7 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer @Override public boolean canTransformResource(String resource) { - if (this.resource != null && this.resource.equalsIgnoreCase(resource)) { - return true; - } - return false; + return this.resource != null && this.resource.equalsIgnoreCase(resource); } @Override From 1c8f7278645e323495021dde7476a27e7c47b9cb Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 8 Aug 2019 14:35:29 +0200 Subject: [PATCH 2/2] Polish "Simplify if statements" See gh-17785 --- .../boot/configurationprocessor/metadata/Metadata.java | 10 ++++++++-- .../boot/loader/tools/MainClassFinder.java | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java index d49030af997..69e3d914cfb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java @@ -157,7 +157,10 @@ public final class Metadata { if (this.deprecation == null && itemMetadata.getDeprecation() != null) { return false; } - return this.deprecation == null || this.deprecation.equals(itemMetadata.getDeprecation()); + if (this.deprecation != null && !this.deprecation.equals(itemMetadata.getDeprecation())) { + return false; + } + return true; } public MetadataItemCondition ofType(Class dataType) { @@ -339,7 +342,10 @@ public final class Metadata { if (this.value != null && !this.value.equals(valueHint.getValue())) { return false; } - return this.description == null || this.description.equals(valueHint.getDescription()); + if (this.description != null && !this.description.equals(valueHint.getDescription())) { + return false; + } + return true; } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java index cfe20c14b74..a4488836201 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java @@ -381,7 +381,10 @@ public abstract class MainClassFinder { return false; } MainClass other = (MainClass) obj; - return this.name.equals(other.name); + if (!this.name.equals(other.name)) { + return false; + } + return true; } @Override