added configuration class
This commit is contained in:
@@ -17,6 +17,8 @@ import java.util.Map;
|
||||
|
||||
public abstract class ValueDumper implements Dumper {
|
||||
|
||||
protected final Value.Configuration cfg;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
protected static class StackLevel {
|
||||
public int index = 0;
|
||||
@@ -64,10 +66,16 @@ public abstract class ValueDumper implements Dumper {
|
||||
|
||||
protected ArrayDeque<StackLevel> stack;
|
||||
|
||||
protected ValueDumper() {
|
||||
protected ValueDumper(Value.Configuration cfg) {
|
||||
this.cfg = cfg;
|
||||
stack = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
protected ValueDumper() {
|
||||
this(Value.configuration);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void dump(Value value, OutputStream stream) {
|
||||
throw new NotImplementedException("Method not implemented");
|
||||
|
@@ -15,6 +15,8 @@ import java.util.ArrayDeque;
|
||||
|
||||
public class ValueParser implements Parser {
|
||||
|
||||
protected final Value.Configuration cfg;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
protected static class StackLevel {
|
||||
public final Value value;
|
||||
@@ -33,12 +35,12 @@ public class ValueParser implements Parser {
|
||||
protected static class ObjectStackLevel extends StackLevel {
|
||||
public String currentKey;
|
||||
|
||||
public ObjectStackLevel() {
|
||||
super(ObjectValue.newInstance(), -1);
|
||||
public ObjectStackLevel(Value.Configuration cfg) {
|
||||
super(ObjectValue.newInstance(cfg), -1);
|
||||
}
|
||||
|
||||
public ObjectStackLevel(long expectedSize) {
|
||||
super(ObjectValue.newInstance(), expectedSize);
|
||||
public ObjectStackLevel(Value.Configuration cfg, long expectedSize) {
|
||||
super(ObjectValue.newInstance(cfg), expectedSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +59,11 @@ public class ValueParser implements Parser {
|
||||
}
|
||||
|
||||
protected ValueParser() {
|
||||
this(Value.configuration);
|
||||
}
|
||||
|
||||
protected ValueParser(Value.Configuration cfg) {
|
||||
this.cfg = cfg;
|
||||
stack = new ArrayDeque<>();
|
||||
stack.push(new ArrayStackLevel());
|
||||
}
|
||||
@@ -77,11 +84,11 @@ public class ValueParser implements Parser {
|
||||
}
|
||||
|
||||
protected void beginObject() {
|
||||
stack.push(new ObjectStackLevel());
|
||||
stack.push(new ObjectStackLevel(cfg));
|
||||
}
|
||||
|
||||
protected void beginObject(long size) {
|
||||
stack.push(new ObjectStackLevel(size));
|
||||
stack.push(new ObjectStackLevel(cfg, size));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -3,6 +3,7 @@ package net.woggioni.worth.serialization.binary;
|
||||
import lombok.SneakyThrows;
|
||||
import net.woggioni.worth.exception.NotImplementedException;
|
||||
import net.woggioni.worth.serialization.ValueDumper;
|
||||
import net.woggioni.worth.serialization.json.JSONDumper;
|
||||
import net.woggioni.worth.utils.Leb128;
|
||||
import net.woggioni.worth.utils.WorthUtils;
|
||||
import net.woggioni.worth.value.ArrayValue;
|
||||
@@ -21,6 +22,18 @@ public class JBONDumper extends ValueDumper {
|
||||
return new JBONDumper();
|
||||
}
|
||||
|
||||
public static Dumper newInstance(Value.Configuration cfg) {
|
||||
return new JBONDumper(cfg);
|
||||
}
|
||||
|
||||
public JBONDumper() {
|
||||
super(Value.configuration);
|
||||
}
|
||||
|
||||
public JBONDumper(Value.Configuration cfg) {
|
||||
super(cfg);
|
||||
}
|
||||
|
||||
protected OutputStream os;
|
||||
|
||||
@Override
|
||||
|
@@ -4,6 +4,7 @@ import lombok.SneakyThrows;
|
||||
import net.woggioni.worth.buffer.LookAheadInputStream;
|
||||
import net.woggioni.worth.exception.ParseException;
|
||||
import net.woggioni.worth.serialization.ValueParser;
|
||||
import net.woggioni.worth.serialization.json.JSONParser;
|
||||
import net.woggioni.worth.utils.Leb128;
|
||||
import net.woggioni.worth.utils.WorthUtils;
|
||||
import net.woggioni.worth.xface.Parser;
|
||||
@@ -127,4 +128,16 @@ public class JBONParser extends ValueParser {
|
||||
public static Parser newInstance() {
|
||||
return new JBONParser();
|
||||
}
|
||||
|
||||
public static Parser newInstance(Value.Configuration cfg) {
|
||||
return new JBONParser(cfg);
|
||||
}
|
||||
|
||||
public JBONParser() {
|
||||
super(Value.configuration);
|
||||
}
|
||||
|
||||
public JBONParser(Value.Configuration cfg) {
|
||||
super(cfg);
|
||||
}
|
||||
}
|
@@ -20,6 +20,18 @@ public class JSONDumper extends ValueDumper {
|
||||
return new JSONDumper();
|
||||
}
|
||||
|
||||
public static Dumper newInstance(Value.Configuration cfg) {
|
||||
return new JSONDumper(cfg);
|
||||
}
|
||||
|
||||
public JSONDumper() {
|
||||
super(Value.configuration);
|
||||
}
|
||||
|
||||
public JSONDumper(Value.Configuration cfg) {
|
||||
super(cfg);
|
||||
}
|
||||
|
||||
private Writer writer;
|
||||
|
||||
private String escapeString(String value){
|
||||
|
@@ -140,6 +140,17 @@ public class JSONParser extends ValueParser {
|
||||
public static Parser newInstance() {
|
||||
return new JSONParser();
|
||||
}
|
||||
public static Parser newInstance(Value.Configuration cfg) {
|
||||
return new JSONParser(cfg);
|
||||
}
|
||||
|
||||
public JSONParser() {
|
||||
super(Value.configuration);
|
||||
}
|
||||
|
||||
public JSONParser(Value.Configuration cfg) {
|
||||
super(cfg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value parse(InputStream stream) {
|
||||
|
@@ -9,12 +9,13 @@ import java.util.*;
|
||||
|
||||
public interface ObjectValue extends Value, Iterable<Map.Entry<String, Value>> {
|
||||
|
||||
Implementation implementation = Implementation.valueOf(
|
||||
System.getProperty(ObjectValue.class.getName() + ".implementation", "TreeMap"));
|
||||
|
||||
static ObjectValue newInstance() {
|
||||
return newInstance(Value.configuration);
|
||||
}
|
||||
|
||||
static ObjectValue newInstance(Configuration cfg) {
|
||||
ObjectValue result;
|
||||
switch(implementation) {
|
||||
switch(cfg.objectValueImplementation) {
|
||||
case ArrayList:
|
||||
result = new ListObjectValue();
|
||||
break;
|
||||
@@ -31,7 +32,7 @@ public interface ObjectValue extends Value, Iterable<Map.Entry<String, Value>> {
|
||||
throw WorthUtils.newThrowable(IllegalArgumentException.class,
|
||||
"Unknown value of %s: %s",
|
||||
Implementation.class.getName(),
|
||||
implementation);
|
||||
cfg.objectValueImplementation);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package net.woggioni.worth.xface;
|
||||
|
||||
import net.woggioni.worth.exception.TypeException;
|
||||
import net.woggioni.worth.value.NullValue;
|
||||
import net.woggioni.worth.value.ObjectValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -83,4 +84,12 @@ public interface Value {
|
||||
default boolean has(String key) {
|
||||
throw new TypeException("Not an object");
|
||||
}
|
||||
|
||||
class Configuration {
|
||||
public ObjectValue.Implementation objectValueImplementation = ObjectValue.Implementation.valueOf(
|
||||
System.getProperty(ObjectValue.class.getName() + ".implementation", "TreeMap"));
|
||||
public boolean useReferences = Boolean.valueOf(
|
||||
System.getProperty(Value.class.getName() + ".useReferences", "false"));
|
||||
}
|
||||
Configuration configuration = new Configuration();
|
||||
}
|
||||
|
Reference in New Issue
Block a user