Class Argument<T>
java.lang.Object
com.clumd.projects.java_common_utils.arg_parser.Argument<T>
This Class represents all the configuration required to parse a single Command Line Argument into a usable output
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionfinal voidattemptValueConversion(String value) This method should be called by the implementingCLIArgParserif a value is provided for this Argument.static <T> Argument.ArgumentBuilder<T>builder()protected booleanbooleanIf this argument needs a value, then this should be the fully validated and parsed output of that value.This function is used to convert an argument from the CLI string form, into the object the running process needs.This should be used as the default value, if nothing is provided for the conversion functionUsed to describe the purpose of this Argument and how it should be used.Used to contain all the word alias' to indicate this optionUsed to contain all the single character alias' to indicate this optionintUsed to index the options, must be unique and supplied by the user.This function can be provided to run a verification step that the argument's value is acceptable.inthashCode()booleanhasValue()Used to indicate if this argument can be followed by a value, defaults to falsebooleanUsed to track if a default value has been set for this argument to be used if no CLI value is found.booleanUsed to indicate if this argument is mandatory and MUST be provided for the utilising code to function.voidsetArgumentResult(T argumentResult) If this argument needs a value, then this should be the fully validated and parsed output of that value.voidsetDefaultValue(T defaultValue) This should be used as the default value, if nothing is provided for the conversion functionvoidsetDefaultValueSet(boolean defaultValueSet) Used to track if a default value has been set for this argument to be used if no CLI value is found.toString()final booleanIf a value is possible for this CLI Argument, then this method will be called to verify that the argument provided is acceptable by the calling process.booleanUsed to indicate if the value to this argument can be optional, defaults to false.
-
Method Details
-
attemptValueConversion
This method should be called by the implementingCLIArgParserif a value is provided for this Argument.- Parameters:
value- The CLI Argument's value to be parsed into the desired Java type, or a null if no argument provided
-
validateValue
public final boolean validateValue()If a value is possible for this CLI Argument, then this method will be called to verify that the argument provided is acceptable by the calling process. This works by calling the implementation-providedvalidationFunctionto decide if it is acceptable- Returns:
- True (default if no function was provided), if the value provided meets the acceptance criteria of the
validationFunction, False if it fails validation
-
builder
-
getUniqueId
public int getUniqueId()Used to index the options, must be unique and supplied by the user. -
getShortOptions
Used to contain all the single character alias' to indicate this option -
getLongOptions
Used to contain all the word alias' to indicate this option -
isMandatory
public boolean isMandatory()Used to indicate if this argument is mandatory and MUST be provided for the utilising code to function. If you set this value to true, you probably don't want to set a default value. -
hasValue
public boolean hasValue()Used to indicate if this argument can be followed by a value, defaults to false -
valueIsOptional
public boolean valueIsOptional()Used to indicate if the value to this argument can be optional, defaults to false. (e.g. value MUST be provided) -
getDescription
Used to describe the purpose of this Argument and how it should be used. -
getValidationFunction
This function can be provided to run a verification step that the argument's value is acceptable. -
getConversionFunction
This function is used to convert an argument from the CLI string form, into the object the running process needs. -
isDefaultValueSet
public boolean isDefaultValueSet()Used to track if a default value has been set for this argument to be used if no CLI value is found. -
getArgumentResult
If this argument needs a value, then this should be the fully validated and parsed output of that value. -
getDefaultValue
This should be used as the default value, if nothing is provided for the conversion function -
setDefaultValueSet
public void setDefaultValueSet(boolean defaultValueSet) Used to track if a default value has been set for this argument to be used if no CLI value is found. -
setArgumentResult
If this argument needs a value, then this should be the fully validated and parsed output of that value. -
setDefaultValue
This should be used as the default value, if nothing is provided for the conversion function -
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-