Utils
Class SetSettings

java.lang.Object
  extended by Utils.SetSettings

public class SetSettings
extends java.lang.Object

Represents the value of settings. See Settings for further details of how settings are structured.

Version:
1.0

Constructor Summary
SetSettings()
          Default constructor
 
Method Summary
 boolean addSetting(java.lang.String setting, java.lang.String value)
          Adds a new root level setting
 boolean addSetting(java.lang.String group, java.lang.String setting, java.lang.String value)
          Adds a new setting within a group
static SetSettings fromFile(java.io.File f)
          Reads settings from a file and returns an instance of this class.
static SetSettings fromFileAndCommandLine(java.io.File f, java.lang.String[] c)
          Returns settings from a file and the command line and returns an instance of this class.
 java.util.Set<java.lang.String> getGroups()
          Gets the set of all groups that have had a setting set within them
 java.util.Set<java.lang.String> getSet()
          Gets the set of root level settings that have been set
 java.util.Set<java.lang.String> getSet(java.lang.String group)
          Gets the set of settings that have been set within a group
 java.lang.String getSetting(java.lang.String setting)
          Gets the value of a root level setting
 java.lang.String getSetting(java.lang.String group, java.lang.String setting)
          Gets the value of a setting within a group
 boolean isSet(java.lang.String setting)
          Tests whether a root level setting has been set
 boolean isSet(java.lang.String group, java.lang.String setting)
          Tests whether a setting within a groups has been set
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SetSettings

public SetSettings()
Default constructor

Method Detail

addSetting

public boolean addSetting(java.lang.String setting,
                          java.lang.String value)
Adds a new root level setting

Parameters:
setting - The setting name
value - The value to set the setting to
Returns:
True if this setting was previously set to a value, false otherwise

addSetting

public boolean addSetting(java.lang.String group,
                          java.lang.String setting,
                          java.lang.String value)
Adds a new setting within a group

Parameters:
group - The group name
setting - The setting name
value - The value to set the setting to
Returns:
True if this setting was previously set to a value

getSetting

public java.lang.String getSetting(java.lang.String setting)
Gets the value of a root level setting

Parameters:
setting - The setting's name
Returns:
The value the setting is set to

getSetting

public java.lang.String getSetting(java.lang.String group,
                                   java.lang.String setting)
Gets the value of a setting within a group

Parameters:
group - The group's name
setting - The setting's name
Returns:
The value the setting is set to

getGroups

public java.util.Set<java.lang.String> getGroups()
Gets the set of all groups that have had a setting set within them

Returns:
A set of groups

getSet

public java.util.Set<java.lang.String> getSet()
Gets the set of root level settings that have been set

Returns:
A set of root level settings

getSet

public java.util.Set<java.lang.String> getSet(java.lang.String group)
Gets the set of settings that have been set within a group

Parameters:
group - The group's name
Returns:
A set of settings

isSet

public boolean isSet(java.lang.String setting)
Tests whether a root level setting has been set

Parameters:
setting - The setting's name
Returns:
Whether the setting has been set

isSet

public boolean isSet(java.lang.String group,
                     java.lang.String setting)
Tests whether a setting within a groups has been set

Parameters:
group - The group's name
setting - The setting's anme
Returns:
Whether the setting has been set

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

fromFile

public static SetSettings fromFile(java.io.File f)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException,
                                   SettingException
Reads settings from a file and returns an instance of this class. Format of the setting file is:
  1. The group the following settings will be in is changed by a line with [group name] on it.
  2. Any setting before the first group line is treated as a root setting
  3. Settings are given one per line with the setting name followed by a tab followed by the settings value
  4. Anything following "//" and on the same line is consider a comment
  5. Blank and comment only lines are ignored

Parameters:
f - The file name
Returns:
The set settings
Throws:
java.io.FileNotFoundException - If the settings file is not found
java.io.IOException - If there is a problem reading from the settings file
SettingException - If there is a line in an unexpected format

fromFileAndCommandLine

public static SetSettings fromFileAndCommandLine(java.io.File f,
                                                 java.lang.String[] c)
                                          throws java.io.FileNotFoundException,
                                                 java.io.IOException,
                                                 SettingException
Returns settings from a file and the command line and returns an instance of this class. See fromFile(java.io.File) for file format. If the value of a setting contains $i (where i is an integer) then it is replaced by the ith element of c.

Parameters:
f - The settings file name
c - An array of command line inputs
Returns:
The set settings
Throws:
java.io.FileNotFoundException - If the settings file is not found
java.io.IOException - If there is a problem reading from the settings file
SettingException - If there is a line in an unexpected format