|
qflib 0.98.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--de.qfs.lib.option.OptionSet
An OptionSet bundles Options together, offering convenience methods for easy, typed access to their values. Default values must be provided in many cases, to avoid exception handling.
New in qflib 0.97.0:
Options from nested OptionSets can be queried and set by building a kind of
Option path name with a slash '/' as separator.
Example:
If OptionSet options has a nested OptionSet in an Option named 'a', which
in turn has a StringOption named 'b', then
options.getString("a/b", null)
will get the string value from the nested Option 'b'. If options contains
an Option named a/b' however, it will be accessed instead.
Field Summary | |
protected java.util.Map |
options
The Options of the OptionSet. |
Constructor Summary | |
OptionSet(java.lang.String name)
Create a new OptionSet. |
Method Summary | |
void |
add(Option option)
Add an option to the OptionSet. |
void |
addAll(OptionSet set)
Add all options from another OptionSet to the OptionSet. |
java.lang.Object |
clone()
Creates a deep copy of the OptionSet. |
boolean |
getBoolean(java.lang.String name,
boolean def)
Get the boolean value from an Option in the OptionSet. |
java.lang.String |
getConfigurableName()
Get the Configurable's name. |
java.util.Properties |
getConfigurableState()
Get the Configurable's state. |
java.io.File |
getFile(java.lang.String name,
java.io.File def)
Get the File value from an Option in the OptionSet. |
int |
getInt(java.lang.String name,
int def)
Get the int value from an Option in the OptionSet. |
Option |
getOption(java.lang.String name)
Get an Option from the OptionSet. |
Option[] |
getOptions()
Get all Options from the OptionSet. |
java.lang.String |
getString(java.lang.String name,
java.lang.String def)
Get the String value from an Option in the OptionSet. |
java.lang.Object |
getValue(java.lang.String name,
java.lang.Object def)
Get the value from an Option in the OptionSet. |
java.lang.String |
listOptions()
Print the options in the OptionSet to a string. |
void |
registrationChanged(Configuration config,
java.lang.String name,
boolean registered,
boolean valuesKept)
This callback is used to register or unregister nested OptionSets. |
void |
remove(java.lang.String name)
Remove an Option from the OptionSet. |
void |
setConfigurableName(java.lang.String configurableName)
Set the Configurable's name. |
void |
setConfigurableState(java.util.Properties state)
Set the Configurable's state. |
void |
update(java.util.Observable obs,
java.lang.Object arg)
Update the OptionSet. |
Methods inherited from class java.util.Observable |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected transient java.util.Map options
Constructor Detail |
public OptionSet(java.lang.String name)
name
- The name to use as a Configurable.Method Detail |
public void add(Option option)
option
- The Option to add.public void addAll(OptionSet set)
set
- The source of the Options to add.public void remove(java.lang.String name)
name
- The name of the Option to remove.public Option getOption(java.lang.String name)
name
- The name of the Option.public Option[] getOptions()
public java.lang.Object getValue(java.lang.String name, java.lang.Object def)
name
- The name of the option.def
- A default value in case the name is unknown.public boolean getBoolean(java.lang.String name, boolean def)
name
- The name of the option.def
- A default value in case the name is unknown.public int getInt(java.lang.String name, int def)
name
- The name of the option.def
- A default value in case the name is unknown.public java.lang.String getString(java.lang.String name, java.lang.String def)
name
- The name of the option.def
- A default value in case the name is unknown.public java.io.File getFile(java.lang.String name, java.io.File def)
name
- The name of the option.def
- A default value in case the name is unknown.public final java.lang.String getConfigurableName()
getConfigurableName
in interface Configurable
public final void setConfigurableName(java.lang.String configurableName)
setConfigurableName
in interface Configurable
name
- The name to set.public java.util.Properties getConfigurableState()
getConfigurableState
in interface Configurable
public void setConfigurableState(java.util.Properties state)
setConfigurableState
in interface Configurable
state
- The state to set.public void registrationChanged(Configuration config, java.lang.String name, boolean registered, boolean valuesKept)
registrationChanged
in interface Configurable
config
- The affected Configuration.name
- The registration name of the Configurable which may
be different from the Configurable's name.registered
- True if the Configurable was just registered,
false if it was unregistered.valuesKept
- Whether the Configurable's values were kept, if
it was just unregistered.public void update(java.util.Observable obs, java.lang.Object arg)
update
in interface java.util.Observer
obs
- The Option that has changed.arg
- Details about the change.public java.lang.Object clone()
NestedOptions
. A shallow copy can be obtained via
OptionSet newSet = new OptionSet("name"); newSet.addAll(originalSet);
clone
in class java.lang.Object
public java.lang.String listOptions()
|
qflib 0.98.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |