States, Events, Actions
This is a library to expose DSL, which can be used to create State machines.
We have 3 States PAST, PRESENT, FUTURE. These can be represented as plain simple Strings:
static final class State {
public static final String PAST = "Past";
public static final String PRESENT = "Present";
public static final String FUTURE = "Future";
}
There are 4 actions that let you change from one state to another:
static final class Action {
public static final String FORWARD = "Forward";
public static final String BACKWARD = "Backward";
public static final String FAST_FORWARD = "FastForward";
public static final String FAST_BACKWARD = "FastBackward";
}
Now weave these States and Actions into a Graph using this DSL:
final Hydra<String, String, ?> timeMachine = Hydra.create(mb -> {
mb.initialState(PRESENT);
mb.state(PRESENT, String.class, sb -> {
sb.on(FORWARD, String.class, (currentState, action) -> sb.transitionTo(FUTURE));
sb.on(BACKWARD, String.class, (currentState, action) -> sb.transitionTo(PAST));
});
mb.state(FUTURE, String.class, sb -> {
sb.on(BACKWARD, String.class, (currentState, action) -> sb.transitionTo(PRESENT));
sb.on(FAST_BACKWARD, String.class, (currentState, action) -> sb.transitionTo(PAST));
});
mb.state(PAST, String.class, sb -> {
sb.on(FORWARD, String.class, (currentState, action) -> sb.transitionTo(PRESENT));
sb.on(FAST_FORWARD, String.class, (currentState, action) -> sb.transitionTo(FUTURE));
});
});
Refer to these applications for full-blown apps using this library:
-
This CONTRIBUTING doc has all the information to set up this library on your local and get hands-on.
-
Any issues or PRs are welcome!
♥️ -
Join this Slack Community to discuss issues or PRs related to Consumption-Collaboration-Contribution