|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object core.Settings
public class Settings
Interface for simulation settings stored in setting file(s). Settings
class should be initialized before using (with init(String)
). If
Settings isn't initialized, only settings in DEF_SETTINGS_FILE
are read. Normally, after initialization, settings in the given file can
override any settings defined in the default settings file and/or define
new settings.
All settings are key-value pairs. For parsing details see
Properties.getProperty(String)
. Value can be a single
value or comma separated list of values. With CSV values, CSV methods
must be used (e.g. getCsvInts(String, int)
). Setting value should
not start and end with a bracket since those are reserved for run-specific
values (see setRunIndex(int)
). In file paths directory separator
should always be forward slash ("/").
Field Summary | |
---|---|
static java.lang.String |
DEF_SETTINGS_FILE
file name of the default settings file ("default_settings.txt") |
static java.lang.String |
FILL_DELIMITER
delimiter for requested values in strings ("%%") |
protected static java.util.Properties |
props
properties object where the setting files are read into |
static java.lang.String |
SETTING_OUTPUT_S
Setting to define the file name where all read settings are written ("Settings.output". |
Constructor Summary | |
---|---|
Settings()
Create a setting object without namespace. |
|
Settings(java.lang.String namespace)
Creates a setting object with a namespace. |
Method Summary | |
---|---|
static void |
addSettings(java.lang.String propFile)
Reads another settings file and adds the key-value pairs to the current settings overriding any values that already existed with the same keys. |
void |
assertValidRange(int[] range,
java.lang.String sname)
Checks that the given integer array contains a valid range. |
boolean |
contains(java.lang.String name)
Returns true if a setting with defined name (in the current namespace or secondary namespace if such is set) exists and has some value (not just white space) |
java.lang.Object |
createIntializedObject(java.lang.String className)
Creates (and dynamically loads the class of) an object that intializes itself using the settings in this Settings object (given as the only parameter to the constructor). |
java.lang.Object |
createObject(java.lang.String className)
Creates (and dynamically loads the class of) an object using the constructor without any parameters. |
boolean |
getBoolean(java.lang.String name)
Returns a boolean-valued setting |
double[] |
getCsvDoubles(java.lang.String name)
Returns an array of CSV setting double values. |
double[] |
getCsvDoubles(java.lang.String name,
int expectedCount)
Returns an array of CSV setting double values containing expected amount of values. |
int[] |
getCsvInts(java.lang.String name)
Returns an array of CSV setting integer values |
int[] |
getCsvInts(java.lang.String name,
int expectedCount)
Returns an array of CSV setting integer values |
java.lang.String[] |
getCsvSetting(java.lang.String name)
Returns a CSV setting. |
java.lang.String[] |
getCsvSetting(java.lang.String name,
int expectedCount)
Returns a CSV setting containing expected amount of values. |
double |
getDouble(java.lang.String name)
Returns a double-valued setting |
java.lang.String |
getFullPropertyName(java.lang.String setting)
Returns full (namespace prefixed) property name for a setting. |
int |
getInt(java.lang.String name)
Returns an integer-valued setting |
java.lang.String |
getNameSpace()
Returns the namespace of the settings object |
java.lang.String |
getSetting(java.lang.String name)
Returns a String-valued setting. |
static void |
init(java.lang.String propFile)
Initializes the settings all Settings objects will use. |
void |
restoreNameSpace()
Restores the namespace that was in use before a call to setNameSpace |
void |
restoreSecondaryNamespace()
Restores the secondary namespace that was in use before a call to setSecondaryNameSpace |
void |
setNameSpace(java.lang.String namespace)
Sets the namespace to something else than the current namespace. |
static void |
setRunIndex(int index)
Sets the run index for the settings (only has effect on settings with run array). |
void |
setSecondaryNamespace(java.lang.String namespace)
Sets a secondary namespace where a setting is searched from if it isn't found from the primary namespace. |
java.lang.String |
toString()
Returns a String representation of the stored settings |
java.lang.String |
valueFillString(java.lang.String input)
Fills a String formatted in a special way with values from Settings. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static java.util.Properties props
public static final java.lang.String DEF_SETTINGS_FILE
public static final java.lang.String SETTING_OUTPUT_S
public static final java.lang.String FILL_DELIMITER
valueFillString(String)
,
Constant Field ValuesConstructor Detail |
---|
public Settings(java.lang.String namespace)
namespace
- Namespace to usepublic Settings()
Method Detail |
---|
public static void setRunIndex(int index)
[settingFor1stRun ; settingFor2ndRun ; SettingFor3rdRun]
runIndex % arrayLength
).
To disable whole run-index-thing, set index to value smaller than
zero (e.g. -1). When disabled, run-arrays are returned as normal values,
including the brackets.
index
- The run index to use for subsequent settings calls, or
-1 to disable run indexingpublic void assertValidRange(int[] range, java.lang.String sname) throws SettingsError
first_value <= second_value
.
range
- The range arraysname
- Name of the setting (for error messages)
SettingsError
- If the given array didn't qualify as a rangepublic void setNameSpace(java.lang.String namespace)
restoreNameSpace()
namespace
- The new namespacepublic java.lang.String getFullPropertyName(java.lang.String setting)
setting
- The name of the setting
public java.lang.String getNameSpace()
public void setSecondaryNamespace(java.lang.String namespace)
restoreSecondaryNamespace()
namespace
- The new secondary namespace or null if secondary
namespace is not used (default behavior)public void restoreNameSpace()
setNameSpace(String)
public void restoreSecondaryNamespace()
setSecondaryNamespace(String)
public static void init(java.lang.String propFile) throws SettingsError
DEF_SETTINGS_FILE
, if exists, is always read.
propFile
- Path to the property file where additional settings
are read from or null if no additional settings files are needed.
SettingsError
- If loading the settings file(s) didn't succeedpublic static void addSettings(java.lang.String propFile) throws SettingsError
propFile
- Path to the property file
SettingsError
- If loading the settings file didn't succeedinit(String)
public boolean contains(java.lang.String name)
name
- Name of the setting to check
public java.lang.String getSetting(java.lang.String name)
name
- Name of the setting to get
SettingsError
- if the setting is not found from either one of
the namespacespublic double getDouble(java.lang.String name)
name
- Name of the setting to get
public java.lang.String[] getCsvSetting(java.lang.String name)
name
- Name of the setting
SettingsError
- if something went wrong with readingpublic java.lang.String[] getCsvSetting(java.lang.String name, int expectedCount)
name
- Name of the settingexpectedCount
- how many values are expected
SettingsError
- if something went wrong with reading or didn't
read the expected amount of values.public double[] getCsvDoubles(java.lang.String name, int expectedCount)
name
- Name of the settingexpectedCount
- how many values are expected
getCsvSetting(String, int)
public double[] getCsvDoubles(java.lang.String name)
name
- Name of the setting
getCsvSetting(String)
public int[] getCsvInts(java.lang.String name, int expectedCount)
name
- Name of the settingexpectedCount
- how many values are expected
getCsvSetting(String, int)
public int[] getCsvInts(java.lang.String name)
name
- Name of the setting
getCsvSetting(String, int)
public int getInt(java.lang.String name)
name
- Name of the setting to get
public boolean getBoolean(java.lang.String name)
name
- Name of the setting to get
SettingsError
- if the value wasn't any recognized valuegetSetting(String)
public java.lang.Object createIntializedObject(java.lang.String className)
className
- Name of the class of the object
SettingsError
- if object couldn't be createdpublic java.lang.Object createObject(java.lang.String className)
className
- Name of the class of the object
SettingsError
- if object couldn't be createdpublic java.lang.String valueFillString(java.lang.String input)
FILL_DELIMITER
). Values for those settings
are retrieved and filled in the place of place holders.
input
- The input string that may contain value requests
SettingsError
- if such settings were not foundpublic java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |