blob: 7353bfe5c8387f6c2df477942c5a38041dd09066 (
plain) (
blame)
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
|
package hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft
import com.google.common.collect.Maps
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.CftFactory
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentDefinition
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentFaultTree
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.EventDeclaration
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.InputEvent
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Output
import java.util.Map
class ComponentInstanceTrace {
val componentInstance = CftFactory.eINSTANCE.createComponent
val Map<InputEvent, InputTrace> inputEventsMap
val Map<EventDeclaration, Output> outputEventsMap
protected new(ComponentFaultTree faultTree, ComponentDefinition componentDefinition,
ComponentNameGenerator nameGenerator) {
componentInstance.componentDefinition = componentDefinition
componentInstance.name = nameGenerator.nextName(componentDefinition)
inputEventsMap = Maps.newHashMapWithExpectedSize(componentDefinition.inputEvents.size)
for (inputEvent : componentDefinition.inputEvents) {
val inputTrace = new InputTrace(componentInstance, inputEvent)
inputEventsMap.put(inputEvent, inputTrace)
}
outputEventsMap = Maps.newHashMapWithExpectedSize(componentDefinition.outputEvents.size)
for (outputEvent : componentDefinition.outputEvents) {
val output = CftFactory.eINSTANCE.createOutput
output.eventDeclaration = outputEvent
componentInstance.outputs += output
outputEventsMap.put(outputEvent, output)
}
faultTree.components += componentInstance
}
def void assign(EventDeclaration inputEvent, ComponentInstanceTrace sourceComponent, EventDeclaration outputEvent) {
val inputTrace = inputEventsMap.get(inputEvent)
if (inputTrace === null) {
throw new IllegalArgumentException("Unknown input: " + inputEvent)
}
val output = sourceComponent.outputEventsMap.get(outputEvent)
if (output === null) {
throw new IllegalArgumentException("Unknown output: " + outputEvent)
}
inputTrace.assign(output)
}
protected def getOutputs() {
componentInstance.outputs
}
}
|