Browse Source

Made JSONNull a singleton, thanks grissis

master
Thomas Withiam 2 years ago
parent
commit
92193a65a4
  1. 6
      src/net/pop1040/JSON/JSONArray.java
  2. 2
      src/net/pop1040/JSON/JSONObject.java
  3. 6
      src/net/pop1040/JSON/JSONValue.java

6
src/net/pop1040/JSON/JSONArray.java

@ -55,7 +55,7 @@ public class JSONArray extends JSONValue {
return values.size();
}
private void ensureCapacity(int i) {
while(this.size()<i)values.add(new JSONNull());
while(this.size()<i)values.add(JSONNull.nullVal);
}
public JSONArray setValue(JSONValue v, int i) {
@ -76,7 +76,7 @@ public class JSONArray extends JSONValue {
return this;
}
public JSONArray setNull(int i) {
setValue(new JSONNull(), i);
setValue(JSONNull.nullVal, i);
return this;
}
public JSONArray setBoolean(boolean b, int i) {
@ -109,7 +109,7 @@ public class JSONArray extends JSONValue {
return this;
}
public JSONArray addNull() {
addValue(new JSONNull());
addValue(JSONNull.nullVal);
return this;
}
public JSONArray addBoolean(boolean b) {

2
src/net/pop1040/JSON/JSONObject.java

@ -96,7 +96,7 @@ public class JSONObject extends JSONValue{
}
public JSONObject setNull(String key) {
values.put(key, new JSONNull());
values.put(key, JSONNull.nullVal);
return this;
}
public JSONObject setString(String key, String val) {

6
src/net/pop1040/JSON/JSONValue.java

@ -67,6 +67,10 @@ public class JSONValue {
}
}
public static class JSONNull extends JSONValue{
public static final JSONNull nullVal = new JSONNull();
protected JSONNull(){}
@Override
public String toString() {
return "null";
@ -132,7 +136,7 @@ public class JSONValue {
if(s.nextInt() != 'l')throw new IOException("JSON null was not completed");
if(!s.hasNext()) throw new IOException("JSON null was not completed");
if(s.nextInt() != 'l')throw new IOException("JSON null was not completed");
return new ParseRet(new JSONNull(), nextNonWhitespace(s));
return new ParseRet(JSONNull.nullVal, nextNonWhitespace(s));
}
case 'f':{
if(!s.hasNext()) throw new IOException("JSON boolean false was not completed");

Loading…
Cancel
Save