|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ptc.windchill.upgrade.tool.ArgumentProcessor
Loads all the menu options it receives from another *.class file. When a user makes a call with arguments the ArgumentProcessor checks if the argument matches an option that was previously loaded. The option is then checked for its type: Boolean.class, String.class, or Integer.class.
If the option is of type java.lang.Boolean, no argument needs to follow it. If the argument is of type java.lang.String or java.lang.Integer an argument needs to follow the option.
The String option should be followed by a string and an Integer option should be followed by an argument that is a string but can successfully be converted into an integer.
To load an option that does not need an argument, it can be done in two ways:
ArgumentProcessor ap = new ArgumentProcessor();
First option: ap.addBooleanOption("help"); Second option: ap.addOption("count", Integer.class);To check if the argument provided is an option:
ArgumentProcessor.ProcessedArguments processed_arguments = ap.process(args);To verify there was a match:
String[] opt_names = processed_args.getSelectedOptionNames();If the argument list originally looked like {"-h", "-count", "5", "abc"}, then:
processed_arguments.getArguments() => {"abc"} processed_arguments.getSelectedOptionNames() => {"h", "count"} NOTE: Order is not guaranteed processed_arguments.isOptionSet("h") => true processed_arguments.getOption("count") => 5 as a java.lang.Integer processed_arguments.isOptionSet("blue") => false processed_arguments.getOption("blue") => null
Nested Class Summary | |
static class |
ArgumentProcessor.ProcessedArguments
Inner class that stores the arguments, under the correct category. |
Field Summary | |
private HashMap |
optionDefinitions_
|
Constructor Summary | |
ArgumentProcessor()
Create an instance of ArgumentProcessor without using arguments |
Method Summary | |
void |
addBooleanOption(String option_name)
Adds an argument that should be treated as a boolean. |
void |
addIntegerOption(String option_name)
Adds an argument that should be treated as an integer. |
void |
addOption(String option_name,
Class option_type)
This method adds the different options to be loaded into the options list. |
void |
addStringOption(String option_name)
Adds an argument that should be treated as a string. |
private String |
getOptionNameFromArg(String arg)
|
private Class |
getOptionType(String opt_name)
Check if the command-line argument has a Class type that matches it. |
private boolean |
isOption(String arg)
Checks if an argument starts with a "-" or not. |
ArgumentProcessor.ProcessedArguments |
process(String[] args)
Checks if the argument(s) specified are options. |
void |
removeOption(String option_name)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private HashMap optionDefinitions_
Constructor Detail |
public ArgumentProcessor()
Method Detail |
public void addBooleanOption(String option_name)
Boolean.TRUE
and
ProcessedArguments.isOptionSet()
will report
true
. Otherwise, it will be null and ProcessedArguments.isOptionSet()
will report false
public void addIntegerOption(String option_name)
ProcessedArguments.isOptionSet()
will report
true
. Otherwise, it will be null and ProcessedArguments.isOptionSet()
will report false
.
public void addStringOption(String option_name)
ProcessedArguments.isOptionSet()
will report
true
. Otherwise, it will be null and ProcessedArguments.isOptionSet()
will report false
.
public void addOption(String option_name, Class option_type)
option_type
- Class
IllegalArgumentException
- if the Class type does not match
Boolean.class, String.class, or Integer.classpublic void removeOption(String option_name)
public ArgumentProcessor.ProcessedArguments process(String[] args) throws Exception
Exception
private boolean isOption(String arg)
private String getOptionNameFromArg(String arg)
private Class getOptionType(String opt_name)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |