acm.util
Class OptionTable

java.lang.Object
  extended by acm.util.OptionTable

public class OptionTable
extends Object

This class implements a simple tool for parsing key/value pairs from a string.


Constructor Summary
OptionTable(Map<String,String> map)
          Creates a new OptionTable from an existing map.
OptionTable(String str)
          Creates a new OptionTable and initializes it from the specified string.
OptionTable(String str, String[] keys)
          Creates a new OptionTable from the specified string, checking to make sure that all keys exist in the string array keys.
 
Method Summary
 double getDoubleOption(String key)
          Returns the double value associated with key in the option table, or 0.0 if no such value exists.
 double getDoubleOption(String key, double defValue)
          Returns the double value associated with key in the option table or the specified default value if no such binding exists.
 int getIntOption(String key)
          Returns the integer value associated with key in the option table, or 0 if no such value exists.
 int getIntOption(String key, int defValue)
          Returns the integer value associated with key in the option table or the specified default value if no such binding exists.
 HashMap<String,String> getMap()
          Returns the HashMap used to associate keys and options.
 String getOption(String key)
          Returns the value associated with key in the option table, or null if no such value exists.
 String getOption(String key, String defValue)
          Returns the value associated with key in the option table or the specified default value if no such binding exists.
 boolean isSpecified(String key)
          Returns true if the key has been specified in the option table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptionTable

public OptionTable(Map<String,String> map)
Creates a new OptionTable from an existing map. Most clients will not need to use this method.

Parameters:
map - An existing key/value mapping

OptionTable

public OptionTable(String str)
Creates a new OptionTable and initializes it from the specified string. The options in str are in two possible forms:
  1. key
  2. key=value
The first option sets the value associated with the key to the empty string; the second supplies the value explicitly.

Parameters:
str - The option string that is parsed to initialize the table

OptionTable

public OptionTable(String str,
                   String[] keys)
Creates a new OptionTable from the specified string, checking to make sure that all keys exist in the string array keys. If keys is null, checking is disabled.

Parameters:
str - The option string that is parsed to initialize the table
keys - An array of strings indicating the legal keys
Method Detail

getDoubleOption

public double getDoubleOption(String key)
Returns the double value associated with key in the option table, or 0.0 if no such value exists.

Parameters:
key - The key
Returns:
The corresponding option value parsed as a double

getDoubleOption

public double getDoubleOption(String key,
                              double defValue)
Returns the double value associated with key in the option table or the specified default value if no such binding exists.

Parameters:
key - The key
defValue - The default to use if the key is not found
Returns:
The corresponding option value

getIntOption

public int getIntOption(String key)
Returns the integer value associated with key in the option table, or 0 if no such value exists.

Parameters:
key - The key
Returns:
The corresponding option value parsed as an integer

getIntOption

public int getIntOption(String key,
                        int defValue)
Returns the integer value associated with key in the option table or the specified default value if no such binding exists.

Parameters:
key - The key
defValue - The default to use if the key is not found
Returns:
The corresponding option value

getMap

public HashMap<String,String> getMap()
Returns the HashMap used to associate keys and options.

Returns:
The HashMap used to associate keys and options

getOption

public String getOption(String key)
Returns the value associated with key in the option table, or null if no such value exists.

Parameters:
key - The key
Returns:
The corresponding option value

getOption

public String getOption(String key,
                        String defValue)
Returns the value associated with key in the option table or the specified default value if no such binding exists.

Parameters:
key - The key
defValue - The default to use if the key is not found
Returns:
The corresponding option value

isSpecified

public boolean isSpecified(String key)
Returns true if the key has been specified in the option table.

Parameters:
key - The key being checked
Returns:
true if key was specified in the option string