Merge pull request #987 from AlexCai2019/master

Use constant.equals()
This commit is contained in:
Sean Leary 2025-06-07 09:59:48 -05:00 committed by GitHub
commit f1935f5254
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 17 deletions

View File

@ -334,13 +334,11 @@ public class JSONArray implements Iterable<Object> {
*/
public boolean getBoolean(int index) throws JSONException {
Object object = this.get(index);
if (object.equals(Boolean.FALSE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("false"))) {
if (Boolean.FALSE.equals(object)
|| (object instanceof String && "false".equalsIgnoreCase((String) object))) {
return false;
} else if (object.equals(Boolean.TRUE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("true"))) {
} else if (Boolean.TRUE.equals(object)
|| (object instanceof String && "true".equalsIgnoreCase((String) object))) {
return true;
}
throw wrongValueFormatException(index, "boolean", object, null);

View File

@ -111,7 +111,7 @@ public class JSONML {
}
} else if (c == '[') {
token = x.nextToken();
if (token.equals("CDATA") && x.next() == '[') {
if ("CDATA".equals(token) && x.next() == '[') {
if (ja != null) {
ja.put(x.nextCDATA());
}

View File

@ -679,13 +679,11 @@ public class JSONObject {
*/
public boolean getBoolean(String key) throws JSONException {
Object object = this.get(key);
if (object.equals(Boolean.FALSE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("false"))) {
if (Boolean.FALSE.equals(object)
|| (object instanceof String && "false".equalsIgnoreCase((String) object))) {
return false;
} else if (object.equals(Boolean.TRUE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("true"))) {
} else if (Boolean.TRUE.equals(object)
|| (object instanceof String && "true".equalsIgnoreCase((String) object))) {
return true;
}
throw wrongValueFormatException(key, "Boolean", object, null);
@ -1911,7 +1909,7 @@ public class JSONObject {
}
//If the superclass is Object, no annotations will be found any more
if (c.getSuperclass().equals(Object.class))
if (Object.class.equals(c.getSuperclass()))
return null;
try {
@ -1969,7 +1967,7 @@ public class JSONObject {
}
//If the superclass is Object, no annotations will be found any more
if (c.getSuperclass().equals(Object.class))
if (Object.class.equals(c.getSuperclass()))
return -1;
try {
@ -3022,7 +3020,7 @@ public class JSONObject {
* @return number without leading zeros
*/
private static String removeLeadingZerosOfNumber(String value){
if (value.equals("-")){return value;}
if ("-".equals(value)){return value;}
boolean negativeFirstChar = (value.charAt(0) == '-');
int counter = negativeFirstChar ? 1:0;
while (counter < value.length()){

View File

@ -127,7 +127,7 @@ public class JSONPointer {
if (pointer == null) {
throw new NullPointerException("pointer cannot be null");
}
if (pointer.isEmpty() || pointer.equals("#")) {
if (pointer.isEmpty() || "#".equals(pointer)) {
this.refTokens = Collections.emptyList();
return;
}