|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.gjt.btools.utilities.OptionSet
Provides a mechanism for a program to keep a set of options that can be stored in a file between program sessions. Each option has a string name associated with it, and can be read or altered using the various get and set member functions.
Constructor Summary | |
OptionSet()
Creates a new option set not associated with any file. |
|
OptionSet(java.io.File optionFile,
java.lang.String comment)
Creates a new option set based on the given file. |
|
OptionSet(java.io.File optionFile,
java.lang.String comment,
boolean forceLoad)
Creates a new option set based on the given file. |
Method Summary | |
boolean |
getBooleanOption(java.lang.String key)
Retrieves the value of a boolean option. |
boolean |
getBooleanOption(java.lang.String key,
boolean defaultOption)
Retrieves the value of a boolean option. |
int |
getIntOption(java.lang.String key)
Retrieves the value of an integer option. |
int |
getIntOption(java.lang.String key,
int defaultOption)
Retrieves the value of an integer option. |
java.lang.String |
getStringOption(java.lang.String key)
Retrieves the value of a string option. |
java.lang.String |
getStringOption(java.lang.String key,
java.lang.String defaultOption)
Retrieves the value of a string option. |
static java.lang.String |
getSystemProperty(java.lang.String key)
Gets the system property indicated by the specified key. |
static java.lang.String |
getSystemProperty(java.lang.String key,
java.lang.String def)
Gets the system property indicated by the specified key. |
protected void |
init()
Performs extra initialisation for a new option set that should take place before the options are read from file. |
protected void |
readFromFile()
Attempt to read this option set from file. |
void |
removeOption(java.lang.String key)
Removes the given option from this option set. |
void |
setBooleanOption(java.lang.String key,
boolean value)
Sets the value of a given boolean option. |
void |
setIntOption(java.lang.String key,
int value)
Sets the value of a given integer option. |
void |
setStringOption(java.lang.String key,
java.lang.String value)
Sets the value of a given string option. |
void |
writeToFile()
Attempt to write this option set to file. |
void |
writeToFile(boolean forceWrite)
Attempt to write this option set to file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public OptionSet()
The initialisation routine init() will be called from this constructor.
init()
public OptionSet(java.io.File optionFile, java.lang.String comment)
The initialisation routine init() will be called before the attempt to read the file.
optionFile
- the file to/from which this option set is to
be written/read.comment
- a comment to place at the beginning of the option
file when writing; this parameter is essentially irrelevant unless
you wish to hand-examine the option file. It does not matter if
the comment passed here is different to the existing comment in the
file; the existing comment will simply be overwritten.OptionSet(File, String, boolean)
,
init()
public OptionSet(java.io.File optionFile, java.lang.String comment, boolean forceLoad) throws java.io.IOException
The initialisation routine init() will be called before the attempt to read the file.
optionFile
- the file to/from which this option set is to
be written/read.comment
- a comment to place at the beginning of the option
file when writing; this parameter is essentially irrelevant unless
you wish to hand-examine the option file. It does not matter if
the comment passed here is different to the existing comment in the
file; the existing comment will simply be overwritten.forceLoad
- if set to false, we will ignore
any errors in reading from file. If set to true, an
exception will be thrown if an error occurs.
java.io.IOException
- thrown if an error occurs in reading from file.OptionSet(File, String)
,
init()
Method Detail |
protected void init()
protected void readFromFile() throws java.io.IOException
java.io.IOException
- thrown if an error occurs in reading from file.public void removeOption(java.lang.String key)
key
- the name of the requested option.public java.lang.String getStringOption(java.lang.String key)
key
- the name of the requested option.
public java.lang.String getStringOption(java.lang.String key, java.lang.String defaultOption)
key
- the name of the requested option.defaultOption
- the value to use if the requested option is
not in the set.
public void setStringOption(java.lang.String key, java.lang.String value)
key
- the name of the option to set.value
- the value to assign to the option.writeToFile()
public boolean getBooleanOption(java.lang.String key)
key
- the name of the requested option.
public boolean getBooleanOption(java.lang.String key, boolean defaultOption)
key
- the name of the requested option.defaultOption
- the value to use if the requested option is
not in the set.
public void setBooleanOption(java.lang.String key, boolean value)
key
- the name of the option to set.value
- the value to assign to the option.writeToFile()
public int getIntOption(java.lang.String key)
key
- the name of the requested option.
public int getIntOption(java.lang.String key, int defaultOption)
key
- the name of the requested option.defaultOption
- the value to use if the requested option is
not in the set.
public void setIntOption(java.lang.String key, int value)
key
- the name of the option to set.value
- the value to assign to the option.writeToFile()
public void writeToFile()
public void writeToFile(boolean forceWrite) throws java.io.IOException
forceWrite
- if set to false, we will ignore
any errors in writing to file. If set to true, an
exception will be thrown if an error occurs.
java.io.IOException
- thrown if an error occurs in writing to file.public static java.lang.String getSystemProperty(java.lang.String key)
key
- the name of the system property to retrieve.
public static java.lang.String getSystemProperty(java.lang.String key, java.lang.String def)
key
- the name of the system property to retrieve.def
- the default value to use if there is no property with
the given key.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |