Class PlistParser
plist-files.
The primary purpose and motivation for PlistParser is to allow
EvoLudo to save and restore the exact states of numerical or
individual based models. The faithful storage of all information (including
the state of the random number generator) allows to resume calculations
without any information loss. For example, the state of some calculations is
saved after some time. Then the restored calculations produce time series
that are identical to the ones produced when continuing the original
calculation. Naturally, this strong criterion no longer holds after any
modifications of numerical schemes or the use of random numbers.
- Author:
- Christoph Hauert
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final LoggerThe logger for logging warnings and errors.private static final StringHelper string for formatting log messages that invalid or missing closing tags are ignored.private static final StringHelper string for formatting log messages a particular line of the plist file.private static final StringTag for parsing aarrayentry in a string representing a plist file.private static final StringTag for parsing adictentry in a string representing a plist file.private static final StringTag for parsing afalseentry in a string representing a plist file.private static final StringTag for parsing aintegerentry in a string representing a plist file.private static final StringTag for parsing akeyentry in a string representing a plist file.private static final StringTag for parsing a string representing a plist file.private static final StringTag for parsing arealentry in a string representing a plist file.private static final StringTag for parsing astringentry in a string representing a plist file.private static final StringTag for parsing atrueentry in a string representing a plist file. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSuppresses default constructor, ensuring non-instantiability. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidlogClosingTagWarning(int line, String tag) Logs a warning that the closing tag is missing.private static voidlogInvalidTagWarning(int line, String tag, String context) Logs a warning that the tag is invalid in the given context.static PlistParses the contents of aplistfile supplied as a String and returns aPlistwith key and object associations.parseArray(PlistReader reader, List<Object> array) Parses an array entry,<array>, in theplist-string provided byreaderand writes all elements to the listarray.protected static PlistparseDict(PlistReader reader, Plist dict) Parses a dictionary entry,<dict>, in theplist-string provided byreaderand writes<key>andplistelement pairs to the lookup tabledict.private static doubleParses a real number from a string.private static voidstore(PlistReader reader, Plist dict, String key, Object value) Stores the key-value pair in the dictionary.
-
Field Details
-
TAG_PLIST
-
TAG_DICT
Tag for parsing adictentry in a string representing a plist file.- See Also:
-
TAG_ARRAY
Tag for parsing aarrayentry in a string representing a plist file.- See Also:
-
TAG_STRING
Tag for parsing astringentry in a string representing a plist file.- See Also:
-
TAG_INTEGER
Tag for parsing aintegerentry in a string representing a plist file.- See Also:
-
TAG_REAL
Tag for parsing arealentry in a string representing a plist file.- See Also:
-
TAG_TRUE
Tag for parsing atrueentry in a string representing a plist file.- See Also:
-
TAG_FALSE
Tag for parsing afalseentry in a string representing a plist file.- See Also:
-
TAG_KEY
Tag for parsing akeyentry in a string representing a plist file.- See Also:
-
MSG_LINE
Helper string for formatting log messages a particular line of the plist file.- See Also:
-
MSG_IGNORE
Helper string for formatting log messages that invalid or missing closing tags are ignored.- See Also:
-
LOGGER
The logger for logging warnings and errors.
-
-
Constructor Details
-
PlistParser
private PlistParser()Suppresses default constructor, ensuring non-instantiability.
-
-
Method Details
-
parse
Parses the contents of aplistfile supplied as a String and returns aPlistwith key and object associations. The parser processes the followingplistelements:<key>- Name of tag: any valid String.
<dict>- Dictionary: Alternating
<key>tags andplistelements (excluding<key>). Can be empty. <array>- Array: Can contain any number of identical child
plistelements (excluding<key>). Can be empty. <string>- UTF-8 encoded string.
<real>- Floating point number: if the string ends with '
L' it is assumed to be a double encoded as a long.Important:
- Using long to encode floating point numbers is not part of the
plistspecification. However, only bitwise encoding can guarantee faithful writing and restoring of floating point numbers. - Cannot use
Double.valueOf(String)because it is not implemented by GWT.
- Using long to encode floating point numbers is not part of the
<integer>- Integer number: any string that
Integer.parseInt(String)can process, i.e., limited to 32 bits. <true/>,<false/>- Boolean values: tag represents the boolean values
trueandfalse.
Not currently implemented:
<data>- Base64 encoded data.
<date>- ISO 8601 formatted string.
Note: Invalid or unknown tags trigger an error message on standard error.
- Parameters:
string- contents of theplistfile- Returns:
- a
Plistwith key and element associations
-
parseDict
Parses a dictionary entry,<dict>, in theplist-string provided byreaderand writes<key>andplistelement pairs to the lookup tabledict. Note, dictionaries may contain<dict>elements, which results in recursive calls to this method.Note: Invalid or unknown tags trigger error message on standard out.
- Parameters:
reader- iterator overplisttagsdict- map for storing all pairs of<key>andplistelement pairs.- Returns:
- the filled dictionary
dict
-
parseArray
Parses an array entry,<array>, in theplist-string provided byreaderand writes all elements to the listarray.Note: Invalid or unknown tags trigger log warnings and errors.
- Parameters:
reader- iterator overplisttagsarray- list for storing the array ofplistelements.- Returns:
- the filled array
array
-
parseReal
Parses a real number from a string. If the string ends with 'L' it is assumed to be bitstring of a double encoded as a long.- Parameters:
real- the string representation of the real number- Returns:
- the parsed double value
-
store
Stores the key-value pair in the dictionary. If the key is null, a warning is logged and the value is ignored.- Parameters:
reader- the plist readerdict- the dictionary to store the value inkey- the key for the valuevalue- the value to store
-
logClosingTagWarning
Logs a warning that the closing tag is missing.- Parameters:
line- the line numbertag- the tag name
-
logInvalidTagWarning
-