com.dimajix.shaded.everit.schema.internal.JSONPrinter Maven / Gradle / Ivy
package com.dimajix.shaded.everit.schema.internal;
import static java.util.Objects.requireNonNull;
import java.io.Writer;
import java.util.Map;
import com.dimajix.shaded.everit.schema.Schema;
public class JSONPrinter {
private final JSONWriter writer;
public JSONPrinter(Writer writer) {
this(new JSONWriter(writer));
}
public JSONPrinter(com.dimajix.shaded.json.JSONWriter writer) {
throw new RuntimeException();
}
public JSONPrinter(JSONWriter writer) {
this.writer = requireNonNull(writer, "writer cannot be null");
}
public JSONPrinter key(final String key) {
writer.key(key);
return this;
}
public JSONPrinter value(final Object value) {
writer.value(value);
return this;
}
public JSONPrinter object() {
writer.object();
return this;
}
public JSONPrinter endObject() {
writer.endObject();
return this;
}
public JSONPrinter ifPresent(final String key, final Object value) {
if (value != null) {
key(key);
value(value);
}
return this;
}
public JSONPrinter ifTrue(final String key, final Boolean value) {
if (value != null && value) {
key(key);
value(value);
}
return this;
}
public JSONPrinter array() {
writer.array();
return this;
}
public JSONPrinter endArray() {
writer.endArray();
return this;
}
public void ifFalse(String key, Boolean value) {
if (value != null && !value) {
writer.key(key);
writer.value(value);
}
}
public void printSchemaMap(Map input) {
object();
input.entrySet().forEach(entry -> {
key(entry.getKey().toString());
entry.getValue().describeTo(this);
});
endObject();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy