Package com.example.common.command
Class CommandsCollection
java.lang.Object
com.example.common.command.CommandsCollection
- All Implemented Interfaces:
CommandsInterface
The CommandsCollection class implements the CommandsInterface using a HashMap to store commands.
This class provides methods to add, remove, and retrieve commands, as well as check for the presence of a command.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a command to the collection using the command's name as the key and the command object as the value.boolean
Checks if a command with the specified name exists in the collection.Returns a collection containing all the commands stored in the collection.Retrieves a command from the collection based on its name.void
Removes a command from the collection using its name as the key.int
size()
Returns the number of commands stored in the collection.
-
Constructor Details
-
CommandsCollection
public CommandsCollection()
-
-
Method Details
-
add
Adds a command to the collection using the command's name as the key and the command object as the value.- Specified by:
add
in interfaceCommandsInterface
- Parameters:
command
- The command to be added to the collection.
-
remove
Removes a command from the collection using its name as the key.- Specified by:
remove
in interfaceCommandsInterface
- Parameters:
name
- The name of the command to be removed.
-
size
public int size()Returns the number of commands stored in the collection.- Specified by:
size
in interfaceCommandsInterface
- Returns:
- The size of the collection.
-
getAllCommands
Returns a collection containing all the commands stored in the collection.- Specified by:
getAllCommands
in interfaceCommandsInterface
- Returns:
- A Collection of all commands.
-
contains
Checks if a command with the specified name exists in the collection.- Specified by:
contains
in interfaceCommandsInterface
- Parameters:
name
- The name of the command to check for.- Returns:
- true if the collection contains the command, false otherwise.
-
getByName
Retrieves a command from the collection based on its name.- Specified by:
getByName
in interfaceCommandsInterface
- Parameters:
name
- The name of the command to retrieve.- Returns:
- The command object corresponding to the specified name.
-