Polish "Removed some redundant 'else's using early return"

See gh-22528
This commit is contained in:
Stephane Nicoll 2020-09-01 13:34:08 +02:00
parent 2627bf896e
commit f8bc656921
3 changed files with 14 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

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

View File

@ -549,13 +549,15 @@ public class JSONTokener {
if (hex >= '0' && hex <= '9') {
return hex - '0';
}
if (hex >= 'A' && hex <= 'F') {
else if (hex >= 'A' && hex <= 'F') {
return hex - 'A' + 10;
}
if (hex >= 'a' && hex <= 'f') {
else if (hex >= 'a' && hex <= 'f') {
return hex - 'a' + 10;
}
return -1;
else {
return -1;
}
}
}