Package org.zkoss.fsm

Class StateCtx<E,​C,​IN>

  • Direct Known Subclasses:
    MacroStateCtx

    public class StateCtx<E,​C,​IN>
    extends java.lang.Object
    A context for a State in a StateMachine, holding returning and transition information.
    Since:
    6.0.0
    Author:
    simonpai
    • Field Detail

      • _returnAll

        protected boolean _returnAll
      • _returners

        protected final java.util.Set<C> _returners
      • _minorReturners

        protected final java.util.Set<IN> _minorReturners
      • _transitions

        protected final java.util.Map<C,​E> _transitions
      • _minorTransitions

        protected final java.util.Map<IN,​E> _minorTransitions
    • Constructor Detail

      • StateCtx

        public StateCtx()
        Creates a new state context
    • Method Detail

      • init

        protected void init()
        Initialization method called at the constructor
      • addReturningClasses

        public StateCtx<E,​C,​IN> addReturningClasses​(C... inputClasses)
        Add an input class for returning to this state
        Returns:
        this state
      • addReturningClasses

        public StateCtx<E,​C,​IN> addReturningClasses​(java.util.Collection<C> collection)
        Add multiple input classes for returning to this state
        Returns:
        this state
      • addReturningInputs

        public StateCtx<E,​C,​IN> addReturningInputs​(IN... inputs)
        Add input characters for returning to this state
        Returns:
        this state
      • addReturningInputs

        public StateCtx<E,​C,​IN> addReturningInputs​(java.util.Collection<IN> collection)
        Add input characters for returning to this state
        Returns:
        this state
      • setReturningAll

        public StateCtx<E,​C,​IN> setReturningAll​(boolean returnAll)
        Set whether returns to this state upon meeting unspecified characters
        Returns:
        this state
      • addTransition

        public StateCtx<E,​C,​IN> addTransition​(C inputClass,
                                                          E destination)
        Add a transition rule
        Returns:
        this state
      • addTransitions

        public StateCtx<E,​C,​IN> addTransitions​(E destination,
                                                           C... inputClasses)
        Add multiple transitions
        Returns:
        this state
      • addMinorTransition

        public StateCtx<E,​C,​IN> addMinorTransition​(IN input,
                                                               E destination)
        Add a transition for a character.
        Returns:
        this state
      • addMinorTransitions

        public StateCtx<E,​C,​IN> addMinorTransitions​(E destination,
                                                                IN... inputs)
        Add multiple transitions for characters
        Returns:
        this state
      • addMinorTransitions

        public StateCtx<E,​C,​IN> addMinorTransitions​(E destination,
                                                                StateCtx.TransitionListener<IN,​C> callback,
                                                                IN... inputs)
        Add multiple transitions for characters with a callback
        Returns:
        this state
      • addMinorRoute

        public StateCtx<E,​C,​IN> addMinorRoute​(IN input,
                                                          E destination)
        Add a transition for a character. Same as addMinorRoute(Object, Object), and only differs in return value.
        Returns:
        destination state
      • isReturningAll

        public boolean isReturningAll()
        Returns true if this state returns to itself by default, unless meeting specified characters or classes.
      • isReturning

        public boolean isReturning​(IN input,
                                   C inputClass)
        Returns true if this state returns to itself upon meeting the character or the class.
      • isLeaving

        public boolean isLeaving​(IN input,
                                 C inputClass)
        Returns true if the machine is leaving this state upon meeting the character or the class.
      • getDestination

        public E getDestination​(IN input,
                                C inputClass)
        Returns the destination state upon meeting the character or the class.
      • onLand

        protected void onLand​(IN input,
                              C inputClass,
                              E origin)
        This method is called when the machine enters this state
      • onReturn

        protected void onReturn​(IN input,
                                C inputClass)
        This method is called when the machine returns to the same state
      • onReject

        protected void onReject​(IN input,
                                C inputClass)
        This method is called when the machine rejects the input on this state
      • onLeave

        protected void onLeave​(IN input,
                               C inputClass,
                               E destination)
        This method is called when the machine leaves this state
      • onStop

        protected void onStop​(boolean endOfInput)
        This method is called when the machine stops on this state