Package com.lmax.simpledsl.api
Class SimpleDslArg
- java.lang.Object
-
- com.lmax.simpledsl.api.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.StringgetDefaultValue()Get a default value for this argument.java.lang.StringgetMultipleValueSeparator()Get the separator that can be used to separate multiple values.java.lang.StringgetName()Get the name of this argument.booleanisAllowMultipleValues()Check whether this argument can take multiple values.booleanisRequired()Determine if a value is required for this argument.<T> SimpleDslArgsetAllowedValues(java.lang.Class<T> clazz)Restrict the allowed values for this argument to the specified set.SimpleDslArgsetAllowedValues(java.lang.String... allowedValues)Restrict the allowed values for this argument to the specified set.SimpleDslArgsetAllowMultipleValues()Allow multiple values to be specified for this argument, either as separate arguments or using comma (,) as a delimiter.SimpleDslArgsetAllowMultipleValues(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.SimpleDslArgsetDefault(java.lang.String defaultValue)Set a default value for this argument.
-
-
-
Method Detail
-
getName
public java.lang.String getName()
Description copied from interface:DslArgGet the name of this argument.
-
isRequired
public boolean isRequired()
Description copied from interface:DslArgDetermine if a value is required for this argument.- Specified by:
isRequiredin interfaceDslArg- Returns:
- true if and only if this argument is required.
-
getDefaultValue
public java.lang.String getDefaultValue()
Description copied from interface:DslArgGet a default value for this argument.If the argument is required, this method will throw an
IllegalArgumentException.- Specified by:
getDefaultValuein interfaceDslArg- Returns:
- the default value for the argument
-
isAllowMultipleValues
public boolean isAllowMultipleValues()
Description copied from interface:DslArgCheck whether this argument can take multiple values.- Specified by:
isAllowMultipleValuesin interfaceDslArg- Returns:
- true if and only if the argument takes multiple values.
-
getMultipleValueSeparator
public java.lang.String getMultipleValueSeparator()
Description copied from interface:DslArgGet the separator that can be used to separate multiple values.- Specified by:
getMultipleValueSeparatorin interfaceDslArg- Returns:
- the separator for splitting multiple values.
-
getAllowedValues
public java.lang.String[] getAllowedValues()
Description copied from interface:DslArgGet the specific values that this argument will accept.- Specified by:
getAllowedValuesin interfaceDslArg- 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- theClassthat 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()
-
-