NOS.io
Class Settings

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable
          extended by NOS.io.Settings
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map

public class Settings
extends java.util.Hashtable

See Also:
Serialized Form

Constructor Summary
Settings()
          Creates a new Settings object.
Settings(java.io.InputStream in, char divider, boolean ignoreCase, boolean removeQuotesFromValues)
          Creates a new Settings object.
Settings(NOSFile file)
          Creates a new Settings object.
Settings(java.lang.String filenm)
          Creates a new Settings object.
Settings(java.lang.String filenm, char divider, boolean ignoreCase, boolean removeQuotesFromValues)
          Creates a new Settings object.
 
Method Summary
 void commitChanges()
          Forces a save to disk.
 boolean readBool(java.lang.String key, boolean def)
          Retrieve a boolean value from the store.
 int readColour(java.lang.String key, int def)
          Retrieve a hex integer value from the store.
 double readDouble(java.lang.String key, double def)
          Retrieve a double value from the store.
 float readFloat(java.lang.String key, float def)
          Retrieve a float value from the store.
 int readInt(java.lang.String key, int def)
          Retrieve a integer value from the store.
 java.lang.String readString(java.lang.String key, java.lang.String def)
          Retrieve a string value from the store.
 void refresh()
          Forces a re-read of the settings from storage.
 java.lang.String toString()
          Returns a string representation of this Settings store.
 void writeValue(java.lang.String key, java.lang.String value)
          Change/Add a value in/to the store.
 void writeValues(java.util.Hashtable values)
          Change/Add values in/to the store from all entries in the Hashtable.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Settings

public Settings()
Creates a new Settings object.


Settings

public Settings(NOSFile file)
Creates a new Settings object.

Parameters:
file - The NOSFile object to read from.

Settings

public Settings(java.lang.String filenm)
Creates a new Settings object.

Parameters:
filenm - The name of the file to associate with this group of settings.

Settings

public Settings(java.io.InputStream in,
                char divider,
                boolean ignoreCase,
                boolean removeQuotesFromValues)
Creates a new Settings object.

Parameters:
in - An InputStream to read settings from
divider - A divider char to use
ignoreCase - If true then the case of keys will be ignored
removeQuotesFromValues - Remove '!' quotes from settings file values

Settings

public Settings(java.lang.String filenm,
                char divider,
                boolean ignoreCase,
                boolean removeQuotesFromValues)
Creates a new Settings object.

Parameters:
filenm - The name of the file to associate with this group of settings.
divider - The divider to use between labels and values.
ignoreCase - If true then the case of keys will be ignored
removeQuotesFromValues - Remove '!' quotes from settings file values
Method Detail

refresh

public void refresh()
Forces a re-read of the settings from storage.


commitChanges

public void commitChanges()
Forces a save to disk. This method should be called before discarding a Settings object so that all the settings persist.


readString

public java.lang.String readString(java.lang.String key,
                                   java.lang.String def)
Retrieve a string value from the store. I the named string cannot be found then the default value is returned and stored in the Settings store. The next call to commitChanges will then save this default setting to persistant storage.

Parameters:
key - Identifing label.
def - Default value, returned if no value can be found.
Returns:
The String.

readColour

public int readColour(java.lang.String key,
                      int def)
Retrieve a hex integer value from the store. If the named int cannot be found then the default value is returned and stored in the Settings store. The next call to commitChanges will then save this default setting to persistant storage.

Parameters:
key - Identifing label.
def - Default value, returned if no value can be found.
Returns:
The int.

readInt

public int readInt(java.lang.String key,
                   int def)
Retrieve a integer value from the store. If the named int cannot be found then the default value is returned and stored in the Settings store. The next call to commitChanges will then save this default setting to persistant storage.

Parameters:
key - Identifing label.
def - Default value, returned if no value can be found.
Returns:
The int.

readDouble

public double readDouble(java.lang.String key,
                         double def)
Retrieve a double value from the store. If the named double cannot be found then the default value is returned and stored in the Settings store. The next call to commitChanges will then save this default setting to persistant storage.

Parameters:
key - Identifing label.
def - Default value, returned if no value can be found.
Returns:
The double.

readFloat

public float readFloat(java.lang.String key,
                       float def)
Retrieve a float value from the store. If the named float cannot be found then the default value is returned and stored in the Settings store. The next call to commitChanges will then save this default setting to persistant storage.

Parameters:
key - Identifing label.
def - Default value, returned if no value can be found.
Returns:
The float.

readBool

public boolean readBool(java.lang.String key,
                        boolean def)
Retrieve a boolean value from the store. If the named bool cannot be found then the default value is returned and stored in the Settings store. The next call to commitChanges will then save this default setting to persistant storage.

Parameters:
key - Identifing label.
def - Default value, returned if no value can be found.
Returns:
The boolean.

writeValue

public void writeValue(java.lang.String key,
                       java.lang.String value)
Change/Add a value in/to the store.

Parameters:
key - Identifing label.
value - Corresponding value.

writeValues

public void writeValues(java.util.Hashtable values)
Change/Add values in/to the store from all entries in the Hashtable.

Parameters:
values - A Hashtable of values.

toString

public java.lang.String toString()
Returns a string representation of this Settings store.

Overrides:
toString in class java.util.Hashtable
Returns:
A string representation.