File tree Expand file tree Collapse file tree 4 files changed +13
-8
lines changed Expand file tree Collapse file tree 4 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -7,10 +7,9 @@ class Fsm(
7
7
) {
8
8
9
9
companion object {
10
- @JvmStatic
11
- fun create (initialState : String , xxx : FsmSpec .() -> FsmSpec ): Fsm {
10
+ fun create (initialState : String , fsmRecipe : FsmSpec .() -> FsmSpec ): Fsm {
12
11
return FsmSpec (initialState = initialState)
13
- .xxx ()
12
+ .fsmRecipe ()
14
13
.build()
15
14
}
16
15
}
Original file line number Diff line number Diff line change 1
1
package dsl
2
2
3
3
class FsmSpec (
4
- private val transitions : MutableList <TransitionSpec .() - > TransitionSpec > = mutableListOf(),
4
+ private val transitions : MutableList <Transition > = mutableListOf(),
5
5
val initialState : String
6
6
) {
7
7
8
8
fun add (transitionRecipe : TransitionSpec .() -> TransitionSpec ): FsmSpec {
9
- transitions.add(transitionRecipe)
9
+ transitions.add(Transition .create( transitionRecipe) )
10
10
return this
11
11
}
12
12
13
13
fun build (): Fsm {
14
- val map = transitions.map { func -> TransitionSpec ().func().build() }
15
- .associateBy({ it.event }, { it.stateFlow })
14
+ val map = transitions.associateBy({ it.event }, { it.stateFlow })
16
15
return Fsm (
17
16
transitions = map,
18
17
initial = State (initialState),
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package dsl
3
3
data class StateFlow (val from : State , val into : State ) {
4
4
5
5
companion object {
6
- @JvmStatic
7
6
fun of (from : String , into : String ): StateFlow {
8
7
return StateFlow (State (from), State (into))
9
8
}
Original file line number Diff line number Diff line change @@ -2,6 +2,14 @@ package dsl
2
2
3
3
data class Transition (val event : Event , val stateFlow : StateFlow ) {
4
4
5
+ companion object {
6
+ fun create (transitionSpec : TransitionSpec .() -> TransitionSpec ): Transition {
7
+ return TransitionSpec ()
8
+ .transitionSpec()
9
+ .build()
10
+ }
11
+ }
12
+
5
13
override fun toString (): String {
6
14
return " $event : $stateFlow "
7
15
}
You can’t perform that action at this time.
0 commit comments