This class is used to load and store external configuration data with objects of class Configuration and its plug-ins ConfigurationPlugin.
Construction/Redeclaration:
While constructors accepting attributes of a variable exist, it is recommended to declare all external configuration variables in a central place, using statically or dynamically allocated objects of type VariableDecl and pass such record to the constructor of a variable.
The class is designed to be 'reused' to avoid repeated allocation/de-allocation of memory. After invoking one of the overloaded methods declare, which share the same signatures as the overloaded constructors, a variable is freshly initialized. Internally, the memory allocated for values remains allocated.
Values:
A variable can contain zero, one or several values. If zero, then the variable was either not loaded, yet or the load operation failed (no configuration plug-in defined the variable). Method size reports the currently available values and methods getString(int), getInteger(int) and getFloat(int) return a value. Internally all values are stored as strings. If field config is set, its field Configuration.numberFormat is used for floating point conversion.
When storing a variable that contains more than one value, field delim has to be set. Conversely, when reading a variable that contains multiple values, the delimiter has to be set prior to the load operation.
Loading and Storing:
There are two ways of loading and storing a variable:
Storing empty variables (method size returns 0
) deletes a variable from the those configuration plug-ins that are write enabled.
Public Static Fields | |
static final int | FORMAT_HINT_CUSTOM = 1 << 16 |
static final int | FORMAT_HINT_MULTILINE = 1 << 0 |
static final int | FORMAT_HINT_NO_DELIM_SPACES = 1 << 1 |
static final int | FORMAT_HINT_NONE = 0 |
Public Fields | |
AString | category = new AString() |
AString | comments = new AString() |
Configuration | config = null |
AString | defaultValue = new AString() |
char | delim = '\0' |
String | formatAttrAlignment |
int | formatHints |
AString | fullname = new AString() |
AString | name = new AString() |
int | priority = 0 |
Public Methods | |
Variable () | |
Variable (CharSequence category, CharSequence name) | |
Variable (CharSequence category, CharSequence name, char delim) | |
Variable (CharSequence category, CharSequence name, char delim, CharSequence comments) | |
Variable (Variable variable) | |
Variable (VariableDecl declaration, Object... replacements) | |
AString | add () |
AString | add (boolean value) |
AString | add (Object value) |
Variable | clearValues () |
Variable | clearValues (int startIdx) |
Variable | declare (CharSequence category, CharSequence name) |
Variable | declare (CharSequence category, CharSequence name, char delim) |
Variable | declare (CharSequence category, CharSequence name, char delim, CharSequence comments) |
Variable | declare (Variable variable) |
Variable | declare (VariableDecl declaration, Object... replacements) |
boolean | getAttribute (String attrName, Substring result) |
double | getDouble () |
double | getFloat (int idx) |
long | getInteger () |
long | getInteger (int idx) |
AString | getString () |
AString | getString (int idx) |
boolean | isTrue () |
boolean | isTrue (int idx) |
void | ReplaceValue (int idx, Variable replVariable) |
int | size () |
Protected Fields | |
int | qtyValues = 0 |
ArrayList< AString > | values = new ArrayList<AString>() |
Protected Methods | |
void | clear () |
Package Access Methods | |
boolean | getAttribute (String attrName, Substring result, char attrDelim) |
Variable | ( | VariableDecl | declaration, |
Object... | replacements | ||
) |
Constructs a variable from a declaration. Strings named "%1"
, "%2"
... "%N"
found in the fields category, name, comments and defaultValue are replaced with given replacement strings found in array replacements.
declaration | The declaration data of the variable. |
replacements | List of objects that will be converted to strings using AString.__(Object). |
Variable | ( | CharSequence | category, |
CharSequence | name, | ||
char | delim, | ||
CharSequence | comments | ||
) |
Constructs a variable from the given values
category | The category of the variable. |
name | The name of the variable |
comments | Comment lines that might be added in the configuration storage (plug-in implementation dependent). |
delim | A proposal for a delimiter that might be used by some plug-ins to delimit different values from each other (e.g. INI files). |
Variable | ( | CharSequence | category, |
CharSequence | name, | ||
char | delim | ||
) |
Overloaded constructor providing default parameters.
category | The category of the variable. |
name | The name of the variable |
delim | A proposal for a delimiter that might be used by some plug-ins to delimit different values from each other (e.g. INI files). |
Variable | ( | CharSequence | category, |
CharSequence | name | ||
) |
Overloaded constructor providing default parameters.
category | The category of the variable. |
name | The name of the variable |
AString add | ( | ) |
Adds an empty value to the end of the list of values.
AString add | ( | boolean | value | ) |
Adds the given boolean value to the end of the list of values. For true
values string "true" is set, otherwise "false".
value | The value to set. |
AString add | ( | Object | value | ) |
Adds the given string value to the end of the list of values.
value | The value to set. |
|
protected |
Clears all values.
Variable clearValues | ( | ) |
Variable clearValues | ( | int | startIdx | ) |
Clears the value, respectively the list of values set. After invoking this method, size will return startIdx and getString will return null
for any index greater or equal to startIdx.
startIdx | The index of the first value to be cleared. Defaults to 0 . |
this
to allow concatenated operations. Variable declare | ( | CharSequence | category, |
CharSequence | name | ||
) |
Overloaded version providing default parameters.
category | The category of the variable. |
name | The name of the variable |
this
to allow concatenated operations. Variable declare | ( | CharSequence | category, |
CharSequence | name, | ||
char | delim | ||
) |
Overloaded version providing default parameters.
category | The category of the variable. |
name | The name of the variable |
delim | A proposal for a delimiter that might be used by some plug-ins to delimit different values from each other (e.g. INI files). Defaults to '\0' . |
this
to allow concatenated operations. Variable declare | ( | CharSequence | category, |
CharSequence | name, | ||
char | delim, | ||
CharSequence | comments | ||
) |
Clears the variable resets its declaration.
category | The category of the variable. |
name | The name of the variable |
delim | A proposal for a delimiter that might be used by some plug-ins to delimit different values from each other (e.g. INI files). Defaults to '\0' . |
comments | Comment lines that might be added in the configuration storage (plug-in implementation dependent). Defaults to null . |
this
to allow concatenated operations. Variable declare | ( | VariableDecl | declaration, |
Object... | replacements | ||
) |
Clears the variable resets its declaration. Strings named "%1"
, "%2"
... "%N"
found in the fields category, name, comments and defaultValue are replaced with given replacement string arguments in array replacements.
declaration | The declaration data of the variable. |
replacements | List of objects that will be converted to strings using AString.__(Object). |
this
to allow concatenated operations. boolean getAttribute | ( | String | attrName, |
Substring | result | ||
) |
Overloaded version providing default value '='
for parameter attrDelim.
attrName | The name of the attribute searched. | |
[out] | result | A substring with the result. |
true
if the attribute was found, false
otherwise.
|
package |
Searches in the values of this variable for the pattern attrName = result
and sets parameter result to the string following this pattern.
attrName | The name of the attribute searched. | |
[out] | result | A substring with the result. |
attrDelim | The delimiter to search for. Defaults to '='. |
true
if the attribute was found, false
otherwise. double getDouble | ( | ) |
Returns the value at index 0
interpreted as a double value. If no value is defined, 0.0
is returned. Parsing is done using field numberFormat
of field config, respectively, if this is not set, the static singleton NumberFormat.global.
double getFloat | ( | int | idx | ) |
Returns the value at idx interpreted as a double value. If the index is invalid, 0.0
is returned. Parsing is done using field numberFormat
of field config, respectively, if this is not set, the static singleton NumberFormat.global.
idx | The index of the value to be retrieved. Defaults to 0 . |
long getInteger | ( | ) |
Returns the first (in most cases the only) value interpreted as an integer. If no value is set 0
is returned.
long getInteger | ( | int | idx | ) |
Returns the value at idx interpreted as an integer. If the index is invalid, 0
is returned.
idx | The index of the value to be retrieved. Defaults to 0 . |
AString getString | ( | ) |
Returns the first (in most cases the only) value. If no value is set null
is returned.
AString getString | ( | int | idx | ) |
Returns the value with the given index. Valid values for parameter idx are between 0
and size - 1
. If no value is set for the given index, null
is returned.
idx | The index of the value to be retrieved. Defaults to 0 . |
boolean isTrue | ( | ) |
Returns true
if the first value represents a boolean 'true'. Evaluation is done using field config, respectively if this is not set, the static singleton ALIB.config.
If no value is set false
is returned.
boolean isTrue | ( | int | idx | ) |
Returns true
if the value at the given idx represents a boolean 'true'. Evaluation is done using field config, respectively if this is not set, the static singleton ALIB.config.
If the index is invalid, false
is returned.
idx | The index of the value to be retrieved. Defaults to 0 . |
void ReplaceValue | ( | int | idx, |
Variable | replVariable | ||
) |
Replaces the value at idx with the values of the given other variable.
idx | The index of the value to replace. |
replVariable | The variable providing the replacement values. |
int size | ( | ) |
Returns the number of values set in this object.
Configuration config = null |
The Configuration that was recently used to request or store the value.
The default value provided as an externalized string.
The only occasion that this value is used is with method Configuration.load. If no plug-in has this variable defined and this field is not nulled, then the value is written into plug-in of priority Configuration.PRIO_DEFAULT_VALUES, respectively - if this default plug-in was replaced by the user - into a plug-in found at or below this priority.
In this case, the value is parsed using method XTernalizer.loadFromString of field ConfigurationPlugin.stringConverter of the plug-in writing the value.
char delim = '\0' |
The delimiter used for parsing and storing values by simple textual plug-ins which use the default version of XTernalizer for in- and externalizing variables.
|
static |
This and upward bits are reserved for custom plug-ins
|
static |
Write each argument in a new line
|
static |
Suppress spaces around the delimiter (only used in single line mode)
|
static |
No hints
String formatAttrAlignment |
If set, attributes written in multi-lines are vertically aligned by this character or string. Use cases are "=", ":" or "->".
Used by IniFile and potentially by custom plug-ins.
int formatHints |
Hints for formatting textual configuration files. (Used by class IniFile and potentially by custom plug-ins.
The configuration variable category and name concatenated with an underscore character '_'
. This is useful e.g. for naming variables in log messages.
int priority = 0 |
A value related to the priority of a configuration plug-in. The following values apply:
0
after creation or declaration (reuse).0
, if the last load or store operation failed. In addition prior to storing a variable, the value might be manually set. See documentation of Configuration.store) for details.
|
protected |
The number of values currently stored. This may be less than items found in values as those are reused objects.