Skip to content

Commit c6c3a91

Browse files
SaberXusnicoll
SaberXu
authored andcommitted
Simplify if statements
See spring-projectsgh-17785
1 parent 3efead4 commit c6c3a91

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private boolean nullSafeEquals(Object o1, Object o2) {
165165
if (o1 == o2) {
166166
return true;
167167
}
168-
return o1 != null && o2 != null && o1.equals(o2);
168+
return o1 != null && o1.equals(o2);
169169
}
170170

171171
public static String nestedPrefix(String prefix, String name) {

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@ public boolean matches(ConfigurationMetadata value) {
157157
if (this.deprecation == null && itemMetadata.getDeprecation() != null) {
158158
return false;
159159
}
160-
if (this.deprecation != null && !this.deprecation.equals(itemMetadata.getDeprecation())) {
161-
return false;
162-
}
163-
return true;
160+
return this.deprecation == null || this.deprecation.equals(itemMetadata.getDeprecation());
164161
}
165162

166163
public MetadataItemCondition ofType(Class<?> dataType) {
@@ -342,10 +339,7 @@ public boolean matches(ItemHint value) {
342339
if (this.value != null && !this.value.equals(valueHint.getValue())) {
343340
return false;
344341
}
345-
if (this.description != null && !this.description.equals(valueHint.getDescription())) {
346-
return false;
347-
}
348-
return true;
342+
return this.description == null || this.description.equals(valueHint.getDescription());
349343
}
350344

351345
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LaunchScriptConfiguration.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,14 @@ public boolean equals(Object obj) {
106106
return false;
107107
}
108108
if (this.script == null) {
109-
if (other.script != null) {
110-
return false;
111-
}
109+
return other.script == null;
112110
}
113111
else if (!this.script.equals(other.script)) {
114112
return false;
115113
}
116-
else if (!equalContents(this.script, other.script)) {
117-
return false;
114+
else {
115+
return equalContents(this.script, other.script);
118116
}
119-
return true;
120117
}
121118

122119
private boolean equalContents(File one, File two) {
@@ -132,7 +129,7 @@ private boolean equalContents(File one, File two) {
132129
public int hashCode() {
133130
final int prime = 31;
134131
int result = 1;
135-
result = prime * result + ((this.properties == null) ? 0 : this.properties.hashCode());
132+
result = prime * result + this.properties.hashCode();
136133
result = prime * result + ((this.script == null) ? 0 : this.script.hashCode());
137134
return result;
138135
}

spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,7 @@ public boolean equals(Object obj) {
381381
return false;
382382
}
383383
MainClass other = (MainClass) obj;
384-
if (!this.name.equals(other.name)) {
385-
return false;
386-
}
387-
return true;
384+
return this.name.equals(other.name);
388385
}
389386

390387
@Override

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ public Properties getData() {
5252

5353
@Override
5454
public boolean canTransformResource(String resource) {
55-
if (this.resource != null && this.resource.equalsIgnoreCase(resource)) {
56-
return true;
57-
}
58-
return false;
55+
return this.resource != null && this.resource.equalsIgnoreCase(resource);
5956
}
6057

6158
@Override

0 commit comments

Comments
 (0)