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
-
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.boolean
registerCommand
(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, wait
Methods 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: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 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
null
if none were found.
-
getCommands
Description copied from interface:Registry
Retrieves all commands known to this registry that are compatible with the given type.- Specified by:
getCommands
in 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:Registry
Retrieves the command with the given ID that is registered to this registry.- Specified by:
getCommand
in interfaceRegistry
- Parameters:
id
- TheID
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
Description copied from interface:Registry
Registers a command into this registry.- Specified by:
registerCommand
in interfaceRegistry
- 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. 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:Registry
Removes a command from this registry that was registered with the given ID.- Specified by:
removeCommand
in interfaceRegistry
- Parameters:
id
- TheID
of the command to remove.- Returns:
- The removed command, or
null
if there was no command in this registry registered with the given ID.
-