Skip to content

Commit 68c7152

Browse files
committed
Use constant.equals()
There are some equals() that are not constant.equals(variable), but variable.equals(constant)
1 parent 72a1a48 commit 68c7152

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

src/main/java/org/json/JSONArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ public Object get(int index) throws JSONException {
334334
*/
335335
public boolean getBoolean(int index) throws JSONException {
336336
Object object = this.get(index);
337-
if (object.equals(Boolean.FALSE)
337+
if (Boolean.FALSE.equals(object)
338338
|| (object instanceof String && ((String) object)
339339
.equalsIgnoreCase("false"))) {
340340
return false;
341-
} else if (object.equals(Boolean.TRUE)
341+
} else if (Boolean.TRUE.equals(object)
342342
|| (object instanceof String && ((String) object)
343343
.equalsIgnoreCase("true"))) {
344344
return true;

src/main/java/org/json/JSONML.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static Object parse(
111111
}
112112
} else if (c == '[') {
113113
token = x.nextToken();
114-
if (token.equals("CDATA") && x.next() == '[') {
114+
if ("CDATA".equals(token) && x.next() == '[') {
115115
if (ja != null) {
116116
ja.put(x.nextCDATA());
117117
}

src/main/java/org/json/JSONObject.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,11 @@ public <E extends Enum<E>> E getEnum(Class<E> clazz, String key) throws JSONExce
679679
*/
680680
public boolean getBoolean(String key) throws JSONException {
681681
Object object = this.get(key);
682-
if (object.equals(Boolean.FALSE)
682+
if (Boolean.FALSE.equals(object)
683683
|| (object instanceof String && ((String) object)
684684
.equalsIgnoreCase("false"))) {
685685
return false;
686-
} else if (object.equals(Boolean.TRUE)
686+
} else if (Boolean.TRUE.equals(object)
687687
|| (object instanceof String && ((String) object)
688688
.equalsIgnoreCase("true"))) {
689689
return true;
@@ -1911,7 +1911,7 @@ private static <A extends Annotation> A getAnnotation(final Method m, final Clas
19111911
}
19121912

19131913
//If the superclass is Object, no annotations will be found any more
1914-
if (c.getSuperclass().equals(Object.class))
1914+
if (Object.class.equals(c.getSuperclass()))
19151915
return null;
19161916

19171917
try {
@@ -1969,7 +1969,7 @@ private static int getAnnotationDepth(final Method m, final Class<? extends Anno
19691969
}
19701970

19711971
//If the superclass is Object, no annotations will be found any more
1972-
if (c.getSuperclass().equals(Object.class))
1972+
if (Object.class.equals(c.getSuperclass()))
19731973
return -1;
19741974

19751975
try {
@@ -2751,9 +2751,6 @@ private static Object wrap(Object object, Set<Object> objectsRecord) {
27512751

27522752
private static Object wrap(Object object, Set<Object> objectsRecord, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
27532753
try {
2754-
if (NULL.equals(object)) {
2755-
return NULL;
2756-
}
27572754
if (object instanceof JSONObject || object instanceof JSONArray
27582755
|| NULL.equals(object) || object instanceof JSONString
27592756
|| object instanceof Byte || object instanceof Character
@@ -3022,7 +3019,7 @@ private static JSONException recursivelyDefinedObjectException(String key) {
30223019
* @return number without leading zeros
30233020
*/
30243021
private static String removeLeadingZerosOfNumber(String value){
3025-
if (value.equals("-")){return value;}
3022+
if ("-".equals(value)){return value;}
30263023
boolean negativeFirstChar = (value.charAt(0) == '-');
30273024
int counter = negativeFirstChar ? 1:0;
30283025
while (counter < value.length()){

src/main/java/org/json/JSONPointer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public JSONPointer(final String pointer) {
127127
if (pointer == null) {
128128
throw new NullPointerException("pointer cannot be null");
129129
}
130-
if (pointer.isEmpty() || pointer.equals("#")) {
130+
if (pointer.isEmpty() || "#".equals(pointer)) {
131131
this.refTokens = Collections.emptyList();
132132
return;
133133
}

0 commit comments

Comments
 (0)