Class CommandsCollection

java.lang.Object
com.example.common.command.CommandsCollection
All Implemented Interfaces:
CommandsInterface

public class CommandsCollection extends Object implements 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 Details

    • CommandsCollection

      public CommandsCollection()
  • Method Details

    • add

      public void add(Command command)
      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 interface CommandsInterface
      Parameters:
      command - The command to be added to the collection.
    • remove

      public void remove(String name)
      Removes a command from the collection using its name as the key.
      Specified by:
      remove in interface CommandsInterface
      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 interface CommandsInterface
      Returns:
      The size of the collection.
    • getAllCommands

      public Collection<Command> getAllCommands()
      Returns a collection containing all the commands stored in the collection.
      Specified by:
      getAllCommands in interface CommandsInterface
      Returns:
      A Collection of all commands.
    • contains

      public boolean contains(String name)
      Checks if a command with the specified name exists in the collection.
      Specified by:
      contains in interface CommandsInterface
      Parameters:
      name - The name of the command to check for.
      Returns:
      true if the collection contains the command, false otherwise.
    • getByName

      public Command getByName(String name)
      Retrieves a command from the collection based on its name.
      Specified by:
      getByName in interface CommandsInterface
      Parameters:
      name - The name of the command to retrieve.
      Returns:
      The command object corresponding to the specified name.