-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCollector.xtend
More file actions
48 lines (38 loc) · 1.32 KB
/
Collector.xtend
File metadata and controls
48 lines (38 loc) · 1.32 KB
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
package de.grammarcraft.xtend.annotatedflow
import de.grammarcraft.xtend.flow.annotations.FunctionUnit
import java.util.List
import java.util.ArrayList
import de.grammarcraft.xtend.flow.annotations.InputPort
import de.grammarcraft.xtend.flow.annotations.OutputPort
@FunctionUnit(
inputPorts = #[
@InputPort(name="lower", type=String),
@InputPort(name="upper", type=String)
],
outputPorts = #[
@OutputPort(name="output", type=String),
@OutputPort(name="error", type=String)
]
)
class Collector {
new(String separator) {
this.separator = separator;
}
override processLower(String msg) {
if (accumulation.length >= 2)
error.forward(this + ' got more than two input messages; not allowed')
accumulateInput(msg)
}
override processUpper(String msg) {
if (accumulation.length >= 2)
error.forward(this + ' got more than two input messages; not allowed')
accumulateInput(msg)
}
var String separator
val List<String> accumulation = new ArrayList
// This method implements the semantic of the function unit
private def accumulateInput(String msg) {
accumulation.add(msg)
if (accumulation.length == 2) output.forward(accumulation.join(separator))
}
}