Skip to content

Commit 8870834

Browse files
committed
Merge pull request #39259 from tobias-lippert
* pr/39259: Update copyright header of cleaned up code Replace !Optional.isPresent with Optional.isEmpty Polish 'Simplify stream chain operations' Simplify stream chain operations Polish 'Remove redundant array creation' Remove redundant array creation Replace multiple ifs with switch Use try with resources instead of try-finally Replace explicit type with diamond operator Avoid redundant boxing Remove redundant boxing Polish 'Use pattern variables' Use pattern variables Use string.repeat() Polish 'Simplify conditionals' Simplify conditionals Inline redundant if statements Remove unnecessary semicolons Remove unnecessary toString calls Closes gh-39259
2 parents a31319c + 8f1a330 commit 8870834

File tree

63 files changed

+175
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+175
-245
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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/UpgradeDependencies.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private Milestone determineMilestone(GitHubRepository repository) {
194194
java.util.Optional<Milestone> matchingMilestone = milestones.stream()
195195
.filter((milestone) -> milestone.getName().equals(getMilestone().get()))
196196
.findFirst();
197-
if (!matchingMilestone.isPresent()) {
197+
if (matchingMilestone.isEmpty()) {
198198
throw new InvalidUserDataException("Unknown milestone: " + getMilestone().get());
199199
}
200200
return matchingMilestone.get();
@@ -242,9 +242,9 @@ private boolean isAnUpgrade(Library library, DependencyVersion candidate) {
242242
}
243243

244244
private boolean isNotProhibited(Library library, DependencyVersion candidate) {
245-
return !library.getProhibitedVersions()
245+
return library.getProhibitedVersions()
246246
.stream()
247-
.anyMatch((prohibited) -> prohibited.isProhibited(candidate.toString()));
247+
.noneMatch((prohibited) -> prohibited.isProhibited(candidate.toString()));
248248
}
249249

250250
private List<Library> matchingLibraries() {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,22 +64,25 @@ public int compareTo(DependencyVersion other) {
6464

6565
@Override
6666
public boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots) {
67-
if (!(candidate instanceof ReleaseTrainDependencyVersion)) {
68-
return true;
67+
if (candidate instanceof ReleaseTrainDependencyVersion candidateReleaseTrain) {
68+
return isUpgrade(candidateReleaseTrain, movingToSnapshots);
6969
}
70-
ReleaseTrainDependencyVersion candidateReleaseTrain = (ReleaseTrainDependencyVersion) candidate;
71-
int comparison = this.releaseTrain.compareTo(candidateReleaseTrain.releaseTrain);
70+
return true;
71+
}
72+
73+
private boolean isUpgrade(ReleaseTrainDependencyVersion candidate, boolean movingToSnapshots) {
74+
int comparison = this.releaseTrain.compareTo(candidate.releaseTrain);
7275
if (comparison != 0) {
7376
return comparison < 0;
7477
}
75-
if (movingToSnapshots && !isSnapshot() && candidateReleaseTrain.isSnapshot()) {
78+
if (movingToSnapshots && !isSnapshot() && candidate.isSnapshot()) {
7679
return true;
7780
}
78-
comparison = this.type.compareTo(candidateReleaseTrain.type);
81+
comparison = this.type.compareTo(candidate.type);
7982
if (comparison != 0) {
8083
return comparison < 0;
8184
}
82-
return Integer.compare(this.version, candidateReleaseTrain.version) < 0;
85+
return Integer.compare(this.version, candidate.version) < 0;
8386
}
8487

8588
private boolean isSnapshot() {
@@ -88,10 +91,9 @@ private boolean isSnapshot() {
8891

8992
@Override
9093
public boolean isSnapshotFor(DependencyVersion candidate) {
91-
if (!isSnapshot() || !(candidate instanceof ReleaseTrainDependencyVersion)) {
94+
if (!isSnapshot() || !(candidate instanceof ReleaseTrainDependencyVersion candidateReleaseTrain)) {
9295
return false;
9396
}
94-
ReleaseTrainDependencyVersion candidateReleaseTrain = (ReleaseTrainDependencyVersion) candidate;
9597
return this.releaseTrain.equals(candidateReleaseTrain.releaseTrain);
9698
}
9799

@@ -127,10 +129,7 @@ public boolean equals(Object obj) {
127129
return false;
128130
}
129131
ReleaseTrainDependencyVersion other = (ReleaseTrainDependencyVersion) obj;
130-
if (!this.original.equals(other.original)) {
131-
return false;
132-
}
133-
return true;
132+
return this.original.equals(other.original);
134133
}
135134

136135
@Override

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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/info/InfoContributorFallback.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,6 @@ public enum InfoContributorFallback {
3737
/**
3838
* Do not fall back, thereby disabling the info contributor.
3939
*/
40-
DISABLE;
40+
DISABLE
4141

4242
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -90,7 +90,7 @@ public static MeterValue valueOf(String value) {
9090
if (duration != null) {
9191
return new MeterValue(duration);
9292
}
93-
return new MeterValue(Double.valueOf(value));
93+
return new MeterValue(Double.parseDouble(value));
9494
}
9595

9696
/**

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -116,7 +116,7 @@ public enum HistogramType {
116116
/**
117117
* Delta histogram.
118118
*/
119-
DELTA;
119+
DELTA
120120

121121
}
122122

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/TracingProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public enum PropagationType {
268268
* <a href="https://github.com/openzipkin/b3-propagation#multiple-headers">B3
269269
* multiple headers</a> propagation.
270270
*/
271-
B3_MULTI;
271+
B3_MULTI
272272

273273
}
274274

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ public boolean isMandatory() {
6868
if (!ObjectUtils.isEmpty(this.parameter.getAnnotationsByType(Nullable.class))) {
6969
return false;
7070
}
71-
return (jsr305Present) ? new Jsr305().isMandatory(this.parameter) : true;
71+
if (jsr305Present) {
72+
return new Jsr305().isMandatory(this.parameter);
73+
}
74+
return true;
7275
}
7376

7477
@Override

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -482,7 +482,7 @@ public enum Compression {
482482
/**
483483
* No compression.
484484
*/
485-
NONE;
485+
NONE
486486

487487
}
488488

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -224,7 +224,7 @@ public enum ConstructorDetectorStrategy {
224224
* Refuse to decide implicit mode and instead throw an InvalidDefinitionException
225225
* for ambiguous cases.
226226
*/
227-
EXPLICIT_ONLY;
227+
EXPLICIT_ONLY
228228

229229
}
230230

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFile.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,8 +55,12 @@ public ClassLoaderFile(Kind kind, byte[] contents) {
5555
*/
5656
public ClassLoaderFile(Kind kind, long lastModified, byte[] contents) {
5757
Assert.notNull(kind, "Kind must not be null");
58-
Assert.isTrue((kind != Kind.DELETED) ? contents != null : contents == null,
59-
() -> "Contents must " + ((kind != Kind.DELETED) ? "not " : "") + "be null");
58+
if (kind == Kind.DELETED) {
59+
Assert.isTrue(contents == null, "Contents must be null");
60+
}
61+
else {
62+
Assert.isTrue(contents != null, "Contents must not be null");
63+
}
6064
this.kind = kind;
6165
this.lastModified = lastModified;
6266
this.contents = contents;

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ContextCustomizer createContextCustomizer(Class<?> testClass,
4444
}
4545
OverrideAutoConfiguration overrideAutoConfiguration = TestContextAnnotationUtils.findMergedAnnotation(testClass,
4646
OverrideAutoConfiguration.class);
47-
boolean enabled = (overrideAutoConfiguration != null) ? overrideAutoConfiguration.enabled() : true;
47+
boolean enabled = (overrideAutoConfiguration == null) || overrideAutoConfiguration.enabled();
4848
return !enabled ? new DisableAutoConfigurationContextCustomizer() : null;
4949
}
5050

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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/context/SpringBootTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -211,7 +211,7 @@ enum UseMainMethod {
211211
* that class does not have a main method, a test-specific
212212
* {@link SpringApplication} will be used.
213213
*/
214-
WHEN_AVAILABLE;
214+
WHEN_AVAILABLE
215215

216216
}
217217

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/BsdDomainSocket.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ private SockaddrUn(byte sunFamily, byte[] path) {
7575

7676
@Override
7777
protected List<String> getFieldOrder() {
78-
return Arrays.asList(new String[] { "sunLen", "sunFamily", "sunPath" });
78+
return Arrays.asList("sunLen", "sunFamily", "sunPath");
7979
}
8080

8181
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/LinuxDomainSocket.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ private SockaddrUn(byte sunFamily, byte[] path) {
7272

7373
@Override
7474
protected List<String> getFieldOrder() {
75-
return Arrays.asList(new String[] { "sunFamily", "sunPath" });
75+
return Arrays.asList("sunFamily", "sunPath");
7676
}
7777

7878
}

0 commit comments

Comments
 (0)