Class SimpleDslArg

  • All Implemented Interfaces:
    DslArg
    Direct Known Subclasses:
    OptionalArg, RequiredArg

    public abstract class SimpleDslArg
    extends java.lang.Object
    implements DslArg
    The root type for all simple args.
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleDslArg​(java.lang.String name, boolean required)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String[] getAllowedValues()
      Get the specific values that this argument will accept.
      java.lang.String getDefaultValue()
      Get a default value for this argument.
      java.lang.String getMultipleValueSeparator()
      Get the separator that can be used to separate multiple values.
      java.lang.String getName()
      Get the name of this argument.
      boolean isAllowMultipleValues()
      Check whether this argument can take multiple values.
      boolean isRequired()
      Determine if a value is required for this argument.
      <T> SimpleDslArg setAllowedValues​(java.lang.Class<T> clazz)
      Restrict the allowed values for this argument to the specified set.
      SimpleDslArg setAllowedValues​(java.lang.String... allowedValues)
      Restrict the allowed values for this argument to the specified set.
      SimpleDslArg setAllowMultipleValues()
      Allow multiple values to be specified for this argument, either as separate arguments or using comma (,) as a delimiter.
      SimpleDslArg setAllowMultipleValues​(java.lang.String delimiter)
      Allow multiple values to be specified for this argument, either as separate arguments or using the specified string as a delimiter.
      SimpleDslArg setDefault​(java.lang.String defaultValue)
      Set a default value for this argument.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleDslArg

        public SimpleDslArg​(java.lang.String name,
                            boolean required)
    • Method Detail

      • getName

        public java.lang.String getName()
        Description copied from interface: DslArg
        Get the name of this argument.
        Specified by:
        getName in interface DslArg
        Returns:
        the argument name.
      • isRequired

        public boolean isRequired()
        Description copied from interface: DslArg
        Determine if a value is required for this argument.
        Specified by:
        isRequired in interface DslArg
        Returns:
        true if and only if this argument is required.
      • getDefaultValue

        public java.lang.String getDefaultValue()
        Description copied from interface: DslArg
        Get a default value for this argument.

        If the argument is required, this method will throw an IllegalArgumentException.

        Specified by:
        getDefaultValue in interface DslArg
        Returns:
        the default value for the argument
      • isAllowMultipleValues

        public boolean isAllowMultipleValues()
        Description copied from interface: DslArg
        Check whether this argument can take multiple values.
        Specified by:
        isAllowMultipleValues in interface DslArg
        Returns:
        true if and only if the argument takes multiple values.
      • getMultipleValueSeparator

        public java.lang.String getMultipleValueSeparator()
        Description copied from interface: DslArg
        Get the separator that can be used to separate multiple values.
        Specified by:
        getMultipleValueSeparator in interface DslArg
        Returns:
        the separator for splitting multiple values.
      • getAllowedValues

        public java.lang.String[] getAllowedValues()
        Description copied from interface: DslArg
        Get the specific values that this argument will accept.
        Specified by:
        getAllowedValues in interface DslArg
        Returns:
        the values allowed by this argument, or null if all values are allowed
      • setDefault

        public SimpleDslArg setDefault​(java.lang.String defaultValue)
        Set a default value for this argument.

        If a default is provided, the argument will be considered to always have a value, and will return the default if no other value is provided by the caller.

        Parameters:
        defaultValue - the default value for the argument.
        Returns:
        this argument
        Throws:
        java.lang.IllegalArgumentException - if the default value cannot be set
      • setAllowedValues

        public SimpleDslArg setAllowedValues​(java.lang.String... allowedValues)
        Restrict the allowed values for this argument to the specified set.

        Specifying a value outside this set will result in an exception being thrown when parsing the arguments.

        Parameters:
        allowedValues - the allowable values for this argument.
        Returns:
        this argument
      • setAllowedValues

        public <T> SimpleDslArg setAllowedValues​(java.lang.Class<T> clazz)
        Restrict the allowed values for this argument to the specified set.

        Specifying a value outside this set will result in an exception being thrown when parsing the arguments.

        Type Parameters:
        T - the type
        Parameters:
        clazz - the Class that provides the allowed values.
        Returns:
        this argument
        Throws:
        java.lang.IllegalArgumentException - if allowed values cannot be determined from the provided class
      • setAllowMultipleValues

        public SimpleDslArg setAllowMultipleValues()
        Allow multiple values to be specified for this argument, either as separate arguments or using comma (,) as a delimiter.

        The following calls are equivalent:

        
         verifyUsersPresent("user: joan", "user: jenny", "user: joanne");
         verifyUsersPresent("user: joan, jenny, joanne");
         
        Returns:
        this argument
        See Also:
        setAllowMultipleValues(String)
      • setAllowMultipleValues

        public SimpleDslArg setAllowMultipleValues​(java.lang.String delimiter)
        Allow multiple values to be specified for this argument, either as separate arguments or using the specified string as a delimiter.
        Parameters:
        delimiter - the delimiter to use to separate values
        Returns:
        this argument
        See Also:
        setAllowMultipleValues()