Package edu.wisc.game.util

## Class ParseConfig

- java.lang.Object
- - java.util.Dictionary<K,​V>
  - - java.util.Hashtable<String,​Object>
    - - edu.wisc.game.util.ParseConfig

- All Implemented Interfaces:
    `Serializable`, `Cloneable`, `Map<String,​Object>`

      public final class ParseConfig
      extends Hashtable<String,​Object>

  This class is used to obtain configuration parameters, from a configuration file or from Java System Properties. If this is an applet, SecurityException is caught safely.
  Author:
    Qin Shi, Vladimir Menkov //@date 1999-2018
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ParseConfig()` | Creates an empty hashtable.
    `ParseConfig​(Reader in)` | Creates a hashtable that contains the parsed data obtained from an open reader (which may, for example, be associated with an open file), and then closes the reader.
    `ParseConfig​(String aFname)` | Creates a hashtable that contains the parsed contents of the specified configuration file.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `containsKey​(String aName)` |
    `String[]` | `enrichFromArgv​(String[] argv)` | Scans the argv array, identifying all elements of the form X=Y.
    `boolean` | `getBoolean​(String name, boolean defVal)` |
    `double` | `getDouble​(String name, double defVal)` |
    `<T extends Enum<T>> T` | `getEnum​(Class<T> retType, String name, T defVal)` |
    `int` | `getInt​(String name, int defVal)` |
    `long` | `getLong​(String name, long defVal)` |
    `boolean` | `getOption​(String aName, boolean aDefault)` | Gets the requested integer value from the hash table or from the Java system property aName.
    `int` | `getOption​(String aName, int aDefault)` | Gets the requested integer value from the hash table or from the Java system property aName.
    `String` | `getOption​(String aName, String aDefault)` | Gets the requested value from the hash table or from the Java system property aName.
    `Date` | `getOptionDate​(String aName, String aDefault)` | Gets a date parameter, in the format YYYY-MM-DD
    `double` | `getOptionDouble​(String aName, double aDefault)` | Gets the requested double value from the hash table or from the Java system property aName.
    `<T extends Enum<T>> T` | `getOptionEnum​(Class<T> retType, String aName, T defVal)` | Returns the value of the specified parameter if it can be interpreted as a value of the specified enumerated type.
    `<T extends Enum<T>> T[]` | `getOptionEnumArray​(Class<T> retType, String aName, T[] defVal)` | Reads a comma-separated array of enums.
    `long` | `getOptionLong​(String aName, long aDefault)` |
    `String` | `getParameter​(String aName)` | Gets the requested value from the hash table.
    `String` | `getString​(String name, String defVal)` |
    `static void` | `main​(String[] argv)` | Purely for testing.

    - ### Methods inherited from class java.util.Hashtable

      `clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, toString, values`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ParseConfig

          public ParseConfig()

      Creates an empty hashtable. That can be used simply as a convenient interface for accessing Java system options.

    - #### ParseConfig

          public ParseConfig​(String aFname)
                      throws FileNotFoundException,
                             IOException

      Creates a hashtable that contains the parsed contents of the specified configuration file.
      Parameters:
        `aFname` - Configuration file name.
      Throws:
        `FileNotFoundException`
        `IOException`

    - #### ParseConfig

          public ParseConfig​(Reader in)
                      throws IOException

      Creates a hashtable that contains the parsed data obtained from an open reader (which may, for example, be associated with an open file), and then closes the reader.

      The configuration file syntax:

      - Lines (or "tails" of lines) beginning with a '#' are comments, and are ignored
      - Blank lines are ignored
      - A line of the form

                    name  value

        or

                    name = value

        assigns a value to the named variable. The equal sign is optional. There can be a semicolon at the end of the line, but it's optional. The value may be a number (with no quotes), or a string surrounded by double quotes. If the string consists only of alphanumeric characters, with possible '/' and ':' chars, then quotes are optional too.

      A ParseConfig structure is created by reading a specified configuration file. The values of parameters stored in the table can be accessed by using accessor methods, such as getOption or getOptionDouble.

      This method throws various exceptions, so that the caller method could produce a meaningful error report.

      Parameters:
        `in` - A Reader (a file reader, etc.)
      Throws:
        `IOException`

  - ### Method Detail

    - #### getOption

          public String getOption​(String aName,
                                  String aDefault)

      Gets the requested value from the hash table or from the Java system property aName. The Java system property, if given, overrides the value from the hash table.

    - #### getOptionDouble

          public double getOptionDouble​(String aName,
                                        double aDefault)

      Gets the requested double value from the hash table or from the Java system property aName.

    - #### getOption

          public int getOption​(String aName,
                               int aDefault)

      Gets the requested integer value from the hash table or from the Java system property aName.

    - #### getOptionLong

          public long getOptionLong​(String aName,
                                    long aDefault)

    - #### getOption

          public boolean getOption​(String aName,
                                   boolean aDefault)

      Gets the requested integer value from the hash table or from the Java system property aName.

    - #### getOptionDate

          public Date getOptionDate​(String aName,
                                    String aDefault)
                             throws ParseException

      Gets a date parameter, in the format YYYY-MM-DD
      Parameters:
        `aDefault` - Default date, in format 'YYYY-MM-DD'
      Throws:
        `ParseException`

    - #### getOptionEnum

          public <T extends Enum<T>> T getOptionEnum​(Class<T> retType,
                                                     String aName,
                                                     T defVal)

      Returns the value of the specified parameter if it can be interpreted as a value of the specified enumerated type. If no parameter with the specified value has been supplied, or if its value cannot be interpreted as a value of the desired type, the supplied default value is returned
      Parameters:
        `defVal` - The default value to be returned. May be null.

    - #### getOptionEnumArray

          public <T extends Enum<T>> T[] getOptionEnumArray​(Class<T> retType,
                                                            String aName,
                                                            T[] defVal)

      Reads a comma-separated array of enums. E.g. -Dcolors=RED,GREEN,BLUE

    - #### containsKey

          public boolean containsKey​(String aName)

    - #### getParameter

          public String getParameter​(String aName)
                              throws IOException

      Gets the requested value from the hash table. If the value is not found, IOException is thrown.
      Throws:
        `IOException`

    - #### getLong

          public long getLong​(String name,
                              long defVal)

    - #### getInt

          public int getInt​(String name,
                            int defVal)

    - #### getDouble

          public double getDouble​(String name,
                                  double defVal)

    - #### getString

          public String getString​(String name,
                                  String defVal)

    - #### getBoolean

          public boolean getBoolean​(String name,
                                    boolean defVal)

    - #### getEnum

          public <T extends Enum<T>> T getEnum​(Class<T> retType,
                                               String name,
                                               T defVal)

    - #### enrichFromArgv

          public String[] enrichFromArgv​(String[] argv)

      Scans the argv array, identifying all elements of the form X=Y. For each such element, adds the (key,value) pair (X,Y) to this ParseConfig table.
      Returns:
        An array that contains all other elements from argv (those not of the form X=Y).

    - #### main

          public static void main​(String[] argv)
                           throws FileNotFoundException,
                                  IOException

      Purely for testing.
      Throws:
        `FileNotFoundException`
        `IOException`