Class CommandArgument<C,​T>

    • Constructor Summary

      Constructors 
      Constructor Description
      CommandArgument​(boolean required, @NonNull java.lang.String name, @NonNull ArgumentParser<C,​T> parser, @NonNull java.lang.Class<T> valueType)
      Construct a new command argument
      CommandArgument​(boolean required, @NonNull java.lang.String name, @NonNull ArgumentParser<C,​T> parser, @NonNull java.lang.String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable java.util.function.BiFunction<CommandContext<C>,​java.lang.String,​java.util.List<java.lang.String>> suggestionsProvider)
      Construct a new command argument
      CommandArgument​(boolean required, @NonNull java.lang.String name, @NonNull ArgumentParser<C,​T> parser, @NonNull java.lang.String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable java.util.function.BiFunction<CommandContext<C>,​java.lang.String,​java.util.List<java.lang.String>> suggestionsProvider, @NonNull java.util.Collection<@NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.util.Queue<@NonNull java.lang.String>,​@NonNull ArgumentParseResult<java.lang.Boolean>>> argumentPreprocessors)
      Construct a new command argument
      CommandArgument​(boolean required, @NonNull java.lang.String name, @NonNull ArgumentParser<C,​T> parser, @NonNull java.lang.String defaultValue, @NonNull java.lang.Class<T> valueType, @Nullable java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.lang.String,​@NonNull java.util.List<@NonNull java.lang.String>> suggestionsProvider)
      Construct a new command argument
    • Method Summary

      Modifier and Type Method Description
      @NonNull CommandArgument<C,​T> addPreprocessor​(@NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.util.Queue<java.lang.String>,​@NonNull ArgumentParseResult<java.lang.Boolean>> preprocessor)
      Register a new preprocessor.
      int compareTo​(@NonNull CommandArgument<?,​?> o)  
      @NonNull CommandArgument<C,​T> copy()
      Create a copy of the command argument
      boolean equals​(java.lang.Object o)  
      @NonNull java.lang.String getDefaultValue()
      Get the default value
      @NonNull java.lang.String getName()
      Get the command argument name;
      @Nullable Command<C> getOwningCommand()
      Get the owning command
      @NonNull ArgumentParser<C,​T> getParser()
      Get the parser that is used to parse the command input into the corresponding command type
      @NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.lang.String,​@NonNull java.util.List<java.lang.String>> getSuggestionsProvider()
      Get the argument suggestions provider
      @NonNull io.leangen.geantyref.TypeToken<T> getValueType()
      Get the type of this argument's value
      boolean hasDefaultValue()
      Check if the argument has a default value
      int hashCode()  
      boolean isArgumentRegistered()
      Check whether or not the argument has been used in a command
      boolean isRequired()
      Check whether or not the command argument is required
      static <C,​T>
      @NonNull CommandArgument.Builder<C,​T>
      ofType​(@NonNull io.leangen.geantyref.TypeToken<T> clazz, @NonNull java.lang.String name)
      Create a new command argument
      static <C,​T>
      @NonNull CommandArgument.Builder<@NonNull C,​@NonNull T>
      ofType​(@NonNull java.lang.Class<T> clazz, @NonNull java.lang.String name)
      Create a new command argument
      @NonNull ArgumentParseResult<java.lang.Boolean> preprocess​(@NonNull CommandContext<C> context, @NonNull java.util.Queue<java.lang.String> input)
      Preprocess command input.
      void setArgumentRegistered()
      Indicate that the argument has been associated with a command
      void setOwningCommand​(@NonNull Command<C> owningCommand)
      Set the owning command
      @NonNull java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • CommandArgument

        public CommandArgument​(boolean required,
                               @NonNull java.lang.String name,
                               @NonNull ArgumentParser<C,​T> parser,
                               @NonNull java.lang.String defaultValue,
                               @NonNull io.leangen.geantyref.TypeToken<T> valueType,
                               @Nullable java.util.function.BiFunction<CommandContext<C>,​java.lang.String,​java.util.List<java.lang.String>> suggestionsProvider,
                               @NonNull java.util.Collection<@NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.util.Queue<@NonNull java.lang.String>,​@NonNull ArgumentParseResult<java.lang.Boolean>>> argumentPreprocessors)
        Construct a new command argument
        Parameters:
        required - Whether or not the argument is required
        name - The argument name
        parser - The argument parser
        defaultValue - Default value used when no value is provided by the command sender
        valueType - Type produced by the parser
        suggestionsProvider - Suggestions provider
        argumentPreprocessors - Argument preprocessors
      • CommandArgument

        public CommandArgument​(boolean required,
                               @NonNull java.lang.String name,
                               @NonNull ArgumentParser<C,​T> parser,
                               @NonNull java.lang.String defaultValue,
                               @NonNull io.leangen.geantyref.TypeToken<T> valueType,
                               @Nullable java.util.function.BiFunction<CommandContext<C>,​java.lang.String,​java.util.List<java.lang.String>> suggestionsProvider)
        Construct a new command argument
        Parameters:
        required - Whether or not the argument is required
        name - The argument name
        parser - The argument parser
        defaultValue - Default value used when no value is provided by the command sender
        valueType - Type produced by the parser
        suggestionsProvider - Suggestions provider
      • CommandArgument

        public CommandArgument​(boolean required,
                               @NonNull java.lang.String name,
                               @NonNull ArgumentParser<C,​T> parser,
                               @NonNull java.lang.String defaultValue,
                               @NonNull java.lang.Class<T> valueType,
                               @Nullable java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.lang.String,​@NonNull java.util.List<@NonNull java.lang.String>> suggestionsProvider)
        Construct a new command argument
        Parameters:
        required - Whether or not the argument is required
        name - The argument name
        parser - The argument parser
        defaultValue - Default value used when no value is provided by the command sender
        valueType - Type produced by the parser
        suggestionsProvider - Suggestions provider
      • CommandArgument

        public CommandArgument​(boolean required,
                               @NonNull java.lang.String name,
                               @NonNull ArgumentParser<C,​T> parser,
                               @NonNull java.lang.Class<T> valueType)
        Construct a new command argument
        Parameters:
        required - Whether or not the argument is required
        name - The argument name
        parser - The argument parser
        valueType - Type produced by the parser
    • Method Detail

      • ofType

        public static <C,​T> @NonNull CommandArgument.Builder<C,​T> ofType​(@NonNull io.leangen.geantyref.TypeToken<T> clazz,
                                                                                     @NonNull java.lang.String name)
        Create a new command argument
        Type Parameters:
        C - Command sender type
        T - Argument Type. Used to make the compiler happy.
        Parameters:
        clazz - Argument class
        name - Argument name
        Returns:
        Argument builder
      • ofType

        public static <C,​T> @NonNull CommandArgument.Builder<@NonNull C,​@NonNull T> ofType​(@NonNull java.lang.Class<T> clazz,
                                                                                                       @NonNull java.lang.String name)
        Create a new command argument
        Type Parameters:
        C - Command sender type
        T - Argument Type. Used to make the compiler happy.
        Parameters:
        clazz - Argument class
        name - Argument name
        Returns:
        Argument builder
      • isRequired

        public boolean isRequired()
        Check whether or not the command argument is required
        Returns:
        true if the argument is required, false if not
      • getName

        public @NonNull java.lang.String getName()
        Get the command argument name;
        Returns:
        Argument name
      • getParser

        public @NonNull ArgumentParser<C,​T> getParser()
        Get the parser that is used to parse the command input into the corresponding command type
        Returns:
        Command parser
      • toString

        public final @NonNull java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • addPreprocessor

        public @NonNull CommandArgument<C,​T> addPreprocessor​(@NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.util.Queue<java.lang.String>,​@NonNull ArgumentParseResult<java.lang.Boolean>> preprocessor)
        Register a new preprocessor. If all preprocessor has succeeding results that all return true, the argument will be passed onto the parser.

        It is important that the preprocessor doesn't pop any input. Instead, it should only peek.

        Parameters:
        preprocessor - Preprocessor
        Returns:
        this
      • preprocess

        public @NonNull ArgumentParseResult<java.lang.Boolean> preprocess​(@NonNull CommandContext<C> context,
                                                                          @NonNull java.util.Queue<java.lang.String> input)
        Preprocess command input. This will immediately forward any failed argument parse results. If none fails, a true result will be returned
        Parameters:
        context - Command context
        input - Remaining command input. None will be popped
        Returns:
        Parsing error, or argument containing true
      • getOwningCommand

        public @Nullable Command<C> getOwningCommand()
        Get the owning command
        Returns:
        Owning command
      • setOwningCommand

        public void setOwningCommand​(@NonNull Command<C> owningCommand)
        Set the owning command
        Parameters:
        owningCommand - Owning command
      • getSuggestionsProvider

        public final @NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.lang.String,​@NonNull java.util.List<java.lang.String>> getSuggestionsProvider()
        Get the argument suggestions provider
        Returns:
        Suggestions provider
      • equals

        public final boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public final int compareTo​(@NonNull CommandArgument<?,​?> o)
        Specified by:
        compareTo in interface java.lang.Comparable<C>
      • getDefaultValue

        public @NonNull java.lang.String getDefaultValue()
        Get the default value
        Returns:
        Default value
      • hasDefaultValue

        public boolean hasDefaultValue()
        Check if the argument has a default value
        Returns:
        true if the argument has a default value, false if not
      • getValueType

        public @NonNull io.leangen.geantyref.TypeToken<T> getValueType()
        Get the type of this argument's value
        Returns:
        Value type
      • copy

        public @NonNull CommandArgument<C,​T> copy()
        Create a copy of the command argument
        Returns:
        Copied argument
      • isArgumentRegistered

        public boolean isArgumentRegistered()
        Check whether or not the argument has been used in a command
        Returns:
        true if the argument has been used in a command, else false
      • setArgumentRegistered

        public void setArgumentRegistered()
        Indicate that the argument has been associated with a command