Skip to content

Commit

Permalink
Removed some redundant 'else's using early return
Browse files Browse the repository at this point in the history
  • Loading branch information
pradipta authored and snicoll committed Sep 1, 2020
1 parent 72c6435 commit 2627bf8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 38 deletions.
Expand Up @@ -77,13 +77,11 @@ protected <T> OperationPreprocessor limit(Predicate<T> filter, String... keys) {
Object target = payload;
Map<Object, Object> parent = null;
for (String key : keys) {
if (target instanceof Map) {
parent = (Map<Object, Object>) target;
target = parent.get(key);
}
else {
if (!(target instanceof Map)) {
throw new IllegalStateException();
}
parent = (Map<Object, Object>) target;
target = parent.get(key);
}
if (target instanceof Map) {
parent.put(keys[keys.length - 1], select((Map<String, Object>) target, filter));
Expand Down
Expand Up @@ -404,9 +404,7 @@ private boolean isCandidate(BeanDescription beanDesc, BeanPropertyWriter writer,
return Arrays.stream(bindConstructor.getParameters())
.anyMatch((parameter) -> parameter.getName().equals(writer.getName()));
}
else {
return isReadable(beanDesc, writer);
}
return isReadable(beanDesc, writer);
}

private boolean isReadable(BeanDescription beanDesc, BeanPropertyWriter writer) {
Expand Down
Expand Up @@ -152,19 +152,17 @@ public Resource getResource(String location) {
if (location.startsWith(CLASSPATH_URL_PREFIX)) {
return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());
}
else {
if (location.startsWith(FILE_URL_PREFIX)) {
return this.files.getResource(location);
}
try {
// Try to parse the location as a URL...
URL url = new URL(location);
return new UrlResource(url);
}
catch (MalformedURLException ex) {
// No URL -> resolve as resource path.
return getResourceByPath(location);
}
if (location.startsWith(FILE_URL_PREFIX)) {
return this.files.getResource(location);
}
try {
// Try to parse the location as a URL...
URL url = new URL(location);
return new UrlResource(url);
}
catch (MalformedURLException ex) {
// No URL -> resolve as resource path.
return getResourceByPath(location);
}
}

Expand Down
Expand Up @@ -127,10 +127,7 @@ String determineReason() {
return String.format("Reason: Replacement key '%s' uses an incompatible target type",
deprecation.getReplacement());
}
else {
return String.format("Reason: No metadata found for replacement key '%s'",
deprecation.getReplacement());
}
return String.format("Reason: No metadata found for replacement key '%s'", deprecation.getReplacement());
}
return "Reason: none";
}
Expand Down
Expand Up @@ -596,12 +596,10 @@ public String optString(String name, String fallback) {
*/
public JSONArray getJSONArray(String name) throws JSONException {
Object object = get(name);
if (object instanceof JSONArray) {
return (JSONArray) object;
}
else {
if (!(object instanceof JSONArray)) {
throw JSON.typeMismatch(name, object, "JSONArray");
}
return (JSONArray) object;
}

/**
Expand All @@ -625,12 +623,10 @@ public JSONArray optJSONArray(String name) {
*/
public JSONObject getJSONObject(String name) throws JSONException {
Object object = get(name);
if (object instanceof JSONObject) {
return (JSONObject) object;
}
else {
if (!(object instanceof JSONObject)) {
throw JSON.typeMismatch(name, object, "JSONObject");
}
return (JSONObject) object;
}

/**
Expand Down
Expand Up @@ -549,15 +549,13 @@ public static int dehexchar(char hex) {
if (hex >= '0' && hex <= '9') {
return hex - '0';
}
else if (hex >= 'A' && hex <= 'F') {
if (hex >= 'A' && hex <= 'F') {
return hex - 'A' + 10;
}
else if (hex >= 'a' && hex <= 'f') {
if (hex >= 'a' && hex <= 'f') {
return hex - 'a' + 10;
}
else {
return -1;
}
return -1;
}

}

0 comments on commit 2627bf8

Please sign in to comment.