Fixed some things
This commit is contained in:
parent
f7eac65fb3
commit
5252f04451
2 changed files with 42 additions and 2 deletions
|
|
@ -44,6 +44,13 @@ public class JSONNode implements Iterable<JSONNode>{
|
||||||
this.type = JSONType.Number;
|
this.type = JSONType.Number;
|
||||||
this.value = ""+value;
|
this.value = ""+value;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Creates an instance with an long value
|
||||||
|
*/
|
||||||
|
public JSONNode(long value){
|
||||||
|
this.type = JSONType.Number;
|
||||||
|
this.value = ""+value;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Creates an instance with an String value
|
* Creates an instance with an String value
|
||||||
*/
|
*/
|
||||||
|
|
@ -130,6 +137,9 @@ public class JSONNode implements Iterable<JSONNode>{
|
||||||
public void add(double value){
|
public void add(double value){
|
||||||
list.add(new JSONNode( value ));
|
list.add(new JSONNode( value ));
|
||||||
}
|
}
|
||||||
|
public void add(long value){
|
||||||
|
list.add(new JSONNode( value ));
|
||||||
|
}
|
||||||
public void add(String value){
|
public void add(String value){
|
||||||
list.add(new JSONNode( value ));
|
list.add(new JSONNode( value ));
|
||||||
}
|
}
|
||||||
|
|
@ -148,6 +158,9 @@ public class JSONNode implements Iterable<JSONNode>{
|
||||||
public void add(String key, double value){
|
public void add(String key, double value){
|
||||||
map.put(key, new JSONNode(value));
|
map.put(key, new JSONNode(value));
|
||||||
}
|
}
|
||||||
|
public void add(String key, long value){
|
||||||
|
map.put(key, new JSONNode(value));
|
||||||
|
}
|
||||||
public void add(String key, String value){
|
public void add(String key, String value){
|
||||||
map.put(key, new JSONNode(value));
|
map.put(key, new JSONNode(value));
|
||||||
}
|
}
|
||||||
|
|
@ -175,6 +188,14 @@ public class JSONNode implements Iterable<JSONNode>{
|
||||||
type = JSONType.Boolean;
|
type = JSONType.Boolean;
|
||||||
this.value = ""+value;
|
this.value = ""+value;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Sets the value of the node, but only if it is setup as an JSONType.Value
|
||||||
|
*/
|
||||||
|
public void set(long value){
|
||||||
|
if( !this.isValue() ) throw new NullPointerException("The node is not setup as a value");
|
||||||
|
type = JSONType.Number;
|
||||||
|
this.value = ""+value;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Sets the value of the node, but only if it is setup as an JSONType.Value
|
* Sets the value of the node, but only if it is setup as an JSONType.Value
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package zutil.parser.json;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import zutil.parser.json.JSONNode.JSONType;
|
import zutil.parser.json.JSONNode.JSONType;
|
||||||
|
|
@ -12,7 +13,7 @@ import zutil.parser.json.JSONNode.JSONType;
|
||||||
* @author Ziver
|
* @author Ziver
|
||||||
*/
|
*/
|
||||||
public class JSONWriter{
|
public class JSONWriter{
|
||||||
private PrintStream out;
|
private PrintWriter out;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the writer
|
* Creates a new instance of the writer
|
||||||
|
|
@ -20,7 +21,25 @@ public class JSONWriter{
|
||||||
* @param out the OutputStream that the Nodes will be sent to
|
* @param out the OutputStream that the Nodes will be sent to
|
||||||
*/
|
*/
|
||||||
public JSONWriter(OutputStream out){
|
public JSONWriter(OutputStream out){
|
||||||
this.out = new PrintStream(out);
|
this( new PrintWriter(out) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of the writer
|
||||||
|
*
|
||||||
|
* @param out the OutputStream that the Nodes will be sent to
|
||||||
|
*/
|
||||||
|
public JSONWriter(PrintStream out){
|
||||||
|
this( new PrintWriter(out) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of the writer
|
||||||
|
*
|
||||||
|
* @param out the OutputStream that the Nodes will be sent to
|
||||||
|
*/
|
||||||
|
public JSONWriter(PrintWriter out){
|
||||||
|
this.out = out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue