SimKit
Class Arguments

java.lang.Object
  |
  +--SimKit.Arguments

public class Arguments
extends java.lang.Object

A data structure class that supports add and retreive operations. Records consist of a key and a value; both are strings. This class can be used to encapsulate pairs of command line arguments where the first item is a key (or simulation variable name) and the second represents the key's value.

Implementation: The implementation is slow as snot, but shouldn't matter too much for small number of parameters. A hashtable might be better :-( in case used for lotsa things.


Constructor Summary
Arguments()
          Standard constructor - for normal usage
Arguments(java.lang.String tupleString)
          Construct the object with a string that contains key-value pairs, seperated by spaces.
Arguments(java.lang.String[] argv)
          Construct the object with an array of strings.
 
Method Summary
 void add(java.lang.String key)
          Add a boolean valued key-value record to the data structure.
 void add(java.lang.String key, java.lang.String value)
          Add a key-value record to the data structure.
 boolean exists(java.lang.String key)
          Search for a key in the database.
 void remove(java.lang.String key)
          Remove a key-value record from the data structure.
 java.lang.String retrieve(java.lang.String key)
          Retrieve a key from the database.
 double retrieve(java.lang.String key, double dDefault)
          Retrieve a key from the database.
 double retrieve(java.lang.String key, double dDefault, double min, double max)
          Retrieve a key from the database.
 java.lang.String retrieve(java.lang.String key, java.lang.String sDefault)
          Retrieve a key from the database.
 java.lang.String toString()
          Generate a textual summary of what arguments are currently in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Arguments

public Arguments(java.lang.String tupleString)
Construct the object with a string that contains key-value pairs, seperated by spaces.
Example: "key1 value1 key2 value2". Note that there must be an even number of "words" in the string as they are grouped logically in pairs.

Parameters:
tupleString - A string consisting of an even number of tokens seperated by spaces. It will be parsed into key-value pairs. Strings with quotes will not be parsed as a single token unfortunately.

Arguments

public Arguments(java.lang.String[] argv)
Construct the object with an array of strings. The strings will be paired up into key-value pairs.
The first pair: (argv[0], argv[1])
The next pair: (argv[2], argv[3])
etc ...

Parameters:
argv - The array of strings to initialize the object with.
Throws:
java.lang.IndexOutOfBoundsException - Thrown if there are not an even number of command line arguments.

Arguments

public Arguments()
Standard constructor - for normal usage

Method Detail

add

public void add(java.lang.String key,
                java.lang.String value)
Add a key-value record to the data structure. If a record with a matching key already exists in the database, it will be overwritten. Also, leading and trailing whitespace in the key is not significant.

Parameters:
key - The key of the record to add.
value - The value of the record to add.

add

public void add(java.lang.String key)
Add a boolean valued key-value record to the data structure. This functions adds that record, keyed on key, with a value of "true" set. If the key already exists, that record will be overwritten.

Parameters:
key - The key of the record to add.

remove

public void remove(java.lang.String key)
Remove a key-value record from the data structure. This functions finds the record with a matching key value of "true" set. Nothing happens if the key does not exist.

Parameters:
key - The key of the record to remove.

exists

public boolean exists(java.lang.String key)
Search for a key in the database.

Parameters:
key - The key of the record to find
Returns:
true if the record was found, false otherwise.

retrieve

public java.lang.String retrieve(java.lang.String key)
Retrieve a key from the database.

Parameters:
key - The key of the record to find
Returns:
The record value corresponding to the key, or null if the record was not found.

retrieve

public java.lang.String retrieve(java.lang.String key,
                                 java.lang.String sDefault)
Retrieve a key from the database.

Parameters:
key - The key of the record to find
sDefault - The default value of the double.
Returns:
The record value corresponding to the key, or sDefault if the record was not found.
See Also:
retrieve(String)

retrieve

public double retrieve(java.lang.String key,
                       double dDefault)
Retrieve a key from the database.

Parameters:
key - The key of the record to find
dDefault - The default value of the double.
Returns:
The record value corresponding to the key, or default if the record was not found. If a string is found in the database, but a double cannot be parsed from it, then the NumberFormatException will automatically be caught and the default value will be returned.
See Also:
retrieve(String)

retrieve

public double retrieve(java.lang.String key,
                       double dDefault,
                       double min,
                       double max)
Retrieve a key from the database.

Parameters:
key - The key of the record to find
dDefault - The default value of the double.
min - The minimum value that can be returned.
max - The maximum value that can be returned.
Returns:
The record value corresponding to the key, or dDefault if the record was not found. If a string is found in the database, but a double cannot be parsed from it, then the NumberFormatException will automatically be caught and the default value will be returned. Also, the default is returned if the value looked up is not in the allowable range, between min and max.
See Also:
retrieve(String)

toString

public java.lang.String toString()
Generate a textual summary of what arguments are currently in the database.

Overrides:
toString in class java.lang.Object
Returns:
A string containing a list of all key-value pairs in the databse.