Class StateMachine<T>
- java.lang.Object
-
- io.github.frc5024.libkontrol.statemachines.StateMachine<T>
-
public class StateMachine<T> extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description java.util.HashMap<T,StateHandler<T>>
allStates
T
defaultStateKey
T
desiredStateKey
T
lastStateKey
-
Constructor Summary
Constructors Constructor Description StateMachine(java.lang.String name)
Create a StateMachine
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addState(T key, java.util.function.Consumer<StateMetadata<T>> action)
Add a state to the StateMachineT
getCurrentState()
Get the system's current statevoid
removeState(T key)
Remove a state from the StateMachinevoid
setConsoleHook(java.util.function.Consumer<java.lang.String> hook)
Deprecated, for removal: This API element is subject to removal in a future version.void
setDefaultState(T key, java.util.function.Consumer<StateMetadata<T>> action)
Add a state to the StateMachine, and set it as the default.void
setState(T key)
Set the StateMachine's statevoid
update()
Update the machine.
-
-
-
Method Detail
-
setConsoleHook
@Deprecated(since="July 2020", forRemoval=true) public void setConsoleHook(@Nullable java.util.function.Consumer<java.lang.String> hook)
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated Method- Parameters:
hook
- hook
-
addState
public void addState(T key, java.util.function.Consumer<StateMetadata<T>> action)
Add a state to the StateMachine- Parameters:
key
- State keyaction
- Action to be run
-
setDefaultState
public void setDefaultState(T key, java.util.function.Consumer<StateMetadata<T>> action)
Add a state to the StateMachine, and set it as the default. This state will be called upon any error in state handling, or when no state is set.- Parameters:
key
- State keyaction
- Action to be run
-
removeState
public void removeState(T key)
Remove a state from the StateMachine- Parameters:
key
- State key
-
update
public void update()
Update the machine. This MUST be called periodically
-
setState
public void setState(T key)
Set the StateMachine's state- Parameters:
key
- State key
-
getCurrentState
@Nullable public T getCurrentState()
Get the system's current state- Returns:
- current state
-
-