Class Option.Builder

  • Enclosing class:
    Option

    public static final class Option.Builder
    extends java.lang.Object
    A nested builder class to create Option instances using descriptive methods.

    Example usage:

     Option option = Option.builder("a")
         .required(true)
         .longName("arg-name")
         .build();
     
    • Method Detail

      • longName

        public Option.Builder longName​(java.lang.String longName)
        Sets the long name of the Option.
        Parameters:
        longName - the long name of the Option
        Returns:
        this builder, to allow method chaining
      • valueName

        public Option.Builder valueName​(java.lang.String valueName)
        Sets the display name for the argument value.
        Parameters:
        valueName - the display name for the argument value
        Returns:
        this builder, to allow method chaining
      • valueType

        public Option.Builder valueType​(OptionValueType valueType)
        Sets the type of the Option.
        Parameters:
        valueType - the type of the Option
        Returns:
        this builder, to allow method chaining
      • withEqualSign

        public Option.Builder withEqualSign()
        The Option will use '=' as a means to separate argument value.
        Returns:
        this builder, to allow method chaining
      • hasValue

        public Option.Builder hasValue()
        Indicates that the Option will require an argument.
        Returns:
        this builder, to allow method chaining
      • hasValue

        public Option.Builder hasValue​(boolean hasValue)
        Indicates if the Option has an argument value or not.
        Parameters:
        hasValue - specifies whether the Option takes an argument value or not
        Returns:
        this builder, to allow method chaining
      • hasValues

        public Option.Builder hasValues()
        Indicates that the Option can have unlimited argument values.
        Returns:
        this builder, to allow method chaining
      • numberOfValues

        public Option.Builder numberOfValues​(int numberOfValues)
        Sets the number of argument values the Option can take.
        Parameters:
        numberOfValues - the number of argument values
        Returns:
        this builder, to allow method chaining
      • optionalValue

        public Option.Builder optionalValue()
        Sets whether the Option can have an optional argument value.
        Returns:
        this builder, to allow method chaining
      • required

        public Option.Builder required()
        Marks this Option as required.
        Returns:
        this builder, to allow method chaining
      • required

        public Option.Builder required​(boolean required)
        Sets whether the Option is mandatory.
        Parameters:
        required - specifies whether the Option is mandatory
        Returns:
        this builder, to allow method chaining
      • desc

        public Option.Builder desc​(java.lang.String description)
        Sets the description for this option.
        Parameters:
        description - the description of the option
        Returns:
        this builder, to allow method chaining
      • build

        public Option build()
        Constructs an Option with the values declared by this Option.Builder.
        Returns:
        the new Option
        Throws:
        java.lang.IllegalArgumentException - if neither name or longName has been set