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

eu.lucaventuri.fibry.fsm.FsmConsumer Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
package eu.lucaventuri.fibry.fsm;

import java.util.Map;
import java.util.function.Consumer;

public class FsmConsumer>, I> extends FsmBase {
    FsmConsumer(Map> mapStates, S currentState) {
        super(mapStates, currentState);
    }

    public S onEvent(M event, I userData) {
        return onEvent(event, userData, true, true);
    }

    public S onEvent(M event, I userData, boolean notifyConsumer, boolean exceptionOnUnexpectedEvent) {
        var prevState = mapStates.get(currentState);

        var nextState = prevState.onEvent(event, exceptionOnUnexpectedEvent);
        currentState = nextState.state;

        if (notifyConsumer && nextState.actor != null)
            nextState.actor.accept(new FsmContext<>(prevState.state, nextState.state, event, userData));

        return nextState.state;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy