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.static <H extends Handlers,C extends CommandContext>
List<InvocationHandler<? super C>>accumulateHandlers(List<? extends Command<? extends H>> chain, Function<H, InvocationHandler<? super C>> getter) Determines the sequence of invocation handlers to execute.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.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
argsiterator 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.
-
accumulateHandlers
@SideEffectFree public static <H extends Handlers,C extends CommandContext> List<InvocationHandler<? super C>> accumulateHandlers(List<? extends Command<? extends H>> chain, Function<H, InvocationHandler<? super C>> getter) throws InvalidChainExceptionDetermines the sequence of invocation handlers to execute.- Type Parameters:
H- The handler type.C- The context type.- Parameters:
chain- The invocation chain.getter- The getter to use to retrieve handlers.- Returns:
- The handlers to execute.
- 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
nullif the command's handlers are not compatible.
-