Package org.rwtodd.args
Class BasicOneArgParam<T>
java.lang.Object
org.rwtodd.args.BasicOneArgParam<T>
- Type Parameters:
T- the type of the value maintained by this parameter.
- All Implemented Interfaces:
OneArgParam,Param
- Direct Known Subclasses:
DoubleParam,ExistingDirectoryParam,ExistingFileParam,IntListParam,IntParam,StringParam
A base class for a typical 1-argument parameter. It is expected
that many custom parameters can be built as one-off anonymous classes
with this class as the base.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Tprotected final Stringprotected final Collection<String> -
Constructor Summary
ConstructorsConstructorDescriptionBasicOneArgParam(Collection<String> names, T dflt, String help) Construct a parameter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHelp(PrintStream ps) adds help for this parameter to the given stream.voidAdd the parameter's names to aMap<String,Param>.protected abstract TconvertArg(String param, String arg) A conversion method to get a T from a string.getValue()Fetch the value stored by this parameter.voidProcess an parameter with its argument.protected TA validation method which subclasses can override to restrict the valid values of the argument.
-
Field Details
-
arg
-
paramNames
-
helpText
-
-
Constructor Details
-
BasicOneArgParam
Construct a parameter.- Parameters:
names- a collection of names by which this parameter can be referenced on the command line.dflt- the default, starting value of the parameter.help- the help string for this parameter.
-
-
Method Details
-
getValue
Fetch the value stored by this parameter.- Returns:
- the value.
-
addToMap
Description copied from interface:ParamAdd the parameter's names to aMap<String,Param>. -
addHelp
Description copied from interface:Paramadds help for this parameter to the given stream. -
convertArg
A conversion method to get a T from a string. All subclasses must define this for the type they handle.- Parameters:
param- the name of the parameter found on the command line. In some cases it might affect conversion, but it is also good for error messages.arg- the argument to convert to a type T.- Returns:
- the converted argument.
- Throws:
Exception- if there is a problem with the conversion.
-
validate
A validation method which subclasses can override to restrict the valid values of the argument.- Parameters:
param- the name of the given parameter.arg- the argument to the parameter, as coverted byconvertArg(String, String).- Returns:
- the validated arg, which doesn't have to mach the provided arg.
- Throws:
Exception- if the provided arg was invalid.
-
process
Description copied from interface:OneArgParamProcess an parameter with its argument.- Specified by:
processin interfaceOneArgParam- Parameters:
param- the name of the parameter, as it was found in the command-line.argument- the given argument to the parameter.- Throws:
ArgParserException- if there is a problem parsing the argument.
-