mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
clean up toString() and implement toJSON() consistently
This commit is contained in:
@@ -475,17 +475,20 @@ public class StringDict {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return this dictionary as a String in JSON format.
|
||||
*/
|
||||
public String toJSON() {
|
||||
StringList items = new StringList();
|
||||
for (int i = 0; i < count; i++) {
|
||||
items.append(JSONObject.quote(keys[i])+ ": " + JSONObject.quote(values[i]));
|
||||
}
|
||||
return "{ " + items.join(", ") + " }";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName() + " size=" + size() + " { ");
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (i != 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append("\"" + keys[i] + "\": \"" + values[i] + "\"");
|
||||
}
|
||||
sb.append(" }");
|
||||
return sb.toString();
|
||||
return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user