Class CommandUtils

java.lang.Object
dev.sympho.modular_commands.utils.CommandUtils

public final class CommandUtils extends Object
Utility functions for Commands.
Since:
1.0
Version:
1.0
  • Method Details

    • validateParent

      public static Invocation validateParent(Invocation parent)
      Validates the parent of a command.
      Parameters:
      parent - The parent to validate.
      Returns:
      The validated parent.
    • validateName

      @Pure @StaticallyExecutable public static @MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String validateName(@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String name) throws IllegalArgumentException
      Validates the name of a command.
      Parameters:
      name - The name to validate.
      Returns:
      The validated name.
      Throws:
      IllegalArgumentException - if the name is not valid.
    • validateDisplayName

      @Pure @StaticallyExecutable public static @MatchesRegex("(?U)^[ -_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String validateDisplayName(@MatchesRegex("(?U)^[ -_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String name) throws IllegalArgumentException
      Validates the display name of a command.
      Parameters:
      name - The display name to validate.
      Returns:
      The validated display name.
      Throws:
      IllegalArgumentException - if the display name is not valid.
    • validateAlias

      @Pure @StaticallyExecutable public static @MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String validateAlias(@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String alias) throws IllegalArgumentException
      Validates an alias.
      Parameters:
      alias - The alias to validate.
      Returns:
      The validated alias.
      Throws:
      IllegalArgumentException - if the alias is not valid.
    • validateAliases

      @SideEffectFree public static Set<@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String> validateAliases(Set<@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String> aliases) throws IllegalArgumentException
      Validates the aliases of a command.
      Parameters:
      aliases - The aliases to validate.
      Returns:
      An immutable copy of the validated alias set.
      Throws:
      IllegalArgumentException - if the alias set is not valid.
    • validateDescription

      @Pure @StaticallyExecutable public static @MatchesRegex("(?Us)^.{1,100}+$") String validateDescription(@MatchesRegex("(?Us)^.{1,100}+$") String description) throws IllegalArgumentException
      Validates the description of a command.
      Parameters:
      description - The description to validate.
      Returns:
      The validated description.
      Throws:
      IllegalArgumentException - if the description is not valid.
    • validateParameters

      @SideEffectFree public static List<Parameter<?>> validateParameters(List<Parameter<?>> parameters) throws IllegalArgumentException
      Validates the parameters of a command.
      Parameters:
      parameters - The parameters to validate.
      Returns:
      An immutable copy of the validated parameter list, in the same order as given.
      Throws:
      IllegalArgumentException - if the parameter list is not valid.
    • validateGroup

      @Pure public static Group validateGroup(Group group)
      Validates the required group of a command.
      Parameters:
      group - The group to validate.
      Returns:
      The validated group.
    • validateInvocationHandler

      @Pure public static <H extends InvocationHandler<?>> H validateInvocationHandler(H handler)
      Validates the invocation handler of a command.
      Type Parameters:
      H - The handler type.
      Parameters:
      handler - The handler to validate.
      Returns:
      The validated handler.
    • validateResultHandlers

      @SideEffectFree public static <H extends ResultHandler<?>> List<H> validateResultHandlers(List<? extends H> handlers)
      Validates the result handlers of a command.
      Type Parameters:
      H - The handler type.
      Parameters:
      handlers - The result handlers to validate.
      Returns:
      An immutable copy of the validated handler list.
    • validateHandlers

      public static <H extends Handlers> H validateHandlers(H handlers)
      Validates the handlers of a command.
      Type Parameters:
      H - The handler type.
      Parameters:
      handlers - The handlers to validate.
      Returns:
      The handlers.
    • validateCommand

      @Pure public static <C extends Command<?>> C validateCommand(C command) throws IllegalArgumentException
      Validates a command.
      Type Parameters:
      C - The command type.
      Parameters:
      command - The command to validate.
      Returns:
      The validated command.
      Throws:
      IllegalArgumentException - If one of the components of the command was invalid.