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

io.descoped.dc.api.node.builder.ProcessBuilder Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package io.descoped.dc.api.node.builder;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.descoped.dc.api.Processor;
import io.descoped.dc.api.node.Base;
import io.descoped.dc.api.node.Configurations;
import io.descoped.dc.api.node.Node;
import io.descoped.dc.api.node.Process;

import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

@JsonDeserialize(using = NodeBuilderDeserializer.class)
public class ProcessBuilder extends NodeBuilder {

    @JsonProperty
    Class processorClass;
    @JsonProperty
    Set requiredOutputs = new LinkedHashSet<>();

    public ProcessBuilder(Class processorClass) {
        super(BuilderType.Process);
        this.processorClass = processorClass;
    }

    public ProcessBuilder output(String variable) {
        requiredOutputs.add(variable);
        return this;
    }

    @SuppressWarnings("unchecked")
    @Override
     R build(BuildContext buildContext) {
        return (R) new ProcessNode(buildContext.getInstance(SpecificationBuilder.GLOBAL_CONFIGURATION), processorClass, requiredOutputs);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        ProcessBuilder that = (ProcessBuilder) o;
        return processorClass.equals(that.processorClass) &&
                Objects.equals(requiredOutputs, that.requiredOutputs);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), processorClass, requiredOutputs);
    }

    @Override
    public String toString() {
        return "ProcessBuilder{" +
                "processorClass=" + processorClass +
                ", requiredOutputs=" + requiredOutputs +
                '}';
    }

    static class ProcessNode extends FlowNode implements Process {

        final Class processorClass;
        final Set requiredOutputs;

        ProcessNode(Configurations configurations, Class processorClass, Set requiredOutputs) {
            super(configurations);
            this.processorClass = processorClass;
            this.requiredOutputs = requiredOutputs;
        }

        @Override
        public Class processorClass() {
            return processorClass;
        }

        @Override
        public Set requiredOutputs() {
            return requiredOutputs;
        }

        @Override
        public Iterator iterator() {
            return createNodeList().iterator();
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            ProcessNode that = (ProcessNode) o;
            return processorClass.equals(that.processorClass) &&
                    Objects.equals(requiredOutputs, that.requiredOutputs);
        }

        @Override
        public int hashCode() {
            return Objects.hash(processorClass, requiredOutputs);
        }

        @Override
        public String toString() {
            return "ProcessNode{" +
                    "processorClass=" + processorClass +
                    ", requiredOutputs=" + requiredOutputs +
                    '}';
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy