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

    • 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:
    • ARRAY_OPEN

      static final String ARRAY_OPEN
      String constant for opening an array during plist generation.
      See Also:
    • ARRAY_CLOSE

      static final String ARRAY_CLOSE
      String constant for closing an array during plist generation.
      See Also:
    • INTEGER_OPEN

      static final String INTEGER_OPEN
      String constant for opening an integer entry during plist generation.
      See Also:
    • INTEGER_CLOSE

      static final String INTEGER_CLOSE
      String constant for closing an integer entry during plist generation.
      See Also:
    • KEY_OPEN

      static final String KEY_OPEN
      String constant for opening an integer entry during plist generation.
      See Also:
    • KEY_CLOSE

      static final String KEY_CLOSE
      String constant for closing an key entry during plist generation.
      See Also:
    • REAL_OPEN

      static final String REAL_OPEN
      String constant for opening an real entry during plist generation.
      See Also:
    • REAL_CLOSE

      static final String REAL_CLOSE
      String constant for closing an real entry during plist generation.
      See Also:
    • STRING_OPEN

      static final String STRING_OPEN
      String constant for opening an string entry during plist generation.
      See Also:
    • STRING_CLOSE

      static final String STRING_CLOSE
      String constant for closing an string entry during plist generation.
      See Also:
    • DIFF_KEY

      static final String DIFF_KEY
      String constant for reporting differences in keys.
      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> skip)
      Compare this plist to plist but ignore keys in clo.
      Parameters:
      plist - the reference Plist to compare against
      skip - the collection of keys to skip
      Returns:
      the number of differences
    • hashCode

      public int hashCode()
      Override hashCode to only use the actual plist content (HashMap entries). This ensures hash stability regardless of internal state fields.
      Specified by:
      hashCode in interface Map<String,Object>
      Overrides:
      hashCode in class AbstractMap<String,Object>
    • equals

      public boolean equals(Object obj)
      Override equals for consistency with hashCode.
      Specified by:
      equals in interface Map<String,Object>
      Overrides:
      equals in class AbstractMap<String,Object>
    • diffDict

      private void diffDict(Plist reference, Plist plist, Collection<String> skip)
      Helper method to compare two plist-dictionaries.
      Parameters:
      reference - the reference Plist
      plist - the Plist to check
      skip - the collection of keys to skip
    • diffArray

      private void diffArray(List<Object> reference, List<Object> array, Collection<String> skip)
      Helper method to compare two plist-arrays.
      Parameters:
      reference - the reference array
      array - the array to check
      skip - the collection of keys to skip
    • 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
    • diffMeRef

      private String diffMeRef(Object me, Object ref)
      Helper method for formatting output of differences in plists.
      Parameters:
      me - the object that failed comparison
      ref - the reference object
      Returns:
      formatted string with the difference
    • diffMeRefDelta

      private String diffMeRefDelta(Double me, Double ref)
      Helper method for formatting output of differences in plists optimized for Double to also show the numerical difference.
      Parameters:
      me - the object that failed comparison
      ref - the reference object
      Returns:
      formatted string
    • diffArray

      private String diffArray(String type, int idx)
      Helper method for formatting output of differences in arrays.
      Parameters:
      type - the type of the array
      idx - the index of the entry
      Returns:
      formatted 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