Class Plist

All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>

public class Plist extends HashMap<String,Object>
Utility class to read and write plist-files with some customizations to store the bit-patterns for doubles to allow for perfect reproducibility.
Author:
Christoph Hauert
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Required for serializable classes.
      See Also:
    • skip

      The list of keys to skip when comparing two plists.
    • failFast

      boolean failFast
      The flag to indicate if the comparison should fail fast, i.e. after first issue encountered.
    • N_REPEAT

      static final int N_REPEAT
      The number of repeated messages to report before skipping further messages.
      See Also:
    • PRECISION_DIGITS

      private static final int PRECISION_DIGITS
      The number of significant digits. This is used to distinguish between minor numerical issues and major differences.
      See Also:
    • nIssues

      private int nIssues
      The number of issues found.
    • nNumerical

      private int nNumerical
      The number of numerical issues found.
    • nRepeat

      private int nRepeat
      The number of times a particular type of issue is reported before skipping any further ones.
    • prevmsg

      private String prevmsg
      The previous message.
    • repeat

      private int repeat
      The number of times the previous message was repeated.
  • Constructor Details

    • Plist

      public Plist()
      Construct a new plist.
  • Method Details

    • verbose

      public void verbose()
      Set verbose mode to report all differences.
    • quiet

      public void quiet()
      Set quiet mode to suppress all differences.
    • failfast

      public boolean failfast()
      Check if in fail-fast mode.
      Returns:
      true if fail-fast mode is set
    • failfast

      public void failfast(boolean failfast)
      Set the fail-fast mode to stop comparisons after the first issue encountered.
      Parameters:
      failfast - the fail-fast-flag
    • getNIssues

      public int getNIssues()
      Get the number of issues found.
      Returns:
      the number of issues
    • getNMajor

      public int getNMajor()
      Get the number of major issues found.
      Returns:
      the number of issues
    • getNMinor

      public int getNMinor()
      Get the number of minor issues found (most likely numerical).
      Returns:
      the number of issues
    • diff

      public int diff(Plist plist)
      Compare this plist to plist.
      Parameters:
      plist - the plist to compare against
      Returns:
      the number of differences
    • diff

      public int diff(Plist plist, Collection<String> clo)
      Compare this plist to plist but ignore keys in clo.
      Parameters:
      plist - the dictionary to compare against
      clo - the collection of keys to skip
      Returns:
      the number of differences
    • diffDict

      private void diffDict(Plist reference, Plist plist)
      Helper method to compare two plist-dictionaries.
      Parameters:
      reference - the reference plist
      plist - the plist to check
    • diffArray

      private void diffArray(List<Object> reference, List<Object> array)
      Helper method to compare two plist-arrays.
      Parameters:
      reference - the reference array
      array - the array to check
    • checkRounding

      private void checkRounding(Double ref, Double check)
      Check if the difference between ref and check is due to rounding errors.
      Parameters:
      ref - the reference value
      check - the value to check
      See Also:
    • checkRounding

      private void checkRounding(Double ref, Double check, Integer digits)
      Check if the difference between ref and check is due to rounding errors.
      Parameters:
      ref - the reference value
      check - the value to check
      digits - the number of significant digits
    • processDiff

      private void processDiff(String msg)
      Process a difference.
      Parameters:
      msg - the message to report
    • reportDiff

      private void reportDiff(String msg)
      Report a difference. Nothing is reported if the message is a repetition of the previous message and nRepeat has been reached. If messages have been skipped a summary is reported before continuing with the next issue.
      Parameters:
      msg - the message to report
    • encodeKey

      public static String encodeKey(String key, boolean bool)
      Utility method to encode boolean with tag key.
      Parameters:
      key - tag name
      bool - boolean value
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, int integer)
      Utility method to encode int with tag key.
      Parameters:
      key - tag name
      integer - int value
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, double real)
      Utility method to encode double with tag key.

      Notes:

      • floating point values are saved as long's (bit strings) to avoid rounding errors when saving/restoring the state of the model.
      • cannot use Double.toHexString(real) because GWT does not implement it.
      Parameters:
      key - tag name
      real - double value
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, String string)
      Utility method to encode String with tag key.
      Parameters:
      key - tag name
      string - String value
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, int[] array)
      Utility method to encode int array with tag key.
      Parameters:
      key - tag name
      array - int[] value
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, int[] array, int len)
      Utility method to encode first len entries of int array with tag key.
      Parameters:
      key - tag name
      array - int[] value
      len - number elements to encode
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, double[] array)
      Utility method to encode double array with tag key.

      Note: floating point values are saved as bit strings to avoid rounding errors when saving/restoring the state of the model.

      Parameters:
      key - tag name
      array - double[] value
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, double[] array, int len)
      Utility method to encode first len entries of double array with tag key.

      Note: floating point values are saved as bit strings to avoid rounding errors when saving/restoring the state of the model.

      Parameters:
      key - tag name
      array - double[] value
      len - number elements to encode
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, double[][] matrix)
      Utility method to encode double matrix with tag key.

      Note: floating point values are saved as bit strings to avoid rounding errors when saving/restoring the state of the model.

      Parameters:
      key - tag name
      matrix - double[][] value
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, String[] array)
      Utility method to encode String array with tag key.
      Parameters:
      key - tag name
      array - String[] value
      Returns:
      encoded String
    • encodeKey

      public static String encodeKey(String key, String[] array, int len)
      Utility method to encode first len entries of String array with tag key.
      Parameters:
      key - tag name
      array - String[] value
      len - number elements to encode
      Returns:
      encoded String
    • encodeArray

      private static String encodeArray(int[] array)
      Helper method to encode int array
      Parameters:
      array - int[] value
      Returns:
      encoded String
    • encodeArray

      private static String encodeArray(int[] array, int len)
      Helper method to encode first len elements of int array
      Parameters:
      array - int[] value
      len - number elements to encode
      Returns:
      encoded String
    • encodeArray

      private static String encodeArray(double[] array)
      Helper method to encode double array

      Note: floating point values are saved as bit strings to avoid rounding errors when saving/restoring the state of the model.

      Parameters:
      array - double[] value
      Returns:
      encoded String
    • encodeArray

      private static String encodeArray(double[] array, int len)
      Helper method to encode first len elements of double array

      Note: floating point values are saved as bit strings to avoid rounding errors when saving/restoring the state of the model.

      Parameters:
      array - double[] value
      len - number elements to encode
      Returns:
      encoded String
    • encodeArray

      private static String encodeArray(double[][] array)
      Helper method to encode double matrix
      Parameters:
      array - double[][] value
      Returns:
      encoded String
    • encodeArray

      private static String encodeArray(String[] array)
      Helper method to encode String array
      Parameters:
      array - String[] value
      Returns:
      encoded String
    • encodeArray

      private static String encodeArray(String[] array, int len)
      Helper method to encode first len elements of String array
      Parameters:
      array - String[] value
      len - number elements to encode
      Returns:
      encoded String
    • list2int

      public static int[] list2int(List<Integer> list)
      Utility method to convert a list of Integer's to an array of int's.
      Parameters:
      list - List<Integer> value
      Returns:
      int[] array
    • list2double

      public static double[] list2double(List<Double> list)
      Utility method to convert a list of Double's to an array of double's.
      Parameters:
      list - List<Double> value
      Returns:
      double[] array