Skip to content

Commit c724710

Browse files
committed
Merge pull request #17779 from blindpirate
* pr/17779: Simplify conditional statements Closes gh-17779
2 parents 4002a66 + c19057e commit c724710

File tree

8 files changed

+16
-33
lines changed

8 files changed

+16
-33
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,8 @@ private boolean isComponent(Class<?> type) {
281281
}
282282
// Nested anonymous classes are not eligible for registration, nor are groovy
283283
// closures
284-
if (type.getName().matches(".*\\$_.*closure.*") || type.isAnonymousClass() || type.getConstructors() == null
285-
|| type.getConstructors().length == 0) {
286-
return false;
287-
}
288-
return true;
284+
return !type.getName().matches(".*\\$_.*closure.*") && !type.isAnonymousClass()
285+
&& type.getConstructors() != null && type.getConstructors().length != 0;
289286
}
290287

291288
/**

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/ApplicationPidFileWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private void writePidFile(SpringApplicationEvent event) throws IOException {
160160

161161
private boolean failOnWriteError(SpringApplicationEvent event) {
162162
String value = getProperty(event, FAIL_ON_WRITE_ERROR_PROPERTIES);
163-
return (value != null) ? Boolean.parseBoolean(value) : false;
163+
return Boolean.parseBoolean(value);
164164
}
165165

166166
private String getProperty(SpringApplicationEvent event, List<Property> candidates) {

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/handler/NoUnboundElementsBindHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ private void collectUnbound(ConfigurationPropertyName name, Set<ConfigurationPro
9999

100100
private boolean isUnbound(ConfigurationPropertyName name, ConfigurationPropertyName candidate) {
101101
if (name.isAncestorOf(candidate)) {
102-
if (!this.boundNames.contains(candidate) && !isOverriddenCollectionElement(candidate)) {
103-
return true;
104-
}
102+
return !this.boundNames.contains(candidate) && !isOverriddenCollectionElement(candidate);
105103
}
106104
return false;
107105
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/CollectionToDelimitedStringConverter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
4949
if (targetType == null || sourceElementType == null) {
5050
return true;
5151
}
52-
if (this.conversionService.canConvert(sourceElementType, targetType)
53-
|| sourceElementType.getType().isAssignableFrom(targetType.getType())) {
54-
return true;
55-
}
56-
return false;
52+
return this.conversionService.canConvert(sourceElementType, targetType)
53+
|| sourceElementType.getType().isAssignableFrom(targetType.getType());
5754
}
5855

5956
@Override

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/AbstractDataSourceInitializer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@ private boolean isEnabled() {
6969
if (getMode() == DataSourceInitializationMode.NEVER) {
7070
return false;
7171
}
72-
if (getMode() == DataSourceInitializationMode.EMBEDDED
73-
&& !EmbeddedDatabaseConnection.isEmbedded(this.dataSource)) {
74-
return false;
75-
}
76-
return true;
72+
return getMode() != DataSourceInitializationMode.EMBEDDED
73+
|| EmbeddedDatabaseConnection.isEmbedded(this.dataSource);
7774
}
7875

7976
/**

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,42 @@ public class DeferredLog implements Log {
3838
@Override
3939
public boolean isTraceEnabled() {
4040
synchronized (this.lines) {
41-
return (this.destination != null) ? this.destination.isTraceEnabled() : true;
41+
return (this.destination == null) || this.destination.isTraceEnabled();
4242
}
4343
}
4444

4545
@Override
4646
public boolean isDebugEnabled() {
4747
synchronized (this.lines) {
48-
return (this.destination != null) ? this.destination.isDebugEnabled() : true;
48+
return (this.destination == null) || this.destination.isDebugEnabled();
4949
}
5050
}
5151

5252
@Override
5353
public boolean isInfoEnabled() {
5454
synchronized (this.lines) {
55-
return (this.destination != null) ? this.destination.isInfoEnabled() : true;
55+
return (this.destination == null) || this.destination.isInfoEnabled();
5656
}
5757
}
5858

5959
@Override
6060
public boolean isWarnEnabled() {
6161
synchronized (this.lines) {
62-
return (this.destination != null) ? this.destination.isWarnEnabled() : true;
62+
return (this.destination == null) || this.destination.isWarnEnabled();
6363
}
6464
}
6565

6666
@Override
6767
public boolean isErrorEnabled() {
6868
synchronized (this.lines) {
69-
return (this.destination != null) ? this.destination.isErrorEnabled() : true;
69+
return (this.destination == null) || this.destination.isErrorEnabled();
7070
}
7171
}
7272

7373
@Override
7474
public boolean isFatalEnabled() {
7575
synchronized (this.lines) {
76-
return (this.destination != null) ? this.destination.isFatalEnabled() : true;
76+
return (this.destination == null) || this.destination.isFatalEnabled();
7777
}
7878
}
7979

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,7 @@ public boolean equals(Object obj) {
344344
return false;
345345
}
346346
Port other = (Port) obj;
347-
if (this.number != other.number) {
348-
return false;
349-
}
350-
return true;
347+
return this.number == other.number;
351348
}
352349

353350
@Override

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,7 @@ public boolean equals(Object obj) {
275275
return false;
276276
}
277277
UndertowWebServer.Port other = (UndertowWebServer.Port) obj;
278-
if (this.number != other.number) {
279-
return false;
280-
}
281-
return true;
278+
return this.number == other.number;
282279
}
283280

284281
@Override

0 commit comments

Comments
 (0)