move files into modules
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package click.kamil.examples.statemachine.dynamic;
|
||||
|
||||
import org.springframework.statemachine.StateMachine;
|
||||
import org.springframework.statemachine.config.StateMachineBuilder;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class DynamicStateMachineExample {
|
||||
|
||||
public enum States {
|
||||
DRAFT, REVIEW, APPROVED
|
||||
}
|
||||
|
||||
public enum Events {
|
||||
SUBMIT, APPROVE
|
||||
}
|
||||
|
||||
public static StateMachine<States, Events> buildStateMachine() throws Exception {
|
||||
StateMachineBuilder.Builder<States, Events> builder = StateMachineBuilder.builder();
|
||||
|
||||
builder.configureStates()
|
||||
.withStates()
|
||||
.initial(States.DRAFT)
|
||||
.end(States.REVIEW)
|
||||
.states(EnumSet.allOf(States.class));
|
||||
|
||||
builder.configureTransitions()
|
||||
.withExternal()
|
||||
.source(States.DRAFT).target(States.REVIEW).event(Events.SUBMIT)
|
||||
.and()
|
||||
.withExternal()
|
||||
.source(States.REVIEW).target(States.APPROVED).event(Events.APPROVE);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
StateMachine<States, Events> sm = buildStateMachine();
|
||||
|
||||
sm.start();
|
||||
System.out.println("Current State: " + sm.getState().getId());
|
||||
|
||||
sm.sendEvent(Events.SUBMIT);
|
||||
System.out.println("After SUBMIT: " + sm.getState().getId());
|
||||
|
||||
sm.sendEvent(Events.APPROVE);
|
||||
System.out.println("After APPROVE: " + sm.getState().getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package click.kamil.examples.statemachine.dynamic.app;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
class StateMachineApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(StateMachineApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
spring.application.name=statemachinedemo
|
||||
@@ -0,0 +1,11 @@
|
||||
package click.kamil.examples.statemachine;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MyTest {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user