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

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

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

import eu.lucaventuri.fibry.MessageOnlyActor;

import java.util.HashMap;
import java.util.Map;

public class FsmTemplateActor, R, ?>, I> extends FsmTemplate {
    public FsmTemplateActor(Map> mapEnums) {
        super(mapEnums);
    }

    public FsmActor newFsmActor(S state) {
        return new FsmActor<>(mapStates, state);
    }

    public FsmActor newFsmActorReplace(S state, A actor) {
        return new FsmActor<>(replaceAllActors(actor), state);
    }

    private Map> replaceAllActors(A actor) {
        var newMapStates = new HashMap>();

        // Replace State in the map
        for (var entry : mapStates.entrySet()) {
            newMapStates.put(entry.getKey(), entry.getValue().withActor(actor, true));
        }

        // Replace State in the lists
        for (var entry : newMapStates.entrySet()) {
            entry.getValue().replaceListActors(actor, newMapStates);
        }

        return newMapStates;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy