Class CommandsManager
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final CommandsAll commands that the engine supports.Registry of available commands mapped by their alias strings.static SemiStatefulCommandThe currently active stateful command, if any. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a CommandsManager and populates thecommandsAliasMapmap with the known command instances. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClear the currently active stateful command (set tonull).static booleanQuery whether a stateful command is currently running.static CommandgetCommand(String name) Retrieve aCommandby an alias name.static Stringstatic booleanCheck whether the givenStatefulCommandinstance is the one currently marked as running.static voidMark the suppliedStatefulCommandas the currently active one.
-
Field Details
-
currentStatefulCommand
The currently active stateful command, if any.Only one
StatefulCommandcan 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
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
Commandinstance 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 viagetCommand(String). -
commands
All commands that the engine supports.
-
-
Constructor Details
-
CommandsManager
public CommandsManager()Constructs a CommandsManager and populates thecommandsAliasMapmap with the known command instances.
-
-
Method Details
-
setAsCurrent
Mark the suppliedStatefulCommandas the currently active one.- Parameters:
c- theStatefulCommandto set as current; may be null to clear
-
isCurrentStatefulRunning
Check whether the givenStatefulCommandinstance is the one currently marked as running.- Parameters:
c- theStatefulCommandinstance to check- Returns:
trueifcurrentStatefulCommand==c,falseotherwise
-
clearCurrent
public static void clearCurrent()Clear the currently active stateful command (set tonull). -
getCommand
Retrieve aCommandby an alias name.- Parameters:
name- alias to look up (case-sensitive)- Returns:
- the
Commandregistered forname, ornullif none found - See Also:
-
commandIsRunning
public static boolean commandIsRunning()Query whether a stateful command is currently running.- Returns:
trueifcurrentStatefulCommandis non-null,falseotherwise
-
getCurrentCommandName
-