From eab6df10ab8292a59a05b25d18c413dd107bb94a Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Thu, 26 Apr 2018 05:48:09 -0700 Subject: Initial commit --- src/bjc/imgchain/pipeline/MutablePipeline.java | 102 +++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/bjc/imgchain/pipeline/MutablePipeline.java (limited to 'src/bjc/imgchain/pipeline/MutablePipeline.java') diff --git a/src/bjc/imgchain/pipeline/MutablePipeline.java b/src/bjc/imgchain/pipeline/MutablePipeline.java new file mode 100644 index 0000000..6272b30 --- /dev/null +++ b/src/bjc/imgchain/pipeline/MutablePipeline.java @@ -0,0 +1,102 @@ +package bjc.imgchain.pipeline; + +import java.awt.Image; +import java.util.ArrayList; +import java.util.List; + +/** + * An editable {@link Pipeline} + * + * @author acm + * + */ +public class MutablePipeline implements Pipeline { + private final List stages; + + private String name; + + /** + * Create a new unnamed mutable pipeline. + */ + public MutablePipeline() { + stages = new ArrayList<>(); + + name = "Unnamed Pipeline"; + } + + /** + * Create a new named mutable pipeline. + * + * @param name + * The name of the pipeline. + */ + public MutablePipeline(String name) { + stages = new ArrayList<>(); + + this.name = name; + } + + @Override + public Image process(Image input) { + Image proc = input; + + for (PipelineStage stage : stages) { + System.out.println("Applying stage " + stage.name()); + proc = stage.process(proc); + System.out.println("Applied stage " + stage.name()); + } + + return proc; + } + + @Override + public List stages() { + return stages; + } + + @Override + public String name() { + return name; + } + + /** + * Set the name of the pipeline. + * + * @param nam + * The name of the pipeline. + */ + public void name(String nam) { + name = nam; + } + + /** + * Append a pipeline stage to the end of this pipeline. + * + * @param stag + * The stage to add. + */ + public void addStage(PipelineStage stag) { + stages.add(stag); + } + + /** + * Remove a pipeline stage. + * + * @param stag + * The stage to remove. + */ + public void removeStage(PipelineStage stag) { + stages.remove(stag); + } + + /** + * Remove a pipeline stage by index. + * + * @param idx + * The index of the stage to remove. + */ + public void removeStage(int idx) { + stages.remove(idx); + } + +} -- cgit v1.2.3