All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.pechorina.kairos.automat.builder.StateConfig.kt Maven / Gradle / Ivy

The newest version!
package net.pechorina.kairos.automat.builder

import net.pechorina.kairos.automat.Action
import net.pechorina.kairos.automat.State

data class StateConfig(
        val state: S? = null,
        var parent: S? = null,
        var initialState: Boolean = false,
        var finalState: Boolean = false,
        var entryAction: Action? = null,
        var exitAction: Action? = null) {

    fun asState(): State {
        if (state == null) throw RuntimeException("State state is not defined")

        return State(
                value = state,
                onEntry = entryAction,
                onExit = exitAction,
                initialState = initialState,
                finalState = finalState
        )
    }

    fun hasParent(): Boolean {
        return parent != null
    }

    fun getChildParentPair(stateFinder: (state: S) -> State): Pair, State> {
        if (parent == null) throw RuntimeException("No parent defined")
        if (state == null) throw RuntimeException("No state defined")

        val child: State = stateFinder(state)
        val parent: State = stateFinder(parent!!)
        return Pair(child, parent)
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy