Class CommandsManager

java.lang.Object
com.j3d.engine.interact.cmd.CommandsManager

public class CommandsManager extends Object
CommandsManager is responsible for creating and storing available command instances and providing lookup utilities for retrieving commands by their aliases.

It also manages a single global reference to the currently running SemiStatefulCommand (if any). This class mixes two responsibilities: - holding the registry of available commands (instance field commandsAliasMap) - tracking the currently active stateful command (static currentStatefulCommand).

Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • currentStatefulCommand

      public static SemiStatefulCommand currentStatefulCommand
      The currently active stateful command, if any.

      Only one StatefulCommand can be active globally at a time. This field is static so that any part of the codebase can check or clear the current command via the static helper methods in this class.

      Possible values: - null: no stateful command is currently running - non-null: reference to the active StatefulCommand

    • commandsAliasMap

      public HashMap<String,Command> commandsAliasMap
      Registry of available commands mapped by their alias strings.

      Key: a single alias string (case-sensitive) that can be used to look up a command. Value: the Command instance associated with that alias.

      The map is populated in the constructor: each concrete command's aliasStream() is iterated and each alias is registered pointing to the same command instance. This allows fast O(1) alias lookups via getCommand(String).

    • commands

      public static final Commands commands
      All commands that the engine supports.
  • Constructor Details

    • CommandsManager

      public CommandsManager()
      Constructs a CommandsManager and populates the commandsAliasMap map with the known command instances.
  • Method Details

    • setAsCurrent

      public static void setAsCurrent(SemiStatefulCommand c)
      Mark the supplied StatefulCommand as the currently active one.
      Parameters:
      c - the StatefulCommand to set as current; may be null to clear
    • isCurrentStatefulRunning

      public static boolean isCurrentStatefulRunning(SemiStatefulCommand c)
      Check whether the given StatefulCommand instance is the one currently marked as running.
      Parameters:
      c - the StatefulCommand instance to check
      Returns:
      true if currentStatefulCommand == c, false otherwise
    • clearCurrent

      public static void clearCurrent()
      Clear the currently active stateful command (set to null).
    • getCommand

      public static Command getCommand(String name)
      Retrieve a Command by an alias name.
      Parameters:
      name - alias to look up (case-sensitive)
      Returns:
      the Command registered for name, or null if none found
      See Also:
    • commandIsRunning

      public static boolean commandIsRunning()
      Query whether a stateful command is currently running.
      Returns:
      true if currentStatefulCommand is non-null, false otherwise
    • getCurrentCommandName

      public static String getCurrentCommandName()