
net.pechorina.kairos.automat.Transition.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kairos-automat Show documentation
Show all versions of kairos-automat Show documentation
Kairos Automat is a finite-state machine library
The newest version!
package net.pechorina.kairos.automat
data class Transition(val source: State, val target: State, val event: Event, val action: Action? = null) {
fun transit(automat: Automat): State {
source.onExit?.let {
it(this, automat)
}
automat.listeners().forEach { it.stateExited(source) }
target.onEntry?.let {
it(this, automat)
}
automat.listeners().forEach { it.stateEntered(target) }
automat.listeners().forEach { it.stateChanged(source, target) }
action?.invoke(this, automat)
automat.listeners().forEach { it.transition(this) }
return target
}
}