blob: ddf2c266cd2f0467eb991179a3d4bc8f63bd3d3e (
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
|
package hu.bme.mit.inf.dslreasoner.faulttree.model.util
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Component
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Connection
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ModalElement
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Modality
final class CftExtensions {
private new() {
throw new IllegalStateException("This is a static utility class and should not be instantiated directly.")
}
static def isMoreConcreteThan(Modality newModality, Modality original) {
switch (original) {
case MAY: newModality != Modality.MAY
case CURRENT: newModality == Modality.MUST
case MUST: false
}
}
static def currentlyExists(ModalElement element) {
element.exists != Modality.MAY
}
static def mustExist(ModalElement element) {
element.exists == Modality.MUST
}
static def appearsExactlyOnce(Component componentInstance) {
componentInstance.mustExist && !componentInstance.multipleAllowed
}
/**
* Checks whether the connection and its target component are both currently present.
*
* A currently present connection without a present target component is a partial model error,
* so we throw an exception instead of returning <code>false</code>.
*
* @param connection The connection to check.
* @throws IllegalStateException When the target component is not currently present.
*/
static def isCurrentlyConnected(Connection connection) {
if (connection.output.component.currentlyExists) {
throw new IllegalStateException("Inconsistent partial model: current connection to a component that may not currently exist")
}
connection.currentlyExists
}
}
|