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:
parent
a490ebdb78
commit
05074386d3
5 changed files with 25 additions and 25 deletions
6
CDL.java
6
CDL.java
|
@ -224,7 +224,7 @@ public class CDL {
|
||||||
*/
|
*/
|
||||||
public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
|
public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
if (names == null || names.length() == 0) {
|
if (names == null || names.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JSONArray ja = new JSONArray();
|
JSONArray ja = new JSONArray();
|
||||||
|
@ -235,7 +235,7 @@ public class CDL {
|
||||||
}
|
}
|
||||||
ja.put(jo);
|
ja.put(jo);
|
||||||
}
|
}
|
||||||
if (ja.length() == 0) {
|
if (ja.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ja;
|
return ja;
|
||||||
|
@ -272,7 +272,7 @@ public class CDL {
|
||||||
*/
|
*/
|
||||||
public static String toString(JSONArray names, JSONArray ja)
|
public static String toString(JSONArray names, JSONArray ja)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
if (names == null || names.length() == 0) {
|
if (names == null || names.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
|
@ -1352,7 +1352,7 @@ public class JSONArray implements Iterable<Object> {
|
||||||
* If any of the names are null.
|
* If any of the names are null.
|
||||||
*/
|
*/
|
||||||
public JSONObject toJSONObject(JSONArray names) throws JSONException {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
JSONObject jo = new JSONObject(names.length());
|
JSONObject jo = new JSONObject(names.length());
|
||||||
|
@ -1528,4 +1528,14 @@ public class JSONArray implements Iterable<Object> {
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if JSONArray is empty.
|
||||||
|
*
|
||||||
|
* @return true if JSONArray is empty, otherwise false.
|
||||||
|
*/
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return myArrayList.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ public class JSONML {
|
||||||
newjo.accumulate(attribute, "");
|
newjo.accumulate(attribute, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (arrayForm && newjo.length() > 0) {
|
if (arrayForm && !newjo.isEmpty()) {
|
||||||
newja.put(newjo);
|
newja.put(newjo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ public class JSONML {
|
||||||
"' and '" + closeTag + "'");
|
"' and '" + closeTag + "'");
|
||||||
}
|
}
|
||||||
tagName = null;
|
tagName = null;
|
||||||
if (!arrayForm && newja.length() > 0) {
|
if (!arrayForm && !newja.isEmpty()) {
|
||||||
newjo.put("childNodes", newja);
|
newjo.put("childNodes", newja);
|
||||||
}
|
}
|
||||||
if (ja == null) {
|
if (ja == null) {
|
||||||
|
|
|
@ -810,11 +810,10 @@ public class JSONObject {
|
||||||
* @return An array of field names, or null if there are no names.
|
* @return An array of field names, or null if there are no names.
|
||||||
*/
|
*/
|
||||||
public static String[] getNames(JSONObject jo) {
|
public static String[] getNames(JSONObject jo) {
|
||||||
int length = jo.length();
|
if (jo.isEmpty()) {
|
||||||
if (length == 0) {
|
|
||||||
return null;
|
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();
|
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
|
* Produce a JSONArray containing the names of the elements of this
|
||||||
* JSONObject.
|
* JSONObject.
|
||||||
|
@ -1966,7 +1956,7 @@ public class JSONObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Writer quote(String string, Writer w) throws IOException {
|
public static Writer quote(String string, Writer w) throws IOException {
|
||||||
if (string == null || string.length() == 0) {
|
if (string == null || string.isEmpty()) {
|
||||||
w.write("\"\"");
|
w.write("\"\"");
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
@ -2245,7 +2235,7 @@ public class JSONObject {
|
||||||
* If any of the values are non-finite numbers.
|
* If any of the values are non-finite numbers.
|
||||||
*/
|
*/
|
||||||
public JSONArray toJSONArray(JSONArray names) throws JSONException {
|
public JSONArray toJSONArray(JSONArray names) throws JSONException {
|
||||||
if (names == null || names.length() == 0) {
|
if (names == null || names.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JSONArray ja = new JSONArray();
|
JSONArray ja = new JSONArray();
|
||||||
|
|
10
XML.java
10
XML.java
|
@ -277,7 +277,7 @@ public class XML {
|
||||||
if ("CDATA".equals(token)) {
|
if ("CDATA".equals(token)) {
|
||||||
if (x.next() == '[') {
|
if (x.next() == '[') {
|
||||||
string = x.nextCDATA();
|
string = x.nextCDATA();
|
||||||
if (string.length() > 0) {
|
if (!string.isEmpty()) {
|
||||||
context.accumulate("content", string);
|
context.accumulate("content", string);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -353,7 +353,7 @@ public class XML {
|
||||||
if (x.nextToken() != GT) {
|
if (x.nextToken() != GT) {
|
||||||
throw x.syntaxError("Misshaped tag");
|
throw x.syntaxError("Misshaped tag");
|
||||||
}
|
}
|
||||||
if (jsonobject.length() > 0) {
|
if (!jsonobject.isEmpty()) {
|
||||||
context.accumulate(tagName, jsonobject);
|
context.accumulate(tagName, jsonobject);
|
||||||
} else {
|
} else {
|
||||||
context.accumulate(tagName, "");
|
context.accumulate(tagName, "");
|
||||||
|
@ -371,7 +371,7 @@ public class XML {
|
||||||
return false;
|
return false;
|
||||||
} else if (token instanceof String) {
|
} else if (token instanceof String) {
|
||||||
string = (String) token;
|
string = (String) token;
|
||||||
if (string.length() > 0) {
|
if (!string.isEmpty()) {
|
||||||
jsonobject.accumulate("content",
|
jsonobject.accumulate("content",
|
||||||
keepStrings ? string : stringToValue(string));
|
keepStrings ? string : stringToValue(string));
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ public class XML {
|
||||||
} else if (token == LT) {
|
} else if (token == LT) {
|
||||||
// Nested element
|
// Nested element
|
||||||
if (parse(x, jsonobject, tagName,keepStrings)) {
|
if (parse(x, jsonobject, tagName,keepStrings)) {
|
||||||
if (jsonobject.length() == 0) {
|
if (jsonobject.isEmpty()) {
|
||||||
context.accumulate(tagName, "");
|
context.accumulate(tagName, "");
|
||||||
} else if (jsonobject.length() == 1
|
} else if (jsonobject.length() == 1
|
||||||
&& jsonobject.opt("content") != null) {
|
&& jsonobject.opt("content") != null) {
|
||||||
|
@ -676,7 +676,7 @@ public class XML {
|
||||||
|
|
||||||
string = (object == null) ? "null" : escape(object.toString());
|
string = (object == null) ? "null" : escape(object.toString());
|
||||||
return (tagName == null) ? "\"" + string + "\""
|
return (tagName == null) ? "\"" + string + "\""
|
||||||
: (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName
|
: (string.isEmpty()) ? "<" + tagName + "/>" : "<" + tagName
|
||||||
+ ">" + string + "</" + tagName + ">";
|
+ ">" + string + "</" + tagName + ">";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue