gt:       return (getClass() + "[currentState=" + currentState + "]");
context: /*
   * Created on 2006-08-21
   *
   * @author M.Olszewski
   */
  
  package net.java.dante.gui.server;
  
  
  import net.java.dante.gui.common.games.Game;
  import net.java.dante.gui.common.games.GameData;
  import net.java.dante.gui.common.games.GameInitData;
  import net.java.dante.gui.common.games.GameInputData;
  import net.java.dante.gui.common.messages.receiver.GameInitializationFailed;
  import net.java.dante.gui.common.messages.receiver.SimulationInputMessage;
  import net.java.dante.gui.common.messages.receiver.SimulationOutputMessage;
  import net.java.dante.receiver.Receiver;
  import net.java.dante.sim.Simulation;
  import net.java.dante.sim.SimulationFactory;
  import net.java.dante.sim.SimulationType;
  import net.java.dante.sim.data.ServerSimulationInitData;
  import net.java.dante.sim.data.common.FileDataSource;
  import net.java.dante.sim.io.GroupAbandonSimulationData;
  import net.java.dante.sim.io.InputData;
  import net.java.dante.sim.io.OutputData;
  import net.java.dante.sim.io.SimulationOutput;
  
  /**
   * Implementation of {@link Game} interface.
   *
   * @author M.Olszewski
   */
  class GameImpl implements Game
  {
    /** Base for name of initialization thread. */
    private final static String INIT_THREAD_NAME_BASE = "GameInitializer#";
  
    /** Game's data. */
    GameDataImpl data;
    /** Simulation. */
    Simulation simulation;
    /** Game's state machine. */
    StateMachine stateMachine = new StateMachine();
  
  
    /**
     * Creates instance of {@link GameImpl} class.
     *
     * @param gameData - this game's data.
     */
    GameImpl(GameDataImpl gameData)
    {
      if (gameData == null)
      {
        throw new NullPointerException("Specified gameData is null!");
      }
  
      data = gameData;
    }
  
  
    /**
     * Creates name of game initialization thread using
     * the specified game's identifier.
     *
     * @param gameId - the specified game's identifier.
     *
     * @return Returns created name of game initialization thread.
     */
    static String createInitThreadName(Integer gameId)
    {
      return (INIT_THREAD_NAME_BASE + gameId);
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#getData()
     */
    public GameData getData()
    {
      return data;
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#create()
     */
    public void create()
    {
      stateMachine.create();
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#ready()
     */
    public void ready()
    {
      stateMachine.ready();
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#notReady()
     */
    public void notReady()
    {
      stateMachine.notReady();
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#init(net.java.dante.gui.common.games.GameInitData)
     */
    public void init(GameInitData initData)
    {
      stateMachine.init(initData);
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#start()
     */
    public void start()
    {
      stateMachine.start();
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#pause()
     */
    public void pause()
    {
      stateMachine.pause();
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#resume()
     */
    public void resume()
    {
      stateMachine.resume();
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#finish()
     */
    public void finish()
    {
      stateMachine.finish();
    }
  
    /**
     * @see net.java.dante.gui.common.games.Game#acceptInput(net.java.dante.gui.common.games.GameInputData)
     */
    public void acceptInput(GameInputData inputData)
    {
      stateMachine.acceptInput(inputData);
    }
  
  
    /**
     * Gets {@link GameDataImpl} object stored by this {@link GameImpl} instance.
     *
     * @return Returns {@link GameDataImpl} object stored by this
     *         {@link GameImpl} instance.
     */
    GameDataImpl getDataImpl()
    {
      return data;
    }
  
    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
      final int PRIME = 37;
      int result = 17;
  
      result = PRIME * result + data.hashCode();
  
      return result;
    }
  
    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object object)
    {
      boolean equal = (this == object);
      if (!equal && (object instanceof GameImpl))
      {
        final GameImpl other = (GameImpl) object;
        equal = (data.equals(other.data));
      }
      return equal;
    }
  
    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
      return (getClass() + "[data=" + data + "; simulation=" + simulation +
          "; stateMachine=" + stateMachine + "]");
    }
  
  
    /**
     * State machine for this game.
     *
     * @author M.Olszewski
     */
    final class StateMachine
    {
      /** Initial state. */
      private final State initialState = new InitialState();
      /** Created and not ready to start state. */
      private final State notReadyState = new NotReadyState();
      /** Ready to start state. */
      private final State readyState = new ReadyState();
      /** Ready to start state. */
      private final State initializingState = new InitializingState();
      /** Running state. */
      private final State runningState = new RunningState();
      /** Paused state. */
      private final State pausedState  = new PausedState();
      /** Current state. */
      private State currentState = initialState;
  
  
      /**
       * Creates instance of {@link StateMachine} class.
       */
      StateMachine()
      {
        // Intentionally left empty.
      }
  
      /**
       * Sets current state to 'initial'.
       */
      void setInitialState()
      {
        currentState = initialState;
      }
  
      /**
       * Sets current state to 'not ready'.
       */
      void setNotReadyState()
      {
        currentState = notReadyState;
      }
  
      /**
       * Sets current state to 'ready'.
       */
      void setReadyState()
      {
        currentState = readyState;
      }
  
      /**
       * Sets current state to 'initializing'.
       */
      void setInitializingState()
      {
        currentState = initializingState;
      }
  
      /**
       * Sets current state to 'running'.
       */
      void setRunningState()
      {
        currentState = runningState;
      }
  
      /**
       * Sets current state to 'paused'.
       */
      void setPausedState()
      {
        currentState = pausedState;
      }
  
      /**
       * @see net.java.dante.gui.common.games.Game#create()
       */
      void create()
      {
        currentState.create();
      }
  
      /**
       * @see net.java.dante.gui.common.games.Game#ready()
       */
      public void ready()
      {
        currentState.ready();
      }
  
      /**
       * @see net.java.dante.gui.common.games.Game#notReady()
       */
      public void notReady()
      {
        currentState.notReady();
      }
  
      /**
       * @see net.java.dante.gui.common.games.Game#init(net.java.dante.gui.common.games.GameInitData)
       *
       * @param initData - initialization data for this game.
       */
      void init(GameInitData initData)
      {
        currentState.init(initData);
      }
  
      /**
       * @see net.java.dante.gui.common.games.Game#start()
       */
      void start()
      {
        currentState.start();
      }
  
      /**
       * @see net.java.dante.gui.common.games.Game#pause()
       */
      void pause()
      {
        currentState.pause();
      }
  
      /**
       * @see net.java.dante.gui.common.games.Game#resume()
       */
      void resume()
      {
        currentState.resume();
      }
  
      /**
       * @see net.java.dante.gui.common.games.Game#finish()
       */
      void finish()
      {
        currentState.finish();
      }
  
      /**
       * @see net.java.dante.gui.common.games.Game#acceptInput(net.java.dante.gui.common.games.GameInputData)
       *
       * @param inputData - input to accept by this game.
       */
      void acceptInput(GameInputData inputData)
      {
        currentState.acceptInput(inputData);
      }
  
      /**
       * @see java.lang.Object#toString()
       */
      @Override
      public String toString()
      {
  