Class InvocationUtils
java.lang.Object
dev.sympho.modular_commands.execute.InvocationUtils
Utility functions for handling invocations.
- Since:
- 1.0
- Version:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionaccumulateGroups
(List<? extends Command<?>> chain) Determines the total set of groups required for an execution chain.Determines if a command has handlers compatible with the given type.static <C extends Command<?>>
CgetInvokedCommand
(List<? extends C> chain) Extracts the command being invoked from an execution chain.getSettingsSource
(List<C> chain) Determines the command in the execution chain that should provide the invocation settings.handlingOrder
(List<C> chain) Determines the sequence that command handlers should be invoked in for the given chain.static <H extends Handlers>
Tuple2<Invocation,List<Command<? extends H>>> parseInvocation
(Registry registry, SmartIterator<String> args, Class<H> commandType) Extracts an invocation from a sequence of args by performing lookups on the given registry, while building the corresponding execution chain.
-
Method Details
-
parseInvocation
@SideEffectFree public static <H extends Handlers> Tuple2<Invocation,List<Command<? extends H>>> parseInvocation(Registry registry, SmartIterator<String> args, Class<H> commandType) Extracts an invocation from a sequence of args by performing lookups on the given registry, while building the corresponding execution chain.After this method returns, the given
args
iterator will be positioned such that the next element is the first argument that did not match a subcommand (and thus the first proper argument).- Type Parameters:
H
- The handler type.- Parameters:
registry
- The registry to use for command lookups.args
- The invocation args.commandType
- The command type.- Returns:
- The detected invocation and the corresponding execution chain.
-
getInvokedCommand
Extracts the command being invoked from an execution chain.- Type Parameters:
C
- The command type.- Parameters:
chain
- The execution chain.- Returns:
- The command that was invoked (the last one in the chain).
-
getSettingsSource
Determines the command in the execution chain that should provide the invocation settings.- Type Parameters:
C
- The command type.- Parameters:
chain
- The command chain.- Returns:
- The command to take settings from.
- See Also:
-
accumulateGroups
Determines the total set of groups required for an execution chain.- Parameters:
chain
- The execution chain.- Returns:
- The required groups.
-
handlingOrder
Determines the sequence that command handlers should be invoked in for the given chain.- Type Parameters:
C
- The command type.- Parameters:
chain
- The invocation chain.- Returns:
- The commands, in the order that their handlers must be executed. Some of the commands in the chain may be missing if they do not need to be executed.
- Throws:
InvalidChainException
- if the command chain is incompatible.- See Also:
-
checkType
@Pure public static <H extends Handlers> @Nullable Command<? extends H> checkType(Command<?> command, Class<H> type) Determines if a command has handlers compatible with the given type.- Type Parameters:
H
- The handler type.- Parameters:
command
- The command to check.type
- The handler type.- Returns:
- The command, or
null
if the command's handlers are not compatible.
-