public class ArgumentAnalyzer
extends java.lang.Object
| Constructor and Description |
|---|
ArgumentAnalyzer(boolean strictMode)
Constructor
Unknown flags are not treated as error.
|
ArgumentAnalyzer(boolean strictMode,
boolean unknowFlagAsError)
Constructor
|
ArgumentAnalyzer(int numberOfArgument)
Constructor for command line without any flag but data passed.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addFlag(java.lang.String id,
Flag flag)
Add flag to the argument analyzer
|
void |
addFlag(java.lang.String id,
java.lang.String flagName,
boolean isMandatory,
int nbData)
Add flag to the argument analyzer
|
java.util.List<java.lang.String> |
getFlagArgs(java.lang.String flagId) |
boolean |
isArgHasBeenFound(java.lang.String flagId)
Check is a given flag has been found during the parsing.
|
void |
parse(java.lang.String[] arguments)
Main job method.
|
public ArgumentAnalyzer(int numberOfArgument)
numberOfArgument - number of expected datapublic ArgumentAnalyzer(boolean strictMode)
strictMode - arguments must be given in a specific order and thus, unknown flags are not allowedpublic ArgumentAnalyzer(boolean strictMode,
boolean unknowFlagAsError)
throws ArgumentAnalyzerException
stictMode - arguments must be given in a specific order and thus, unknown flags are not allowedunknowFlagAsError - should we treat unknown flag as errorArgumentAnalyzerException - when strictMode is set to true
and unknowFlagAsError to false (these two notions are not really compatible.)public void addFlag(java.lang.String id,
java.lang.String flagName,
boolean isMandatory,
int nbData)
throws ArgumentAnalyzerException
id - id of the flagflagName - name of the flagisMandatory - is this flag mandatorynbData - number of expected data for this argumentArgumentAnalyzerExceptionpublic void addFlag(java.lang.String id,
Flag flag)
throws ArgumentAnalyzerException
id - id of the flagflag - The new argument.ArgumentAnalyzerException - id must be uniqueFlag}public void parse(java.lang.String[] arguments)
throws ArgumentAnalyzerException
arguments - arguments line to analyze.ArgumentAnalyzerExceptionpublic boolean isArgHasBeenFound(java.lang.String flagId)
throws ArgumentAnalyzerException
flagId - the target flag Id.ArgumentAnalyzerExceptionpublic java.util.List<java.lang.String> getFlagArgs(java.lang.String flagId)
throws ArgumentAnalyzerException
flagId - the target flag IdList containing the arguments for the target flag.
If no arguments are expected, an empty List is returned.
Whether the flag is not mandatory and has not been found, null is returnedArgumentAnalyzerException