summaryrefslogtreecommitdiff
path: root/src/bjc/imgchain/pipeline/MutablePipeline.java
blob: 6272b3006b24ca13cfabb86037dbca850d998bf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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<PipelineStage> 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<PipelineStage> 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);
	}

}