Class PlistParser

Object
PlistParser

public class PlistParser extends Object
Basic parser for 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

    Fields
    Modifier and Type
    Field
    Description
    private static final Logger
    The logger for logging warnings and errors.
    private static final String
    Helper string for formatting log messages that invalid or missing closing tags are ignored.
    private static final String
    Helper string for formatting log messages a particular line of the plist file.
    private static final String
    Tag for parsing a array entry in a string representing a plist file.
    private static final String
    Tag for parsing a dict entry in a string representing a plist file.
    private static final String
    Tag for parsing a false entry in a string representing a plist file.
    private static final String
    Tag for parsing a integer entry in a string representing a plist file.
    private static final String
    Tag for parsing a key entry in a string representing a plist file.
    private static final String
    Tag for parsing a string representing a plist file.
    private static final String
    Tag for parsing a real entry in a string representing a plist file.
    private static final String
    Tag for parsing a string entry in a string representing a plist file.
    private static final String
    Tag for parsing a true entry in a string representing a plist file.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Suppresses default constructor, ensuring non-instantiability.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    logClosingTagWarning(int line, String tag)
    Logs a warning that the closing tag is missing.
    private static void
    logInvalidTagWarning(int line, String tag, String context)
    Logs a warning that the tag is invalid in the given context.
    static Plist
    parse(String string)
    Parses the contents of a plist file supplied as a String and returns a Plist with key and object associations.
    protected static List<Object>
    parseArray(PlistReader reader, List<Object> array)
    Parses an array entry, <array>, in the plist-string provided by reader and writes all elements to the list array.
    protected static Plist
    parseDict(PlistReader reader, Plist dict)
    Parses a dictionary entry, <dict>, in the plist-string provided by reader and writes <key> and plist element pairs to the lookup table dict.
    private static double
    Parses a real number from a string.
    private static void
    store(PlistReader reader, Plist dict, String key, Object value)
    Stores the key-value pair in the dictionary.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TAG_PLIST

      private static final String TAG_PLIST
      Tag for parsing a string representing a plist file.
      See Also:
    • TAG_DICT

      private static final String TAG_DICT
      Tag for parsing a dict entry in a string representing a plist file.
      See Also:
    • TAG_ARRAY

      private static final String TAG_ARRAY
      Tag for parsing a array entry in a string representing a plist file.
      See Also:
    • TAG_STRING

      private static final String TAG_STRING
      Tag for parsing a string entry in a string representing a plist file.
      See Also:
    • TAG_INTEGER

      private static final String TAG_INTEGER
      Tag for parsing a integer entry in a string representing a plist file.
      See Also:
    • TAG_REAL

      private static final String TAG_REAL
      Tag for parsing a real entry in a string representing a plist file.
      See Also:
    • TAG_TRUE

      private static final String TAG_TRUE
      Tag for parsing a true entry in a string representing a plist file.
      See Also:
    • TAG_FALSE

      private static final String TAG_FALSE
      Tag for parsing a false entry in a string representing a plist file.
      See Also:
    • TAG_KEY

      private static final String TAG_KEY
      Tag for parsing a key entry in a string representing a plist file.
      See Also:
    • MSG_LINE

      private static final String MSG_LINE
      Helper string for formatting log messages a particular line of the plist file.
      See Also:
    • MSG_IGNORE

      private static final String MSG_IGNORE
      Helper string for formatting log messages that invalid or missing closing tags are ignored.
      See Also:
    • LOGGER

      private static final Logger LOGGER
      The logger for logging warnings and errors.
  • Constructor Details

    • PlistParser

      private PlistParser()
      Suppresses default constructor, ensuring non-instantiability.
  • Method Details

    • parse

      public static Plist parse(String string)
      Parses the contents of a plist file supplied as a String and returns a Plist with key and object associations. The parser processes the following plist elements:
      <key>
      Name of tag: any valid String.
      <dict>
      Dictionary: Alternating <key> tags and plist elements (excluding <key>). Can be empty.
      <array>
      Array: Can contain any number of identical child plist elements (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 plist specification. 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.
      <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 true and false.

      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 the plist file
      Returns:
      a Plist with key and element associations
    • parseDict

      protected static Plist parseDict(PlistReader reader, Plist dict)
      Parses a dictionary entry, <dict>, in the plist-string provided by reader and writes <key> and plist element pairs to the lookup table dict. 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 over plist tags
      dict - map for storing all pairs of <key> and plist element pairs.
      Returns:
      the filled dictionary dict
    • parseArray

      protected static List<Object> parseArray(PlistReader reader, List<Object> array)
      Parses an array entry, <array>, in the plist-string provided by reader and writes all elements to the list array.

      Note: Invalid or unknown tags trigger log warnings and errors.

      Parameters:
      reader - iterator over plist tags
      array - list for storing the array of plist elements.
      Returns:
      the filled array array
    • parseReal

      private static double parseReal(String real)
      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

      private static void store(PlistReader reader, Plist dict, String key, Object value)
      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 reader
      dict - the dictionary to store the value in
      key - the key for the value
      value - the value to store
    • logClosingTagWarning

      private static void logClosingTagWarning(int line, String tag)
      Logs a warning that the closing tag is missing.
      Parameters:
      line - the line number
      tag - the tag name
    • logInvalidTagWarning

      private static void logInvalidTagWarning(int line, String tag, String context)
      Logs a warning that the tag is invalid in the given context.
      Parameters:
      line - the line number
      tag - the tag name
      context - the context in which the tag is invalid