Skip to content

Commit def7523

Browse files
tobias-lippertphilwebb
authored andcommitted
Inline redundant if statements
See gh-39259
1 parent 9cdd0c3 commit def7523

File tree

18 files changed

+24
-76
lines changed

18 files changed

+24
-76
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@ private boolean isNodeWithName(Object candidate, String name) {
291291
if ((node.name() instanceof QName qname) && name.equals(qname.getLocalPart())) {
292292
return true;
293293
}
294-
if (name.equals(node.name())) {
295-
return true;
296-
}
294+
return name.equals(node.name());
297295
}
298296
return false;
299297
}

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ public boolean equals(Object obj) {
5858
return false;
5959
}
6060
AbstractDependencyVersion other = (AbstractDependencyVersion) obj;
61-
if (!this.comparableVersion.equals(other.comparableVersion)) {
62-
return false;
63-
}
64-
return true;
61+
return this.comparableVersion.equals(other.comparableVersion);
6562
}
6663

6764
@Override

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersion.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ public boolean equals(Object obj) {
127127
return false;
128128
}
129129
ReleaseTrainDependencyVersion other = (ReleaseTrainDependencyVersion) obj;
130-
if (!this.original.equals(other.original)) {
131-
return false;
132-
}
133-
return true;
130+
return this.original.equals(other.original);
134131
}
135132

136133
@Override

buildSrc/src/main/java/org/springframework/boot/build/classpath/CheckClasspathForProhibitedDependencies.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ private boolean prohibited(ModuleVersionIdentifier id) {
100100
if (group.equals("org.apache.geronimo.specs")) {
101101
return true;
102102
}
103-
if (group.equals("com.sun.activation")) {
104-
return true;
105-
}
106-
return false;
103+
return group.equals("com.sun.activation");
107104
}
108105

109106
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscoverer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ public CloudFoundryWebEndpointDiscoverer(ApplicationContext applicationContext,
6565

6666
@Override
6767
protected boolean isExtensionTypeExposed(Class<?> extensionBeanType) {
68-
if (isHealthEndpointExtension(extensionBeanType) && !isCloudFoundryHealthEndpointExtension(extensionBeanType)) {
69-
// Filter regular health endpoint extensions so a CF version can replace them
70-
return false;
71-
}
72-
return true;
68+
// Filter regular health endpoint extensions so a CF version can replace them
69+
return !isHealthEndpointExtension(extensionBeanType)
70+
|| isCloudFoundryHealthEndpointExtension(extensionBeanType);
7371
}
7472

7573
private boolean isHealthEndpointExtension(Class<?> extensionBeanType) {

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ protected boolean ignoreApplicationContext(ApplicationContext applicationContext
136136
return true;
137137
}
138138
String managementContextId = applicationContext.getParent().getId() + ":management";
139-
if (!managementContextId.equals(applicationContext.getId())) {
140-
return true;
141-
}
139+
return !managementContextId.equals(applicationContext.getId());
142140
}
143141
return false;
144142
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ public boolean equals(Object obj) {
3939
if (obj == this) {
4040
return true;
4141
}
42-
if (obj == null || obj.getClass() != getClass()) {
43-
return false;
44-
}
45-
return true;
42+
return obj != null && obj.getClass() == getClass();
4643
}
4744

4845
@Override

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ private boolean isStandardBeanOrSingletonFactoryBean(ConfigurableListableBeanFac
119119
String factoryBeanName = BeanFactory.FACTORY_BEAN_PREFIX + name;
120120
if (beanFactory.containsBean(factoryBeanName)) {
121121
FactoryBean<?> factoryBean = (FactoryBean<?>) beanFactory.getBean(factoryBeanName);
122-
if (!factoryBean.isSingleton()) {
123-
return false;
124-
}
122+
return factoryBean.isSingleton();
125123
}
126124
return true;
127125
}

spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ public String getUsageHelp() {
8181
}
8282

8383
private boolean isHelpShown(Command command) {
84-
if (command instanceof HelpCommand || command instanceof HintCommand) {
85-
return false;
86-
}
87-
return true;
84+
return !(command instanceof HelpCommand) && !(command instanceof HintCommand);
8885
}
8986

9087
@Override

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

Lines changed: 2 additions & 8 deletions
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) {
@@ -348,10 +345,7 @@ public boolean matches(ItemHint value) {
348345
if (this.value != null && !this.value.equals(valueHint.getValue())) {
349346
return false;
350347
}
351-
if (this.description != null && !this.description.equals(valueHint.getDescription())) {
352-
return false;
353-
}
354-
return true;
348+
return this.description == null || this.description.equals(valueHint.getDescription());
355349
}
356350

357351
}

spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertyMigration.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,8 @@ private static boolean determineCompatibleType(ConfigurationMetadataProperty met
8585
if (replacementType.equals(currentType)) {
8686
return true;
8787
}
88-
if (replacementType.equals(Duration.class.getName())
89-
&& (currentType.equals(Long.class.getName()) || currentType.equals(Integer.class.getName()))) {
90-
return true;
91-
}
92-
return false;
88+
return replacementType.equals(Duration.class.getName())
89+
&& (currentType.equals(Long.class.getName()) || currentType.equals(Integer.class.getName()));
9390
}
9491

9592
private static String determineType(ConfigurationMetadataProperty metadata) {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,9 @@ private boolean isStringConversionBetter(TypeDescriptor sourceType, TypeDescript
9090
return true;
9191
}
9292
}
93-
if ((targetType.isArray() || targetType.isCollection()) && !targetType.equals(BYTE_ARRAY)) {
94-
// StringToArrayConverter / StringToCollectionConverter are better than
95-
// ObjectToArrayConverter / ObjectToCollectionConverter
96-
return true;
97-
}
98-
return false;
93+
// StringToArrayConverter / StringToCollectionConverter are better than
94+
// ObjectToArrayConverter / ObjectToCollectionConverter
95+
return (targetType.isArray() || targetType.isCollection()) && !targetType.equals(BYTE_ARRAY);
9996
}
10097

10198
@Override

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ boolean contains(Class<?> type, Object object) {
332332
&& this.seen.getOrDefault(type, Collections.emptySet()).contains(object)) {
333333
return true;
334334
}
335-
if (this.seen.getOrDefault(ServletContextInitializer.class, Collections.emptySet()).contains(object)) {
336-
return true;
337-
}
338-
return false;
335+
return this.seen.getOrDefault(ServletContextInitializer.class, Collections.emptySet()).contains(object);
339336
}
340337

341338
static Seen empty() {

spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,7 @@ public boolean supportsParameter(ParameterContext parameterContext, ExtensionCon
155155
if (parameterContext.getParameter().getType().equals(AbstractApplicationLauncher.class)) {
156156
return true;
157157
}
158-
if (parameterContext.getParameter().getType().equals(RestTemplate.class)) {
159-
return true;
160-
}
161-
return false;
158+
return parameterContext.getParameter().getType().equals(RestTemplate.class);
162159
}
163160

164161
@Override

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/test/java/smoketest/liquibase/SampleLiquibaseApplicationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ private boolean serverNotRunning(IllegalStateException ex) {
6969
};
7070
if (nested.contains(ConnectException.class)) {
7171
Throwable root = nested.getRootCause();
72-
if (root.getMessage().contains("Connection refused")) {
73-
return true;
74-
}
72+
return root.getMessage().contains("Connection refused");
7573
}
7674
return false;
7775
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Location.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ public boolean equals(Object o) {
5555
if (this.x != location.x) {
5656
return false;
5757
}
58-
if (this.y != location.y) {
59-
return false;
60-
}
61-
return true;
58+
return this.y == location.y;
6259
}
6360

6461
@Override

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Location.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ public boolean equals(Object o) {
5555
if (this.x != location.x) {
5656
return false;
5757
}
58-
if (this.y != location.y) {
59-
return false;
60-
}
61-
return true;
58+
return this.y == location.y;
6259
}
6360

6461
@Override

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Location.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ public boolean equals(Object o) {
5555
if (this.x != location.x) {
5656
return false;
5757
}
58-
if (this.y != location.y) {
59-
return false;
60-
}
61-
return true;
58+
return this.y == location.y;
6259
}
6360

6461
@Override

0 commit comments

Comments
 (0)