1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

change length comparison to isEmpty method

This commit is contained in:
Andrei_Paikin 2018-05-21 16:58:13 +03:00
parent a490ebdb78
commit 05074386d3
5 changed files with 25 additions and 25 deletions

View file

@ -224,7 +224,7 @@ public class CDL {
*/
public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
throws JSONException {
if (names == null || names.length() == 0) {
if (names == null || names.isEmpty()) {
return null;
}
JSONArray ja = new JSONArray();
@ -235,7 +235,7 @@ public class CDL {
}
ja.put(jo);
}
if (ja.length() == 0) {
if (ja.isEmpty()) {
return null;
}
return ja;
@ -272,7 +272,7 @@ public class CDL {
*/
public static String toString(JSONArray names, JSONArray ja)
throws JSONException {
if (names == null || names.length() == 0) {
if (names == null || names.isEmpty()) {
return null;
}
StringBuffer sb = new StringBuffer();

View file

@ -1352,7 +1352,7 @@ public class JSONArray implements Iterable<Object> {
* If any of the names are null.
*/
public JSONObject toJSONObject(JSONArray names) throws JSONException {
if (names == null || names.length() == 0 || this.length() == 0) {
if (names == null || names.isEmpty() || this.isEmpty()) {
return null;
}
JSONObject jo = new JSONObject(names.length());
@ -1528,4 +1528,14 @@ public class JSONArray implements Iterable<Object> {
}
return results;
}
/**
* Check if JSONArray is empty.
*
* @return true if JSONArray is empty, otherwise false.
*/
public boolean isEmpty() {
return myArrayList.isEmpty();
}
}

View file

@ -178,7 +178,7 @@ public class JSONML {
newjo.accumulate(attribute, "");
}
}
if (arrayForm && newjo.length() > 0) {
if (arrayForm && !newjo.isEmpty()) {
newja.put(newjo);
}
@ -208,7 +208,7 @@ public class JSONML {
"' and '" + closeTag + "'");
}
tagName = null;
if (!arrayForm && newja.length() > 0) {
if (!arrayForm && !newja.isEmpty()) {
newjo.put("childNodes", newja);
}
if (ja == null) {

View file

@ -810,11 +810,10 @@ public class JSONObject {
* @return An array of field names, or null if there are no names.
*/
public static String[] getNames(JSONObject jo) {
int length = jo.length();
if (length == 0) {
if (jo.isEmpty()) {
return null;
}
return jo.keySet().toArray(new String[length]);
return jo.keySet().toArray(new String[jo.length()]);
}
/**
@ -972,15 +971,6 @@ public class JSONObject {
return map.isEmpty();
}
/**
* Check if JSONObject is not empty.
*
* @return true if JSONObject is not empty, otherwise false.
*/
public boolean isNotEmpty() {
return !map.isEmpty();
}
/**
* Produce a JSONArray containing the names of the elements of this
* JSONObject.
@ -1966,7 +1956,7 @@ public class JSONObject {
}
public static Writer quote(String string, Writer w) throws IOException {
if (string == null || string.length() == 0) {
if (string == null || string.isEmpty()) {
w.write("\"\"");
return w;
}
@ -2245,7 +2235,7 @@ public class JSONObject {
* If any of the values are non-finite numbers.
*/
public JSONArray toJSONArray(JSONArray names) throws JSONException {
if (names == null || names.length() == 0) {
if (names == null || names.isEmpty()) {
return null;
}
JSONArray ja = new JSONArray();

View file

@ -277,7 +277,7 @@ public class XML {
if ("CDATA".equals(token)) {
if (x.next() == '[') {
string = x.nextCDATA();
if (string.length() > 0) {
if (!string.isEmpty()) {
context.accumulate("content", string);
}
return false;
@ -353,7 +353,7 @@ public class XML {
if (x.nextToken() != GT) {
throw x.syntaxError("Misshaped tag");
}
if (jsonobject.length() > 0) {
if (!jsonobject.isEmpty()) {
context.accumulate(tagName, jsonobject);
} else {
context.accumulate(tagName, "");
@ -371,7 +371,7 @@ public class XML {
return false;
} else if (token instanceof String) {
string = (String) token;
if (string.length() > 0) {
if (!string.isEmpty()) {
jsonobject.accumulate("content",
keepStrings ? string : stringToValue(string));
}
@ -379,7 +379,7 @@ public class XML {
} else if (token == LT) {
// Nested element
if (parse(x, jsonobject, tagName,keepStrings)) {
if (jsonobject.length() == 0) {
if (jsonobject.isEmpty()) {
context.accumulate(tagName, "");
} else if (jsonobject.length() == 1
&& jsonobject.opt("content") != null) {
@ -676,7 +676,7 @@ public class XML {
string = (object == null) ? "null" : escape(object.toString());
return (tagName == null) ? "\"" + string + "\""
: (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName
: (string.isEmpty()) ? "<" + tagName + "/>" : "<" + tagName
+ ">" + string + "</" + tagName + ">";
}