All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hydra.dsl.ModuleBuilder Maven / Gradle / Ivy

There is a newer version: 0.8.0
Show newest version
package hydra.dsl;

import hydra.core.FieldType;
import hydra.core.RowType;
import hydra.core.Type;
import hydra.graph.Element;
import hydra.module.Module;
import hydra.module.Namespace;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import hydra.util.Opt;

import static hydra.dsl.Modules.element;
import static hydra.dsl.Modules.qname;


public class ModuleBuilder {
    private final Namespace namespace;
    private final Opt description;
    private final List elements = new ArrayList();

    public ModuleBuilder(Namespace namespace, Opt description) {
        this.namespace = namespace;
        this.description = description;
    }

    public ModuleBuilder(Namespace namespace, String description) {
        this(namespace, Opt.of(description));
    }

    public ModuleBuilder(Namespace namespace) {
        this(namespace, Opt.empty());
    }

    public ModuleBuilder(String namespace) {
        this(new Namespace(namespace));
    }

    public ModuleBuilder(String namespace, String description) {
        this(new Namespace(namespace), description);
    }

    public ModuleBuilder recordType(String localName, FieldType... fields) {
        return type(localName, new Type.Record(
                new RowType(qname(namespace, localName), Arrays.asList(fields))));
    }

    public ModuleBuilder type(String localName, Type type) {
        elements.add(element(qname(namespace, localName), type));
        return this;
    }

    public ModuleBuilder unionType(String localName, FieldType... fields) {
        return type(localName, new Type.Union(
                new RowType(qname(namespace, localName), Arrays.asList(fields))));
    }

    public Module build() {
        return new Module(namespace, elements, Collections.emptyList(), Collections.emptyList(), description);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy