Class SimpleRegistry
java.lang.Object
dev.sympho.modular_commands.impl.registry.SimpleRegistry
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindCommand(Invocation invocation, Class<H> type) Retrieves the best command known to this registry that has the given parent and name, and is compatible with the given type.getCommand(String id) Retrieves the command with the given ID that is registered to this registry.<H extends Handlers>
Collection<Command<? extends H>>getCommands(Class<H> type) Retrieves all commands known to this registry that are compatible with the given type.booleanregisterCommand(Command<?> command) Registers a command into this registry.removeCommand(String id) Removes a command from this registry that was registered with the given ID.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.sympho.modular_commands.api.registry.Registry
registerCommands, registerCommands, registerCommands
-
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:RegistryRetrieves the best command known to this registry that has the given parent and name, and is compatible with the given type.- Specified by:
findCommandin interfaceRegistry- 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
nullif none were found.
-
getCommands
Description copied from interface:RegistryRetrieves all commands known to this registry that are compatible with the given type.- Specified by:
getCommandsin interfaceRegistry- Type Parameters:
H- The handler type that must be supported.- Parameters:
type- The handler type.- Returns:
- The compatible commands known to this registry.
-
getCommand
Description copied from interface:RegistryRetrieves the command with the given ID that is registered to this registry.- Specified by:
getCommandin interfaceRegistry- Parameters:
id- TheIDof the command to retrieve.- Returns:
- The command that was registered with the given ID, or
nullif there is no such command in this registry.
-
registerCommand
Description copied from interface:RegistryRegisters a command into this registry.- Specified by:
registerCommandin interfaceRegistry- Parameters:
command- The command to register.- Returns:
trueif the command was registered successfully.falseif 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. Iffalse, the registration failed and the call had no effect.- Throws:
IllegalArgumentException- if the given command has an invalid configuration.
-
removeCommand
Description copied from interface:RegistryRemoves a command from this registry that was registered with the given ID.- Specified by:
removeCommandin interfaceRegistry- Parameters:
id- TheIDof the command to remove.- Returns:
- The removed command, or
nullif there was no command in this registry registered with the given ID.
-