public class ArgOptions extends Object
parseOptions
 must be called, which will disect an array of Strings and create values for
 each option.  For all option types, a default value may be specified when
 requesting the option value.  In the case of options corresponding to
 classnames, the accessor assumes that no argument constructor exists.
 
 Below are some common usages of this class:
 
 
 ArgOptions opts = new ArgOptions();
 opts.addOption('c', "numClusters", "the number of clusters",
                true, "INT", "Required");
 opts.addOption('C', "clustering", "the clustering algorithm",
                true, "CLASSNAME", "Required");
 opts.addOption('v', "verbose", "true if logs should be emitted",
                false, null, "Optional");
 opts.parseOptions(args);
 int numClusters = opts.getIntOption('c');
 boolean verbose = opts.hasOption('v');
 String clusterName = opts.getStringOption('C');
 | Constructor and Description | 
|---|
| ArgOptions()Constructs an empty  ArgOptionswith no options available. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | addOption(char shortName,
         String longName,
         String description)Creates an option that is in the default group and takes no values and
 adds to the set of possible options. | 
| void | addOption(char shortName,
         String longName,
         String description,
         boolean hasValue,
         String valueName)Creates an option in the default group using the provided parameters and
 adds it to the set of possible options. | 
| void | addOption(char shortName,
         String longName,
         String description,
         boolean hasValue,
         String valueName,
         String optionGroupName)Creates an option based on the provided parameters and adds the option to
 the set of possible options. | 
| boolean | getBooleanOption(char shortName)Returns the boolean value associated with the  shortNameoption. | 
| boolean | getBooleanOption(char shortName,
                boolean defaultValue)Returns the value associated with the  shortName, ordefaultValueif no value was found during parsing. | 
| boolean | getBooleanOption(String optionName)Returns the boolean value associated with the  optionNameoption. | 
| boolean | getBooleanOption(String optionName,
                boolean defaultValue)Returns the value associated with the  optionName, ordefaultValueif no value was found during parsing. | 
| double | getDoubleOption(char shortName)Returns the double value associated with the  shortNameoption. | 
| double | getDoubleOption(char shortName,
               double defaultValue)Returns the value associated with the  shortName, ordefaultValueif no value was found during parsing. | 
| double | getDoubleOption(String optionName)Returns the double value associated with the  optionNameoption. | 
| double | getDoubleOption(String optionName,
               double defaultValue)Returns the value associated with the  shortName, ordefaultValueif no value was found during parsing. | 
| int | getIntOption(char shortName)Returns the int value associated with the  shortNameoption. | 
| int | getIntOption(char shortName,
            int defaultValue)Returns the value associated with the  shortName, ordefaultValueif no value was found during parsing. | 
| int | getIntOption(String optionName)Returns the int value associated with the  optionNameoption. | 
| int | getIntOption(String optionName,
            int defaultValue)Returns the value associated with the  shortName, ordefaultValueif no value was found during parsing. | 
| long | getLongOption(char shortName)Returns the long value associated with the  shortNameoption. | 
| long | getLongOption(char shortName,
             long defaultValue)Returns the value associated with the  shortName, ordefaultValueif no value was found during parsing. | 
| long | getLongOption(String optionName)Returns the long value associated with the  optionNameoption. | 
| long | getLongOption(String optionName,
             long defaultValue)Returns the value associated with the  shortName, ordefaultValueif no value was found during parsing. | 
| <T> T | getObjectOption(char optionName,
               T defaultValue)Returns a class instance of the class specified associated with  optionName, ordefaultValueif there is no value for the
 argument. | 
| <T> T | getObjectOption(String optionName,
               T defaultValue)Returns a class instance of the class specified associated with  optionName, ordefaultValueif there is no value for the
 argument. | 
| String | getPositionalArg(int argNum)Returns the argument that was provided at the position based on the
 original ordering. | 
| List<String> | getPositionalArgs()Returns the positional arguments in the order they were provided. | 
| String | getStringOption(char shortName)Returns the String value associated with the  shortNameoption. | 
| String | getStringOption(char shortName,
               String defaultValue)Returns the value associated with the  shortName, ordefaultValueif no value was found during parsing. | 
| String | getStringOption(String optionName)Returns the boolean value associated with the  optionNameoption. | 
| String | getStringOption(String optionName,
               String defaultValue)Returns the value associated with the  optionName, ordefaultValueif no value was found during parsing. | 
| boolean | hasOption(char shortName)Returns true if there is a value for the short option name. | 
| boolean | hasOption(String optionName)Returns true if there is a value for the long option name. | 
| int | numPositionalArgs()Returns the number of positional arguments specified on the command line. | 
| int | numProvidedOptions()Returns the number of options that were specified on the command line. | 
| void | parseOptions(String[] commandLine) | 
| String | prettyPrint()Returns a pretty-print formated string describing all of the options and
 their arguments. | 
| void | removeOption(char shortName)Removes the  Optionmapped by the givenshortName. | 
| void | removeOption(String longName)Removes the  Optionmapped by the givenlongName. | 
| String | toString()Returns a string description of the options that are currently set and
 their values. | 
public ArgOptions()
ArgOptions with no options available.public void addOption(char shortName,
             String longName,
             String description)
shortName - a one character short name for specify this option.longName - a string name for specifying this option.description - an optional descritpion for this option, or null if no description is to be provided.IllegalArgumentException - if shortName or the same longName
         has been already been added. public void addOption(char shortName,
             String longName,
             String description,
             boolean hasValue,
             String valueName)
shortName - a one character short name for specify this option.longName - a string name for specifying this option.description - an optional descritpion for this option, or null if no description is to be provided.hasValue - whether this option takes a value.valueName - if this option takes a value, the name of that valueIllegalArgumentException - if shortName or the same longName
         has been already been added. hasArg is true but valueName is null.  public void addOption(char shortName,
             String longName,
             String description,
             boolean hasValue,
             String valueName,
             String optionGroupName)
shortName - a one character short name for specify this option.longName - a string name for specifying this option.description - an optional descritpion for this option, or null if no description is to be provided.hasValue - whether this option takes a value.valueName - if this option takes a value, the name of that valueoptionGroupName - the name of a group if this option is part of a
        specific subset of the options, or null if this is a
        generic optionIllegalArgumentException - if shortName or the same longName
         has been already been added. hasArg is true but valueName is null.  public void removeOption(char shortName)
Option mapped by the given shortName.  This
 also removes the mapping from the long name if one exists.shortName - The short name key of the option to remove.public void removeOption(String longName)
Option mapped by the given longName.  This
 also removes the mapping from the short name if one exists.longName - The long name key of the option to remove.public void parseOptions(String[] commandLine)
commandLine - the set of string arguments provided on the command
        linepublic int numPositionalArgs()
public int numProvidedOptions()
public String getPositionalArg(int argNum)
public List<String> getPositionalArgs()
public double getDoubleOption(char shortName)
shortName option.IllegalArgumentException - If no value was provided for shortNamepublic double getDoubleOption(char shortName,
                     double defaultValue)
shortName, or defaultValue if no value was found during parsing.public double getDoubleOption(String optionName)
optionName option.IllegalArgumentException - If no value was provided for shortNamepublic double getDoubleOption(String optionName, double defaultValue)
shortName, or defaultValue if no value was found during parsing.public long getLongOption(char shortName)
shortName option.IllegalArgumentException - If no value was provided for shortNamepublic long getLongOption(char shortName,
                 long defaultValue)
shortName, or defaultValue if no value was found during parsing.public long getLongOption(String optionName)
optionName option.IllegalArgumentException - If no value was provided for shortNamepublic long getLongOption(String optionName, long defaultValue)
shortName, or defaultValue if no value was found during parsing.public int getIntOption(char shortName)
shortName option.IllegalArgumentException - If no value was provided for shortNamepublic int getIntOption(char shortName,
               int defaultValue)
shortName, or defaultValue if no value was found during parsing.public int getIntOption(String optionName)
optionName option.IllegalArgumentException - If no value was provided for shortNamepublic int getIntOption(String optionName, int defaultValue)
shortName, or defaultValue if no value was found during parsing.public boolean getBooleanOption(char shortName)
shortName option.IllegalArgumentException - If no value was provided for shortNamepublic boolean getBooleanOption(char shortName,
                       boolean defaultValue)
shortName, or defaultValue if no value was found during parsing.public boolean getBooleanOption(String optionName)
optionName option.IllegalArgumentException - If no value was provided for shortNamepublic boolean getBooleanOption(String optionName, boolean defaultValue)
optionName, or defaultValue if no value was found during parsing.public String getStringOption(char shortName)
shortName option.IllegalArgumentException - If no value was provided for shortNamepublic String getStringOption(char shortName, String defaultValue)
shortName, or defaultValue if no value was found during parsing.public String getStringOption(String optionName)
optionName option.IllegalArgumentException - If no value was provided for shortNamepublic <T> T getObjectOption(char optionName,
                    T defaultValue)
optionName, or defaultValue if there is no value for the
 argument.  This method assumes that the class has a no argument
 constructor.public <T> T getObjectOption(String optionName, T defaultValue)
optionName, or defaultValue if there is no value for the
 argument.  This method assumes that the class has a no argument
 constructor.public String getStringOption(String optionName, String defaultValue)
optionName, or defaultValue if no value was found during parsing.public boolean hasOption(String optionName)
public boolean hasOption(char shortName)
public String prettyPrint()
Copyright © 2012. All Rights Reserved.