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

rinde.sim.util.fsm.State Maven / Gradle / Ivy

There is a newer version: 4.4.6
Show newest version
package rinde.sim.util.fsm;

import javax.annotation.Nullable;

/**
 * Defines a state in a state machine.
 * 
 * @param  Event type, see {@link StateMachine} for details.
 * @param  Context type, see {@link StateMachine} for details.
 * @author Rinde van Lon 
 */
public interface State {

  /**
   * @return The name of the state.
   */
  String name();

  /**
   * Should handle the event. Allows the state to take control and react to the
   * event.
   * @param event The event that should be handled.
   * @param context The context of the state.
   * @return An event or null. If null is returned
   *         there will be no state transition. If the returned event is not
   *         supported by this state (as defined by the {@link StateMachine}) a
   *         {@link RuntimeException} will be thrown by the {@link StateMachine}
   *         .
   */
  @Nullable
  E handle(@Nullable E event, C context);

  /**
   * This method is called at the moment the {@link StateMachine} 'enters' this
   * state (i.e. during a state transition). It is called just before the
   * {@link #handle(Object, Object)} is called.
   * @param event The event that triggered the transition.
   * @param context The context of the state.
   */
  void onEntry(E event, C context);

  /**
   * This method is called at the moment the {@link StateMachine} 'exits' this
   * state (i.e. during a state transition).
   * @param event The event that triggered the transition.
   * @param context The context of the state.
   */
  void onExit(E event, C context);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy