ioinformarics.oss.jackson.module.jsonld.JsonldGraphBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-jsonld Show documentation
Show all versions of jackson-jsonld Show documentation
JSON-LD Module for Jackson
The newest version!
package ioinformarics.oss.jackson.module.jsonld;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.TextNode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Function;
/**
* @author Alexander De Leon
*/
public class JsonldGraphBuilder {
protected String context;
protected String graphType;
protected String graphId;
protected JsonldResourceBuilder resourceBuilder;
protected Function typeSupplier;
JsonldGraphBuilder() {
resourceBuilder = new JsonldResourceBuilder();
}
public JsonldGraphBuilder context(String context){
this.context = context;
return this;
}
public JsonldGraphBuilder type(String type){
this.graphType = type;
return this;
}
public JsonldGraphBuilder id(String id){
this.graphId = id;
return this;
}
public JsonldGraphBuilder elementId(Function idSupplier){
this.resourceBuilder.id(idSupplier);
return this;
}
public JsonldGraphBuilder elementType(Function typeSupplier){
this.typeSupplier = typeSupplier;
return this;
}
public JsonldResource build(T ... elements) {
return build(Arrays.asList(elements));
}
public JsonldResource build(Iterable elements) {
return new JsonldGraph(elements, Optional.ofNullable(context).map(c -> TextNode.valueOf(c)).orElse(null), graphType, graphId);
}
protected String getType(T e) {
return typeSupplier.apply(e);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy