diff --git a/controls/src/main/java/state_machine/State/StateConfiguration.java b/controls/src/main/java/state_machine/State/StateConfiguration.java index cbb156f..0a42c84 100644 --- a/controls/src/main/java/state_machine/State/StateConfiguration.java +++ b/controls/src/main/java/state_machine/State/StateConfiguration.java @@ -100,6 +100,12 @@ public void runOnExit(Transition transition) { } } + public void runTransition(Transition transition) { + if (transitionAction != null) { + transitionAction.accept(transition); + } + } + public StateConfiguration disableDefaultTransitionAction(){ this.runDefaultTransitionAction = false; return this; diff --git a/controls/src/main/java/state_machine/StateMachine.java b/controls/src/main/java/state_machine/StateMachine.java index 9f4b678..7ebabe9 100644 --- a/controls/src/main/java/state_machine/StateMachine.java +++ b/controls/src/main/java/state_machine/StateMachine.java @@ -53,4 +53,8 @@ public boolean successfulTransition() { public TransitionInfo getTransitionInfo() { return transitionInfo; } + + public boolean inState(State state){ + return currentState.equals(state); + } } diff --git a/controls/src/main/java/state_machine/StateMachineConfiguration.java b/controls/src/main/java/state_machine/StateMachineConfiguration.java index 884b30f..c9ada58 100644 --- a/controls/src/main/java/state_machine/StateMachineConfiguration.java +++ b/controls/src/main/java/state_machine/StateMachineConfiguration.java @@ -3,13 +3,13 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; -import java.util.function.Consumer; +import java.util.function.BiConsumer; public class StateMachineConfiguration { private Map> stateConfigurations; - private Consumer onEntryAction; - private Consumer onExitAction; - private Consumer transitionAction; + private BiConsumer onEntryAction; + private BiConsumer onExitAction; + private BiConsumer transitionAction; public StateMachineConfiguration() { // temp solution @@ -54,17 +54,17 @@ public Optional> getTransition(State state, Trigger t return transition; } - public StateMachineConfiguration configureOnEntryAction(Consumer action){ + public StateMachineConfiguration configureDefaultOnEntryAction(BiConsumer action){ this.onEntryAction = action; return this; } - public StateMachineConfiguration configureOnExitAction(Consumer action){ + public StateMachineConfiguration configureDefaultOnExitAction(BiConsumer action){ this.onExitAction = action; return this; } - public StateMachineConfiguration configureTransitionAction(Consumer action){ + public StateMachineConfiguration configureDefaultTransitionAction(BiConsumer action){ this.transitionAction = action; return this; } diff --git a/controls/src/test/java/StateContainerStateMachineTests.java b/controls/src/test/java/StateContainerStateMachineTests.java index 71fe881..663cb7f 100644 --- a/controls/src/test/java/StateContainerStateMachineTests.java +++ b/controls/src/test/java/StateContainerStateMachineTests.java @@ -1,14 +1,12 @@ package coppercore.controls.test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import coppercore.controls.PeriodicStateInterface; import coppercore.controls.StateContainer; import coppercore.controls.StateMachine; import coppercore.controls.StateMachineConfiguration; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import coppercore.controls.StateInterface; import coppercore.controls.Transition; public class StateContainerStateMachineTests { @@ -75,8 +73,8 @@ public static void setup() { stateContainerTestMachineConfig = new StateMachineConfiguration<>(); stateContainerTestMachineConfig - .configureDefaultEntryAction((testStateContainer state, Transition transition) -> state.onEntry(transition)); - .configureDefaultTransitionAction((testStateContainer state, Transition transition) -> state.onEntry(transition)); + .configureDefaultOnEntryAction((testStateContainer state, Transition transition) -> state.getState().onEntry(transition)) + .configureDefaultTransitionAction((testStateContainer state, Transition transition) -> state.getState().onEntry(transition)); //stateContainerTestMachineConfig