Class CommandFactory

Object
CommandFactory

public class CommandFactory extends Object
The factory that creates commands based on the string entered by the user.
Author:
maartenl
  • Constructor Details

    • CommandFactory

      public CommandFactory()
  • Method Details

    • getBogusCommand

      public static NormalCommand getBogusCommand()
    • getAdminCommand

      public static NormalCommand getAdminCommand()
    • getCommand

      public static List<NormalCommand> getCommand(String aCommand)
      Returns the commands to be used, based on the first word in the command entered by the user.
      Parameters:
      aCommand - String containing the command entered by the user.
      Returns:
      List containing the commands that fit the description. The commands that are contained are in the following order:
      1. special commands retrieved from the database
      2. normal commands
      3. bogus command (the ultimate failover, "I don't understand that.".)
      It also means that this collection will always carry at least one command, the bogus command.

      All commands are newly created.

    • getUserCommands

      public static List<CommandFactory.UserCommandInfo> getUserCommands(User user, String aCommand, BiConsumer<String,Throwable> errorConsumer)

      Returns all matching user commands.

      There are a few requirements

      • commands must match
      • either the user defined command is valid for all rooms OR
      • room defined in the user defined commands euqals the room the user is in

      Parameters:
      user - the user, used to get the room.
      aCommand - the string containing the command issued by the user
      Returns:
      a list of possibly valid user defined commands.
    • noUserCommands

      public static boolean noUserCommands()
      Returns if the map of user commands is empty.
      Returns:
      true if usercommands is empty.
    • clearUserCommandStructure

      public static void clearUserCommandStructure()
      Clears the map containing all user-defined commands. It will be reloaded automatically from the database, upon executing the first command.
    • addUserCommand

      public static void addUserCommand(int aCommandId, String aCommand, String aMethodName, Long aRoom)
      Add a user command to the structure.
      Parameters:
      aCommandId - the id of the command
      aCommand - the command
      aMethodName - the method name
      aRoom - the room, optional, may be null in which case the command is valid for all rooms.