Documentation of 'jas2.util.GetOptions' Java class
GetOptions
jas2.util

Class GetOptions



  • public class GetOptions
    extends java.lang.Object
    GetOptions is used to help parse command line arguments. It is loosely based on Paul Raines' GetOpt module with modifications to handle multiple classes wanting access to the same arguments. The main design difference is that instead of doing all the work in the constructor we do it with addOption() and parseArgs(). Furthermore, the Hashtables are different, etc.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      static class  GetOptions.BadArguments
      Exception to throw when an invalid argument is encountered.
    • Constructor Summary

      Constructors 
      Constructor and Description
      GetOptions()
      Creates an empty GetOptions object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addOption(char shortName, boolean flag)
      Adds an option to be recognized by parseArgs.
      void addOption(char shortName, boolean flag, java.lang.String comment)
      Adds an option to be recognized by parseArgs.
      void addOption(java.lang.String longName, boolean flag)
      Adds an option to be recognized by parseArgs.
      void addOption(java.lang.String longName, boolean flag, java.lang.String comment)
      Adds an option to be recognized by parseArgs.
      void addOption(java.lang.String longName, char shortName, boolean flag)
      Adds an option to be recognized by parseArgs.
      void addOption(java.lang.String longName, char shortName, boolean flag, java.lang.String comment)
      Adds an option to be recognized by parseArgs.
      void addParam(java.lang.String param)
      Add a parmeter
      void dumpOptions() 
      java.lang.String getComment(java.lang.String longName)
      Returns the comment given for the option with the long name longName.
      java.lang.String getOption(java.lang.String longName)
      Returns the value given for the option with the long name longName.
      java.lang.String getParam(int pNum)
      Returns a specific parameter
      java.lang.String[] getParams()
      Returns list of parameters
      boolean hasOption(java.lang.String longName)
      Returns true or false depending on if the option with the long name longName was given in either the short (if one exists) or the long form.
      boolean isLegalOption(java.lang.String longName)
      Returns true or false depending on if the option with the long name longName is in fact a real option.
      int numParams()
      Returns number of parameters
      void parseArgs(java.lang.String[] argv)
      Parses the command line arguments.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GetOptions

        public GetOptions()
        Creates an empty GetOptions object. Options are added to the object using the addOption method, unlike GetOpt which adds them in the constructor.
    • Method Detail

      • addOption

        public void addOption(java.lang.String longName,
                              boolean flag)
        Adds an option to be recognized by parseArgs.
        Parameters:
        longName - the full name of the option
        flag - true if the option is a flag (takes 0 parameters), false otherwise
      • addOption

        public void addOption(java.lang.String longName,
                              boolean flag,
                              java.lang.String comment)
        Adds an option to be recognized by parseArgs.
        Parameters:
        longName - the full name of the option
        flag - true if the option is a flag (takes 0 parameters), false otherwise
        comment - description of the arguments to the option
      • addOption

        public void addOption(char shortName,
                              boolean flag)
        Adds an option to be recognized by parseArgs.
        Parameters:
        shortName - the single character name of the option
        flag - true if the option is a flag (takes 0 parameters), false otherwise
      • addOption

        public void addOption(char shortName,
                              boolean flag,
                              java.lang.String comment)
        Adds an option to be recognized by parseArgs.
        Parameters:
        shortName - the single character name of the option
        flag - true if the option is a flag (takes 0 parameters), false otherwise
        comment - description of the arguments to the option
      • addOption

        public void addOption(java.lang.String longName,
                              char shortName,
                              boolean flag)
        Adds an option to be recognized by parseArgs.
        Parameters:
        longName - the full name of the option
        shortName - the single character name of the option
        flag - true if the option is a flag (takes 0 parameters), false otherwise
      • addOption

        public void addOption(java.lang.String longName,
                              char shortName,
                              boolean flag,
                              java.lang.String comment)
        Adds an option to be recognized by parseArgs.
        Parameters:
        longName - the full name of the option
        shortName - the single character name of the option
        flag - true if the option is a flag (takes 0 parameters), false otherwise
        comment - description of the arguments to the option
      • isLegalOption

        public boolean isLegalOption(java.lang.String longName)
        Returns true or false depending on if the option with the long name longName is in fact a real option.
        Parameters:
        longName - a string describing the option to query for.
        Returns:
        true or false.
      • hasOption

        public boolean hasOption(java.lang.String longName)
        Returns true or false depending on if the option with the long name longName was given in either the short (if one exists) or the long form.
        Parameters:
        longName - a string describing the option to query for.
        Returns:
        true or false.
      • getOption

        public java.lang.String getOption(java.lang.String longName)
        Returns the value given for the option with the long name longName. Returns "FLAG" if the option was given but is a flag (takes no arguments).
        Parameters:
        longName - a string describing the option to query for.
        Returns:
        value of option, "FLAG" or null.
      • getComment

        public java.lang.String getComment(java.lang.String longName)
        Returns the comment given for the option with the long name longName.
        Parameters:
        longName - a string describing the option to query for.
        Returns:
        value of comment or null if no comment exists.
      • dumpOptions

        public void dumpOptions()
      • parseArgs

        public void parseArgs(java.lang.String[] argv)
                       throws GetOptions.BadArguments
        Parses the command line arguments.
        Parameters:
        argv - the array of arguments (eg. args as given to main())
        Throws:
        GetOptions.BadArguments - an invalid arg or wrong # of args is encountered
      • getParams

        public java.lang.String[] getParams()
        Returns list of parameters
      • getParam

        public java.lang.String getParam(int pNum)
        Returns a specific parameter
      • numParams

        public int numParams()
        Returns number of parameters
      • addParam

        public void addParam(java.lang.String param)
        Add a parmeter

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.