Skip to content

Commit e800cc3

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

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +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)
338-
|| (object instanceof String && ((String) object)
339-
.equalsIgnoreCase("false"))) {
337+
if (Boolean.FALSE.equals(object)
338+
|| (object instanceof String && "false".equalsIgnoreCase((String) object))) {
340339
return false;
341-
} else if (object.equals(Boolean.TRUE)
342-
|| (object instanceof String && ((String) object)
343-
.equalsIgnoreCase("true"))) {
340+
} else if (Boolean.TRUE.equals(object)
341+
|| (object instanceof String && "true".equalsIgnoreCase((String) object))) {
344342
return true;
345343
}
346344
throw wrongValueFormatException(index, "boolean", object, null);

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: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +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)
683-
|| (object instanceof String && ((String) object)
684-
.equalsIgnoreCase("false"))) {
682+
if (Boolean.FALSE.equals(object)
683+
|| (object instanceof String && "false".equalsIgnoreCase((String) object))) {
685684
return false;
686-
} else if (object.equals(Boolean.TRUE)
687-
|| (object instanceof String && ((String) object)
688-
.equalsIgnoreCase("true"))) {
685+
} else if (Boolean.TRUE.equals(object)
686+
|| (object instanceof String && "true".equalsIgnoreCase((String) object))) {
689687
return true;
690688
}
691689
throw wrongValueFormatException(key, "Boolean", object, null);
@@ -1911,7 +1909,7 @@ private static <A extends Annotation> A getAnnotation(final Method m, final Clas
19111909
}
19121910

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

19171915
try {
@@ -1969,7 +1967,7 @@ private static int getAnnotationDepth(final Method m, final Class<? extends Anno
19691967
}
19701968

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

19751973
try {
@@ -3022,7 +3020,7 @@ private static JSONException recursivelyDefinedObjectException(String key) {
30223020
* @return number without leading zeros
30233021
*/
30243022
private static String removeLeadingZerosOfNumber(String value){
3025-
if (value.equals("-")){return value;}
3023+
if ("-".equals(value)){return value;}
30263024
boolean negativeFirstChar = (value.charAt(0) == '-');
30273025
int counter = negativeFirstChar ? 1:0;
30283026
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)