Class SimpleRegistry

java.lang.Object
dev.sympho.modular_commands.impl.registry.SimpleRegistry
All Implemented Interfaces:
Registry

public final class SimpleRegistry extends Object implements Registry
A simple, directly-mapped registry implementation that does not support overrides. The (partial) exception to this are aliases, where a command may have an alias that matches the regular invocation of another command (the regular invocation will always have precedence over the alias). It may not, however, have the same alias as another command.
Since:
1.0
Version:
1.0
  • Constructor Details

    • SimpleRegistry

      public SimpleRegistry()
      Creates an empty registry.
  • Method Details

    • findCommand

      public <H extends Handlers> @Nullable Command<? extends H> findCommand(Invocation invocation, Class<H> type)
      Description copied from interface: Registry
      Retrieves the best command known to this registry that has the given parent and name, and is compatible with the given type.
      Specified by:
      findCommand in interface Registry
      Type Parameters:
      H - The handler type that must be supported.
      Parameters:
      invocation - The invocation of the command.
      type - The handler type.
      Returns:
      The best matching command known to this registry, or null if none were found.
    • getCommands

      public <H extends Handlers> Collection<Command<? extends H>> getCommands(Class<H> type)
      Description copied from interface: Registry
      Retrieves all commands known to this registry that are compatible with the given type.
      Specified by:
      getCommands in interface Registry
      Type Parameters:
      H - The handler type that must be supported.
      Parameters:
      type - The handler type.
      Returns:
      The compatible commands known to this registry.
    • getCommand

      public @Nullable Command<?> getCommand(String id)
      Description copied from interface: Registry
      Retrieves the command with the given ID that is registered to this registry.
      Specified by:
      getCommand in interface Registry
      Parameters:
      id - The ID of the command to retrieve.
      Returns:
      The command that was registered with the given ID, or null if there is no such command in this registry.
    • registerCommand

      public boolean registerCommand(Command<?> command) throws IllegalArgumentException
      Description copied from interface: Registry
      Registers a command into this registry.
      Specified by:
      registerCommand in interface Registry
      Parameters:
      command - The command to register.
      Returns:
      true if the command was registered successfully. false if there is already a command in this registry with the given ID, or if there is already a command known to this registry with the given signature and this registry does not allow overriding. If false, the registration failed and the call had no effect.
      Throws:
      IllegalArgumentException - if the given command has an invalid configuration.
    • removeCommand

      public @Nullable Command<?> removeCommand(String id)
      Description copied from interface: Registry
      Removes a command from this registry that was registered with the given ID.
      Specified by:
      removeCommand in interface Registry
      Parameters:
      id - The ID of the command to remove.
      Returns:
      The removed command, or null if there was no command in this registry registered with the given ID.