123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- package org.yakindu.sct.runtime.java.custom;
- import java.util.Collection;
- import java.util.EnumSet;
- import java.util.Set;
- import org.yakindu.sct.runtime.java.base.DataType;
- import org.yakindu.sct.runtime.java.base.IStatemachine;
- public abstract class ExampleAbstractBaseStatemachine implements IStatemachine {
- public enum Event {
-
- e1,
-
- e2,
-
- e3,
-
- e4,
-
- e5,
-
- e6,
-
- i1,
-
- };
- public enum State {
- S1,
- S2,
- S3,
- S4,
-
- };
- private Set<State> activeStates = EnumSet.noneOf(State.class);
-
- private bool condition_S1_tr0(Collection<Event> occuredEvents) {
- return ( eventSet.check( ev_e1) );
- }
-
-
- private bool condition_S2_tr0(Collection<Event> occuredEvents) {
- return ( eventSet.check( ev_e2) );
- }
-
-
- private bool condition_S3_tr0(Collection<Event> occuredEvents) {
- return ( eventSet.check( ev_e3) );
- }
-
-
- private bool condition_S4_tr0(Collection<Event> occuredEvents) {
- return ( eventSet.check( ev_e4) );
- }
-
-
- private void actions_S1_tr0() {
-
-
- activeStates.remove(S1);
- activeStates.add(S2);
- }
-
-
- private void actions_S2_tr0() {
-
-
- activeStates.remove(S2);
- activeStates.add(S1);
- }
-
-
- private void actions_S3_tr0() {
-
-
- activeStates.remove(S3);
- activeStates.add(S4);
- }
-
-
- private void actions_S4_tr0() {
-
-
- activeStates.remove(S4);
- activeStates.add(S3);
- }
-
- private void cycle_S1(Collection<Event> occuredEvents)
- {
-
- if ( condition_S1_tr0(Collection<Event> occuredEvents) ) {
-
- actions_S1_tr0();
- }
- else {
-
- }
- }
- private void cycle_S2(Collection<Event> occuredEvents)
- {
-
- }
- private void cycle_S3(Collection<Event> occuredEvents)
- {
-
- if ( condition_S3_tr0(Collection<Event> occuredEvents) ) {
-
- actions_S3_tr0();
- }
- else {
-
- }
- }
- private void cycle_S4(Collection<Event> occuredEvents)
- {
-
- if ( condition_S4_tr0(Collection<Event> occuredEvents) ) {
-
- actions_S4_tr0();
- }
- else {
-
- }
- }
-
- public void init() {
-
- activeStates.add(S1);
- }
-
- protected abstract Collection<Event> getOccuredEvents();
- public void raiseEvent(DataType event) {
- getOccuredEvents().add(Event.valueOf(event.getName()));
- }
- public boolean eventOccured(DataType event) {
- return getOccuredEvents().contains(Event.valueOf(event.getName()));
- }
- public boolean eventOccured() {
- return !getOccuredEvents().isEmpty();
- }
- public void runCycle(Collection<Event> events) {
- for (State state : activeStates) {
- switch (state) {
-
- case S1:
- cycle_S1(events);
- break;
-
- case S2:
- cycle_S2(events);
- break;
-
- case S3:
- cycle_S3(events);
- break;
-
- case S4:
- cycle_S4(events);
- break;
-
- default:
- // no state found
- }
- }
- }
- }
|