Enhydra 3.1 API

com.lutris.util
Class Config

java.lang.Object
  |
  +--com.lutris.util.KeywordValueTable
        |
        +--com.lutris.util.Config

public class Config
extends KeywordValueTable

Config is essentially a KeywordValueTable used for recursive storage of data derived from a config file. The contents is initialized but ConfigFile.

Version:
$Revision: 1.24.12.1 $
See Also:
ConfigFile, KeywordValueTable, Serialized Form

Constructor Summary
Config()
          Default constructor for an empty Config.
Config(ConfigFile configFile)
          Constructor that associates this Config with a given ConfigFile.
Config(KeywordValueTable kvt)
          Constructor that takes a KeywordValueTable as initialization.
Config(KeywordValueTable kvt, ConfigFile configFile)
          Constructor that takes a KeywordValueTable and a ConfigFile as initialization.
 
Method Summary
 int containsCount(java.lang.String key)
          Returns the number of data elements for a given key, or -1 if the key is not found.
 boolean containsKey(java.lang.String key)
          Returns true if the specified key is found, false otherwise.
 boolean getBoolean(java.lang.String key)
          Returns a single boolean value associated with a given key.
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Returns a single boolean value associated with a given key.
 boolean[] getBooleans(java.lang.String key)
          Returns all boolean values associated with a given key.
 boolean[] getBooleans(java.lang.String key, boolean[] defaultValue)
          Returns all boolean values associated with a given key.
 Config getConfig(java.lang.String keyword)
          Get the value of a section as a Config object.
 ConfigFile getConfigFile()
          Get the ConfigFile associated with this object.
 double getDouble(java.lang.String key)
          Returns a single double value associated with a given key.
 double getDouble(java.lang.String key, double defaultValue)
          Returns a single double value associated with a given key.
 double[] getDoubles(java.lang.String key)
          Returns all double values associated with a given key.
 double[] getDoubles(java.lang.String key, double[] defaultValue)
          Returns all double values associated with a given key.
 int getInt(java.lang.String key)
          Returns a single integer value associated with a given key.
 int getInt(java.lang.String key, int defaultValue)
          Returns a single integer value associated with a given key.
 int[] getInts(java.lang.String key)
          Returns all integer values associated with a given key.
 int[] getInts(java.lang.String key, int[] defaultValue)
          Returns all integer values associated with a given key.
 long getLong(java.lang.String key)
          Returns a single long integer value associated with a given key.
 long getLong(java.lang.String key, long defaultValue)
          Returns a single long integer value associated with a given key.
 long[] getLongs(java.lang.String key)
          Returns all long integer values associated with a given key.
 long[] getLongs(java.lang.String key, long[] defaultValue)
          Returns all long integer values associated with a given key.
 KeywordValueTable getSection(java.lang.String keyword)
          Get the value of a section as a KeywordValueTable object.
 java.lang.String getString(java.lang.String key)
          Returns a single String value associated with a given key.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Returns a single String value associated with a given key.
 java.lang.String[] getStrings(java.lang.String key)
          Returns all String values associated with a given key.
 java.lang.String[] getStrings(java.lang.String key, java.lang.String[] defaultValue)
          Returns all String values associated with a given key.
 boolean isArray(java.lang.String key)
          Is the key is an array, or a single value.
protected  KeywordValueTable newSection()
          Allocate a new section.
 
Methods inherited from class com.lutris.util.KeywordValueTable
get, get, keys, leafKeys, remove, set, setDefault, toHtml, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Config

public Config()
Default constructor for an empty Config.

Config

public Config(KeywordValueTable kvt)
Constructor that takes a KeywordValueTable as initialization.
Parameters:
kvt - KeywordValueTable with which to initialize Config

Config

public Config(KeywordValueTable kvt,
              ConfigFile configFile)
Constructor that takes a KeywordValueTable and a ConfigFile as initialization. The ConfigFile is associated with this Config object.
Parameters:
kvt - KeywordValueTable with which to initialize Config
configFile - ConfigFile to associate this Config object with

Config

public Config(ConfigFile configFile)
Constructor that associates this Config with a given ConfigFile.
Parameters:
configFile - ConfigFile to associate this object with
Method Detail

newSection

protected KeywordValueTable newSection()
Allocate a new section. The overrides the default method to allocate a section that is of class Config.
Overrides:
newSection in class KeywordValueTable
Returns:
A reference to a new section.
See Also:
KeywordValueTable.newSection()

getConfigFile

public ConfigFile getConfigFile()
Get the ConfigFile associated with this object.
Returns:
the associated ConfigFile, null if there is no config file associated with this object.

getConfig

public Config getConfig(java.lang.String keyword)
                 throws KeywordValueException
Get the value of a section as a Config object.
Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Returns:
A reference to the section object or null if not found.
Throws:
KeywordValueException - If the keyword is not syntactically legal or a non-leaf element of the keyword is not a section or the value object is not a KeywordValueTable.
See Also:
KeywordValueTable.getSection(java.lang.String)

getSection

public KeywordValueTable getSection(java.lang.String keyword)
                             throws KeywordValueException
Get the value of a section as a KeywordValueTable object. This method overrides the KeywordValueTable.getSection in order to insure that Config.getSection() always returns a Config object even if a KeywordValueTable was inserted into the Config as a section.
Overrides:
getSection in class KeywordValueTable
Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Returns:
A reference to the section object or null if not found.
Throws:
KeywordValueException - If the keyword is not syntactically legal or a non-leaf element of the keyword is not a section or the value object is not a KeywordValueTable.
See Also:
KeywordValueTable.getSection(java.lang.String)

containsKey

public boolean containsKey(java.lang.String key)
Returns true if the specified key is found, false otherwise.
Overrides:
containsKey in class KeywordValueTable
Parameters:
key - The key whose existence is to be tested.
Returns:
true if the key was found, otherwise false.

containsCount

public int containsCount(java.lang.String key)
                  throws ConfigException
Returns the number of data elements for a given key, or -1 if the key is not found.
Parameters:
key - The key to search for.
Returns:
The number of entries for the given key, or -1 if the key is not found.

isArray

public boolean isArray(java.lang.String key)
                throws ConfigException
Is the key is an array, or a single value. If this returns true, you should use getStrings() (or if you know the type of the data, you can use, for example, getInts()). If this returns false, you shoud use getString() (or if you know the type of the data, you can use, for example, getInt()).
Parameters:
key - The key to search for.
Returns:
True if the key is an array, false if it is a single value.
Throws:
ConfigException - If the key is not found.

getLong

public long getLong(java.lang.String key)
             throws ConfigException
Returns a single long integer value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a long integer then a ConfigException exception is thrown.
Parameters:
key - The key to use to search for the configuration entry.
Returns:
The long integer value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getLong

public long getLong(java.lang.String key,
                    long defaultValue)
             throws ConfigException
Returns a single long integer value associated with a given key. If the key is associated with more than one element then a ConfigException error is thrown with reason set to COUNT. If the retrieved element cannot be converted to a long integer then a ConfigException error is thrown with reason set to FORMAT.
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The long integer value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getLongs

public long[] getLongs(java.lang.String key)
                throws ConfigException
Returns all long integer values associated with a given key. If any of the elements associated with the key cannot be converted to a long integer then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of longs containing the list of long values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getLongs

public long[] getLongs(java.lang.String key,
                       long[] defaultValue)
                throws ConfigException
Returns all long integer values associated with a given key. If any of the elements associated with the key cannot be converted to a long integer then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of longs containing the list of long values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

getInt

public int getInt(java.lang.String key)
           throws ConfigException
Returns a single integer value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a integer then a ConfigException exception is thrown.
Parameters:
key - The key to use to search for the configuration entry.
Returns:
The integer value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getInt

public int getInt(java.lang.String key,
                  int defaultValue)
           throws ConfigException
Returns a single integer value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a integer then a ConfigException exception is thrown.
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The integer value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getInts

public int[] getInts(java.lang.String key)
              throws ConfigException
Returns all integer values associated with a given key. If any of the elements associated with the key cannot be converted to a integer then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of integers containing the list of integer values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getInts

public int[] getInts(java.lang.String key,
                     int[] defaultValue)
              throws ConfigException
Returns all integer values associated with a given key. If any of the elements associated with the key cannot be converted to a integer then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of integers containing the list of integer values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

getString

public java.lang.String getString(java.lang.String key)
                           throws ConfigException
Returns a single String value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a String then a ConfigException exception is thrown.
Overrides:
getString in class KeywordValueTable
Parameters:
key - The key to use to search for the configuration entry.
Returns:
The string value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
                           throws ConfigException
Returns a single String value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a String then a ConfigException exception is thrown.
Overrides:
getString in class KeywordValueTable
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The string value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getStrings

public java.lang.String[] getStrings(java.lang.String key)
                              throws ConfigException
Returns all String values associated with a given key. If any of the elements associated with the key cannot be converted to a String then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of strings containing the list of string values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getStrings

public java.lang.String[] getStrings(java.lang.String key,
                                     java.lang.String[] defaultValue)
                              throws ConfigException
Returns all String values associated with a given key. If any of the elements associated with the key cannot be converted to a String then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of strings containing the list of string values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

getBoolean

public boolean getBoolean(java.lang.String key)
                   throws ConfigException
Returns a single boolean value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a boolean then a ConfigException exception is thrown.
Parameters:
key - The key to use to search for the configuration entry.
Returns:
The boolean value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
                   throws ConfigException
Returns a single boolean value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a boolean then a ConfigException exception is thrown.
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The boolean value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getBooleans

public boolean[] getBooleans(java.lang.String key)
                      throws ConfigException
Returns all boolean values associated with a given key. If any of the elements associated with the key cannot be converted to a boolean then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of booleans containing the list of boolean values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getBooleans

public boolean[] getBooleans(java.lang.String key,
                             boolean[] defaultValue)
                      throws ConfigException
Returns all boolean values associated with a given key. If any of the elements associated with the key cannot be converted to a boolean then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of booleans containing the list of boolean values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

getDouble

public double getDouble(java.lang.String key)
                 throws ConfigException
Returns a single double value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a double then a ConfigException exception is thrown.
Parameters:
key - The key to use to search for the configuration entry.
Returns:
The double value associated with the given key.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
                 throws ConfigException
Returns a single double value associated with a given key. If the key is associated with more than one element, or the retrieved element cannot be converted to a double then a ConfigException exception is thrown.
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
The double value associated with the given key.
Throws:
ConfigException - Thrown if there was not exactly one requested element, or if the element is of the wrong data type or format.
See Also:
ConfigException

getDoubles

public double[] getDoubles(java.lang.String key)
                    throws ConfigException
Returns all double values associated with a given key. If any of the elements associated with the key cannot be converted to a double then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
Returns:
An array of doubles containing the list of double values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entry does not exist or elements are not in the requested format.
See Also:
ConfigException

getDoubles

public double[] getDoubles(java.lang.String key,
                           double[] defaultValue)
                    throws ConfigException
Returns all double values associated with a given key. If any of the elements associated with the key cannot be converted to a double then a ConfigException error is thrown.
Parameters:
key - The key to use to search for the configuration entry.
defaultValue - The default value to use if the requested entry does not exist.
Returns:
An array of doubles containing the list of double values from the configuration input stream.
Throws:
ConfigException - Thrown if the requested entries are of the wrong data type or format.
See Also:
ConfigException

Enhydra 3.1 API