Skip to content

Commit 92dc0da

Browse files
pradiptasnicoll
authored andcommitted
Removed some redundant 'else's using early return
See spring-projectsgh-22528
1 parent e181982 commit 92dc0da

File tree

6 files changed

+23
-38
lines changed

6 files changed

+23
-38
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AbstractEndpointDocumentationTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ protected <T> OperationPreprocessor limit(Predicate<T> filter, String... keys) {
7777
Object target = payload;
7878
Map<Object, Object> parent = null;
7979
for (String key : keys) {
80-
if (target instanceof Map) {
81-
parent = (Map<Object, Object>) target;
82-
target = parent.get(key);
83-
}
84-
else {
80+
if (!(target instanceof Map)) {
8581
throw new IllegalStateException();
8682
}
83+
parent = (Map<Object, Object>) target;
84+
target = parent.get(key);
8785
}
8886
if (target instanceof Map) {
8987
parent.put(keys[keys.length - 1], select((Map<String, Object>) target, filter));

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,7 @@ private boolean isCandidate(BeanDescription beanDesc, BeanPropertyWriter writer,
399399
return Arrays.stream(bindConstructor.getParameters())
400400
.anyMatch((parameter) -> parameter.getName().equals(writer.getName()));
401401
}
402-
else {
403-
return isReadable(beanDesc, writer);
404-
}
402+
return isReadable(beanDesc, writer);
405403
}
406404

407405
private boolean isReadable(BeanDescription beanDesc, BeanPropertyWriter writer) {

spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,17 @@ public Resource getResource(String location) {
152152
if (location.startsWith(CLASSPATH_URL_PREFIX)) {
153153
return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());
154154
}
155-
else {
156-
if (location.startsWith(FILE_URL_PREFIX)) {
157-
return this.files.getResource(location);
158-
}
159-
try {
160-
// Try to parse the location as a URL...
161-
URL url = new URL(location);
162-
return new UrlResource(url);
163-
}
164-
catch (MalformedURLException ex) {
165-
// No URL -> resolve as resource path.
166-
return getResourceByPath(location);
167-
}
155+
if (location.startsWith(FILE_URL_PREFIX)) {
156+
return this.files.getResource(location);
157+
}
158+
try {
159+
// Try to parse the location as a URL...
160+
URL url = new URL(location);
161+
return new UrlResource(url);
162+
}
163+
catch (MalformedURLException ex) {
164+
// No URL -> resolve as resource path.
165+
return getResourceByPath(location);
168166
}
169167
}
170168

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ String determineReason() {
127127
return String.format("Reason: Replacement key '%s' uses an incompatible target type",
128128
deprecation.getReplacement());
129129
}
130-
else {
131-
return String.format("Reason: No metadata found for replacement key '%s'",
132-
deprecation.getReplacement());
133-
}
130+
return String.format("Reason: No metadata found for replacement key '%s'", deprecation.getReplacement());
134131
}
135132
return "Reason: none";
136133
}

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,10 @@ public String optString(String name, String fallback) {
596596
*/
597597
public JSONArray getJSONArray(String name) throws JSONException {
598598
Object object = get(name);
599-
if (object instanceof JSONArray) {
600-
return (JSONArray) object;
601-
}
602-
else {
599+
if (!(object instanceof JSONArray)) {
603600
throw JSON.typeMismatch(name, object, "JSONArray");
604601
}
602+
return (JSONArray) object;
605603
}
606604

607605
/**
@@ -625,12 +623,10 @@ public JSONArray optJSONArray(String name) {
625623
*/
626624
public JSONObject getJSONObject(String name) throws JSONException {
627625
Object object = get(name);
628-
if (object instanceof JSONObject) {
629-
return (JSONObject) object;
630-
}
631-
else {
626+
if (!(object instanceof JSONObject)) {
632627
throw JSON.typeMismatch(name, object, "JSONObject");
633628
}
629+
return (JSONObject) object;
634630
}
635631

636632
/**

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,13 @@ public static int dehexchar(char hex) {
549549
if (hex >= '0' && hex <= '9') {
550550
return hex - '0';
551551
}
552-
else if (hex >= 'A' && hex <= 'F') {
552+
if (hex >= 'A' && hex <= 'F') {
553553
return hex - 'A' + 10;
554554
}
555-
else if (hex >= 'a' && hex <= 'f') {
555+
if (hex >= 'a' && hex <= 'f') {
556556
return hex - 'a' + 10;
557557
}
558-
else {
559-
return -1;
560-
}
558+
return -1;
561559
}
562560

563561
}

0 commit comments

Comments
 (0)