forked from SysMLinJavaModeler/SysMLinJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSysMLTransition.java
More file actions
347 lines (333 loc) · 15.2 KB
/
Copy pathSysMLTransition.java
File metadata and controls
347 lines (333 loc) · 15.2 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
package sysmlinjava.statemachine;
import java.util.Optional;
import sysmlinjava.blocks.SysMLBlock;
import sysmlinjava.common.SysMLClass;
import sysmlinjava.events.SysMLEvent;
import sysmlinjava.events.SysMLSignalEvent;
/**
* SysMLinJava's representation of the SysML state machine's transition. The
* SysMLTransition defines the trigger, guard, and effect of a transition
* between specified states or within a state.
* <p>
* The SysMLTransition automatically adds itself to it's previous state, i.e.
* the state it is to transition from. It also provides a boolean
* {@code guardConditionSatisfied()} operation that determines if the transition
* is enabled under the current trigger and other conditions. The
* SysMLStateMachine uses this transition membership in the state and the
* {@code guardConditionSatisfied()} operation to determine which, if any,
* transition to use to transition the state machine to the next state. An
* example follows.
*
* <pre>{@code
:
@Transition
public InitialTransition initialTransition;
@Transition
public SysMLTransition initialAsGasTransition;
@Transition
public SysMLTransition initialAsLiquidTransition;
@Transition
public SysMLTransition initialAsIceTransition;
@Transition
public SysMLTransition gasToLiquidTransition;
@Transition
public SysMLTransition liquidToIceTransition;
@Transition
public SysMLTransition iceToLiquidTransition;
@Transition
public SysMLTransition liquidToGasTransition;
@Transition
public SysMLTransition gasToDecomposedTransition;
@Transition
public SysMLTransition decomposedToFinalTransition;
:
@Override
protected void createTransitions()
{
super.createTransitions();
initialTransition = new InitialTransition(contextBlock, initialState, choice, "initial");
initialAsGasTransition = new SysMLTransition(contextBlock, choice, gas, Optional.of(initialAsGasGuard), Optional.empty(), "InitialAsGas");
initialAsLiquidTransition = new SysMLTransition(contextBlock, choice, liquid, Optional.of(initialAsLiquidGuard), Optional.empty(), "InitialAsLiquid");
initialAsIceTransition = new SysMLTransition(contextBlock, choice, ice, Optional.of(initialAsIceGuard), Optional.empty(), "InitialAsIce");
gasToLiquidTransition = new SysMLTransition(contextBlock, gas, liquid, Optional.of(TempChangeEvent.class), Optional.of(gasToLiquidGuard), Optional.empty(), "GasToLiquid", SysMLTransitionKind.external);
liquidToIceTransition = new SysMLTransition(contextBlock, liquid, ice, Optional.of(TempChangeEvent.class), Optional.of(liquidToIceGuard), Optional.empty(), "LiquidToIce", SysMLTransitionKind.external);
iceToLiquidTransition = new SysMLTransition(contextBlock, ice, liquid, Optional.of(TempChangeEvent.class), Optional.of(iceToLiquidGuard), Optional.empty(), "IceToLiquid", SysMLTransitionKind.external);
liquidToGasTransition = new SysMLTransition(contextBlock, liquid, gas, Optional.of(TempChangeEvent.class), Optional.of(liquidToGasGuard), Optional.empty(), "LiquidToGas", SysMLTransitionKind.external);
gasToDecomposedTransition = new SysMLTransition(contextBlock, gas, decomposed, Optional.of(TempChangeEvent.class), Optional.of(gasToDecomposedGuard), Optional.empty(), "GasToDecomposed", SysMLTransitionKind.external);
decomposedToFinalTransition = new FinalTransition(contextBlock, decomposed, finalState, "DecomposedToFinal");
}
}
* </pre>
*
* @author ModelerOne
*/
public class SysMLTransition extends SysMLClass
{
/**
* Optional block in whose context the transition resides
*/
public Optional<? extends SysMLBlock> contextBlock;
/**
* Vertex representing the previous (source) state of the transition
*/
public SysMLVertex prevState;
/**
* Vertex representing the next (destination) state of the transition
*/
public SysMLVertex nextState;
/**
* Optional event representing the trigger for the transition
*/
public Optional<Class<? extends SysMLEvent>> trigger;
/**
* Optional guard whose condition will enable or disable the transition
*/
public Optional<? extends SysMLGuard> guard;
/**
* Optional effect to be invoked upon performance of the transition
*/
public Optional<? extends SysMLEffect> effect;
/**
* The kind of transition
*/
public SysMLTransitionKind transitionKind;
/**
* Constructor for maximum specification from state to state, i.e. optionally
* specified triggering event, guard, and effect. The transition kind is also
* specified.
*
* @param contextBlock Optional SysMLBlock that provides the context of the
* state machine
* @param prevState The previous state of the transition, i.e. state to be
* transitioned from.
* @param nextState The next state of the transition, i.e. state to be
* transitioned to.
* @param trigger Optional trigger for the transition, i.e. the type of
* SysMLEvent that will trigger transition.
* @param guard Optional guard for the transition, i.e. the condition
* to be satisfied to allow the transition.
* @param effect Optional effect of the transition, i.e. the activity to
* be performed upon performance of the transition.
* @param name The transition's name
* @param transitionKind The kind of transition, i.e. internal or external
*/
public SysMLTransition(Optional<? extends SysMLBlock> contextBlock, SysMLState prevState, SysMLState nextState, Optional<Class<? extends SysMLEvent>> trigger, Optional<SysMLGuard> guard, Optional<SysMLEffect> effect, String name, SysMLTransitionKind transitionKind)
{
super();
this.contextBlock = contextBlock;
this.prevState = prevState;
this.prevState.addTransition(this);
this.nextState = nextState;
this.trigger = trigger;
this.guard = guard;
this.effect = effect;
this.name = Optional.of(name);
this.transitionKind = transitionKind;
}
/**
* Constructor for maximum specification from state to pseudo-state, i.e.
* optionally specified triggering event, guard, and effect. The transition kind
* is also specified.
*
* @param contextBlock Optional SysMLBlock that provides the context of the
* state machine
* @param prevState The previous state of the transition, i.e. state to be
* transitioned from.
* @param nextState The next (pseudo)state of the transition, i.e.
* pseudo-state to be transitioned to.
* @param trigger Optional trigger for the transition, i.e. the type of
* SysMLEvent that will trigger transition.
* @param guard Optional guard for the transition, i.e. the condition to
* be satisfied to allow the transition.
* @param effect Optional effect of the transition, i.e. the activity to
* be performed upon performance of the transition.
* @param name The transition's name
*/
public SysMLTransition(Optional<? extends SysMLBlock> contextBlock, SysMLState prevState, SysMLPseudoState nextState, Optional<Class<? extends SysMLEvent>> trigger, Optional<SysMLGuard> guard, Optional<SysMLEffect> effect, String name)
{
super();
this.contextBlock = contextBlock;
this.prevState = prevState;
this.prevState.addTransition(this);
this.nextState = nextState;
this.trigger = trigger;
this.guard = guard;
this.effect = effect;
this.name = Optional.of(name);
this.transitionKind = SysMLTransitionKind.external;
}
/**
* Constructor for maximum specification from pseudo-state to state, i.e.
* optionally specified triggering event, guard, and effect. The transition kind
* is also specified.
*
* @param contextBlock Optional SysMLBlock that provides the context of the
* state machine
* @param prevState The previous (pseudo)state of the transition, i.e.
* pseudo-state to be transitioned from.
* @param nextState The next state of the transition, i.e. state to be
* transitioned to.
* @param guard Optional guard for the transition, i.e. the condition to
* be satisfied to allow the transition.
* @param effect Optional effect of the transition, i.e. the activity to
* be performed upon performance of the transition.
* @param name The transition's name
*/
public SysMLTransition(Optional<? extends SysMLBlock> contextBlock, SysMLPseudoState prevState, SysMLState nextState, Optional<SysMLGuard> guard, Optional<SysMLEffect> effect, String name)
{
super();
this.contextBlock = contextBlock;
this.prevState = prevState;
this.prevState.addTransition(this);
this.nextState = nextState;
this.trigger = Optional.empty();
this.guard = guard;
this.effect = effect;
this.name = Optional.of(name);
this.transitionKind = SysMLTransitionKind.external;
}
/**
* Constructor for maximum specification from pseudo-state to pseudo-state, i.e.
* optionally guard, and effect (no trigger event). specified.
*
* @param contextBlock Optional SysMLBlock that provides the context of the
* state machine
* @param prevState The previous (pseudo)state of the transition, i.e.
* pseudo-state to be transitioned from.
* @param nextState The next state of the transition, i.e. state to be
* transitioned to.
* @param guard Optional guard for the transition, i.e. the condition to
* be satisfied to allow the transition.
* @param effect Optional effect of the transition, i.e. the activity to
* be performed upon performance of the transition.
* @param name The transition's name
*/
public SysMLTransition(Optional<? extends SysMLBlock> contextBlock, SysMLPseudoState prevState, SysMLPseudoState nextState, Optional<SysMLGuard> guard, Optional<SysMLEffect> effect, String name)
{
super();
this.contextBlock = contextBlock;
this.prevState = prevState;
this.prevState.addTransition(this);
this.nextState = nextState;
this.trigger = Optional.empty();
this.guard = guard;
this.effect = effect;
this.name = Optional.of(name);
this.transitionKind = SysMLTransitionKind.external;
}
/**
* Constructor for specification from initial state to state, i.e. optionally
* specified effect, but no trigger event nor guard. specified.
*
* @param contextBlock Optional SysMLBlock that provides the context of the
* state machine
* @param prevState The initial state of the transition, i.e. initial state
* to be transitioned from.
* @param nextState The next state of the transition, i.e. state to be
* transitioned to.
* @param effect Optional effect of the transition, i.e. the activity to
* be performed upon performance of the transition.
* @param name The transition's name
*/
public SysMLTransition(Optional<? extends SysMLBlock> contextBlock, SysMLInitialState prevState, SysMLState nextState, Optional<SysMLEffect> effect, String name)
{
super();
this.contextBlock = contextBlock;
this.prevState = prevState;
this.prevState.addTransition(this);
this.nextState = nextState;
this.trigger = Optional.empty();
this.guard = Optional.empty();
this.effect = effect;
this.name = Optional.of(name);
this.transitionKind = SysMLTransitionKind.external;
}
/**
* Constructor for specification from initial state to a pseudo-state, i.e.
* optionally specified effect, but no trigger event nor guard. specified.
*
* @param contextBlock Optional SysMLBlock that provides the context of the
* state machine
* @param prevState The initial state of the transition, i.e. initial state
* to be transitioned from.
* @param nextState The next (pseudo) state of the transition, i.e.
* pseudo-state to be transitioned to.
* @param effect Optional effect of the transition, i.e. the activity to
* be performed upon performance of the transition.
* @param name The transition's name
*/
public SysMLTransition(Optional<? extends SysMLBlock> contextBlock, SysMLInitialState prevState, SysMLPseudoState nextState, Optional<SysMLEffect> effect, String name)
{
super();
this.contextBlock = contextBlock;
this.prevState = prevState;
this.prevState.addTransition(this);
this.nextState = nextState;
this.trigger = Optional.empty();
this.guard = Optional.empty();
this.effect = effect;
this.name = Optional.of(name);
this.transitionKind = SysMLTransitionKind.external;
}
/**
* Constructor for automatic transition, i.e. the transition occurs without a
* trigger or guard condition. The transition kind is defaulted to "external".
*
* @param contextBlock Optional SysMLBlock that provides the context of the
* state machine
* @param prevState The previous state of the transition, i.e. state to be
* transitioned from.
* @param nextState The next state of the transition, i.e. state to be
* transitioned to.
* @param name The transition's name
*/
public SysMLTransition(Optional<? extends SysMLBlock> contextBlock, SysMLState prevState, SysMLState nextState, String name)
{
super();
this.contextBlock = contextBlock;
this.prevState = prevState;
this.prevState.addTransition(this);
this.nextState = nextState;
this.trigger = Optional.empty();
this.guard = Optional.empty();
this.effect = Optional.empty();
this.name = Optional.of(name);
this.transitionKind = SysMLTransitionKind.external;
}
/**
* Boolean operation indicating whether the transition's guard condition is
* satisfied for the current event.
*
* @param currentEvent The current event.
* @return Whether the guard condition is satisfied for the current event.
*/
public boolean guardConditionSatisfied(Optional<? extends SysMLSignalEvent> currentEvent)
{
boolean result = true;
if (trigger.isPresent())
if (guard.isPresent())
result = (currentEvent.getClass().equals(trigger.get())) && guard.get().isSatisfied(currentEvent);
else
result = (currentEvent.getClass().equals(trigger.get()));
else if (guard.isPresent())
result = guard.get().isSatisfied(currentEvent);
return result;
}
/**
* Returns the identity string for this transition. The identity string is
* either the optional name set via the constructor or, if not set, the name of
* the transition class.
*
* @return The transitions identity String
*/
public String identityString()
{
return name.isPresent() ? name.get() : getClass().getSimpleName();
}
@Override
public String toString()
{
return String.format("SysMLTransition [contextBlock=%s, trigger=%s, guard=%s, effect=%s, prevState=%s, nextState=%s, transitionKind=%s, name=%s, id=%s]", contextBlock, trigger, guard, effect, prevState, nextState, transitionKind,
name, id);
}
}