Class TypedOption<T>

java.lang.Object
io.vertx.core.cli.Option
io.vertx.core.cli.TypedOption<T>

public class TypedOption<T> extends Option
An implementation of Option for java specifying the type of object received by the option. This allows converting the given raw value into the specified type.
Author:
Clement Escoffier invalid input: '<'[email protected]>
  • Field Details

    • type

      protected Class<T> type
      The type of the option.
    • parsedAsList

      protected boolean parsedAsList
      whether or not the raw value should be parsed as a list. The list if computed by splitting the value.
    • listSeparator

      protected String listSeparator
      the split character used if the raw value needs to be parsed as a list. ',' is used by default.
    • converter

      protected Converter<T> converter
      the converter to create the value.
  • Constructor Details

    • TypedOption

      public TypedOption()
      Creates an empty instance of TypedOption.
    • TypedOption

      public TypedOption(TypedOption<T> option)
      Creates an instance of TypedOption by copying the state of another TypedOption
      Parameters:
      option - the copied option
  • Method Details

    • setMultiValued

      public TypedOption<T> setMultiValued(boolean acceptMultipleValues)
      Description copied from class: Option
      Sets whether or not this option can receive several values.
      Overrides:
      setMultiValued in class Option
      Parameters:
      acceptMultipleValues - whether or not this option is multi-valued.
      Returns:
      the current Option instance
    • setSingleValued

      public TypedOption<T> setSingleValued(boolean acceptSingleValue)
      Description copied from class: Option
      Sets whether or not this option can receive a value.
      Overrides:
      setSingleValued in class Option
      Parameters:
      acceptSingleValue - whether or not this option is single-valued.
      Returns:
      the current Option instance
    • setArgName

      public TypedOption<T> setArgName(String argName)
      Description copied from class: Option
      Sets te arg name for this option.
      Overrides:
      setArgName in class Option
      Parameters:
      argName - the arg name, must not be null
      Returns:
      the current Option instance
    • setDefaultValue

      public TypedOption<T> setDefaultValue(String defaultValue)
      Description copied from class: Option
      Sets the default value of this option
      Overrides:
      setDefaultValue in class Option
      Parameters:
      defaultValue - the default value
      Returns:
      the current Option instance
    • setDescription

      public TypedOption<T> setDescription(String description)
      Description copied from class: Option
      Sets te description of this option.
      Overrides:
      setDescription in class Option
      Parameters:
      description - the description
      Returns:
      the current Option instance
    • setFlag

      public TypedOption<T> setFlag(boolean flag)
      Description copied from class: Option
      Configures the current Option to be a flag. It will be evaluated to true if it's found in the command line. If you need a flag that may receive a value, use, in this order:
        option.setFlag(true).setSingleValued(true)
      
      Overrides:
      setFlag in class Option
      Parameters:
      flag - whether or not the option is a flag.
      Returns:
      the current Option
    • setHidden

      public TypedOption<T> setHidden(boolean hidden)
      Description copied from class: Option
      Sets whether or not this option should be hidden
      Overrides:
      setHidden in class Option
      Parameters:
      hidden - true to make this option hidden,
      invalid @link
      {@link false
      } otherwise
      Returns:
      the current Option instance
    • setLongName

      public TypedOption<T> setLongName(String longName)
      Description copied from class: Option
      Sets the long name of this option.
      Overrides:
      setLongName in class Option
      Parameters:
      longName - the long name
      Returns:
      the current Option instance
    • setRequired

      public TypedOption<T> setRequired(boolean required)
      Description copied from class: Option
      Sets whether or not this option is mandatory.
      Overrides:
      setRequired in class Option
      Parameters:
      required - true to make this option mandatory,
      invalid @link
      {@link false
      } otherwise
      Returns:
      the current Option instance
    • setShortName

      public TypedOption<T> setShortName(String shortName)
      Description copied from class: Option
      Sets the short name of this option.
      Overrides:
      setShortName in class Option
      Parameters:
      shortName - the short name
      Returns:
      the current Option instance
    • getType

      public Class<T> getType()
    • setType

      public TypedOption<T> setType(Class<T> type)
    • isParsedAsList

      public boolean isParsedAsList()
    • setParsedAsList

      public TypedOption<T> setParsedAsList(boolean isList)
    • getListSeparator

      public String getListSeparator()
    • setListSeparator

      public TypedOption<T> setListSeparator(String listSeparator)
    • getConverter

      public Converter<T> getConverter()
    • setConverter

      public TypedOption<T> setConverter(Converter<T> converter)
    • ensureValidity

      public void ensureValidity()
      Description copied from class: Option
      Checks whether or not the option is valid. This implementation check that it has a short name or a long name. This method is intended to be extended by sub-class. Parser should check that the set of option of a CLI is valid before starting the parsing.

      If the configuration is not valid, this method throws a IllegalArgumentException.

      Overrides:
      ensureValidity in class Option
    • setChoices

      public TypedOption<T> setChoices(Set<String> choices)
      Description copied from class: Option
      Sets the list of values accepted by this option. If the value set by the user does not match once of these values, a InvalidValueException exception is thrown.
      Overrides:
      setChoices in class Option
      Parameters:
      choices - the choices
      Returns:
      the current Option
    • addChoice

      public TypedOption<T> addChoice(String choice)
      Description copied from class: Option
      Adds a choice to the list of values accepted by this option. If the value set by the user does not match once of these values, a InvalidValueException exception is thrown.
      Overrides:
      addChoice in class Option
      Parameters:
      choice - the choice
      Returns:
      the current Option