Package org.evoludo.util
Class Plist
- All Implemented Interfaces:
Serializable,Cloneable,Map<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:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescription(package private) booleanThe flag to indicate if the comparison should fail fast, i.e.(package private) static final intThe number of repeated messages to report before skipping further messages.private intThe number of issues found.private intThe number of numerical issues found.private intThe number of times a particular type of issue is reported before skipping any further ones.private static final intThe number of significant digits.private StringThe previous message.private intThe number of times the previous message was repeated.private static final longRequired for serializable classes.(package private) Collection<String> The list of keys to skip when comparing two plists. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckRounding(Double ref, Double check) Check if the difference betweenrefandcheckis due to rounding errors.private voidcheckRounding(Double ref, Double check, Integer digits) Check if the difference betweenrefandcheckis due to rounding errors.intCompare this plist toplist.intdiff(Plist plist, Collection<String> clo) Compare this plist toplistbut ignore keys inclo.private voidHelper method to compare two plist-arrays.private voidHelper method to compare two plist-dictionaries.private static StringencodeArray(double[] array) Helper method to encodedoublearrayprivate static StringencodeArray(double[][] array) Helper method to encodedoublematrixprivate static StringencodeArray(double[] array, int len) Helper method to encode firstlenelements ofdoublearrayprivate static StringencodeArray(int[] array) Helper method to encodeintarrayprivate static StringencodeArray(int[] array, int len) Helper method to encode firstlenelements ofintarrayprivate static StringencodeArray(String[] array) Helper method to encodeStringarrayprivate static StringencodeArray(String[] array, int len) Helper method to encode firstlenelements ofStringarraystatic StringUtility method to encodebooleanwith tagkey.static StringUtility method to encodedoublewith tagkey.static StringUtility method to encodedoublearray with tagkey.static StringUtility method to encodedoublematrix with tagkey.static StringUtility method to encode firstlenentries ofdoublearray with tagkey.static StringUtility method to encodeintwith tagkey.static StringUtility method to encodeintarray with tagkey.static StringUtility method to encode firstlenentries ofintarray with tagkey.static StringUtility method to encodeStringwith tagkey.static StringUtility method to encodeStringarray with tagkey.static StringUtility method to encode firstlenentries ofStringarray with tagkey.booleanfailfast()Check if in fail-fast mode.voidfailfast(boolean failfast) Set the fail-fast mode to stop comparisons after the first issue encountered.intGet the number of issues found.intGet the number of major issues found.intGet the number of minor issues found (most likely numerical).static double[]list2double(List<Double> list) Utility method to convert a list ofDouble's to an array ofdouble's.static int[]Utility method to convert a list ofInteger's to an array ofint's.private voidprocessDiff(String msg) Process a difference.voidquiet()Set quiet mode to suppress all differences.private voidreportDiff(String msg) Report a difference.voidverbose()Set verbose mode to report all differences.Methods inherited from class HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class AbstractMap
equals, hashCode, toString
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDRequired for serializable classes.- See Also:
-
skip
Collection<String> skipThe list of keys to skip when comparing two plists. -
failFast
boolean failFastThe flag to indicate if the comparison should fail fast, i.e. after first issue encountered. -
N_REPEAT
static final int N_REPEATThe number of repeated messages to report before skipping further messages.- See Also:
-
PRECISION_DIGITS
private static final int PRECISION_DIGITSThe number of significant digits. This is used to distinguish between minor numerical issues and major differences.- See Also:
-
nIssues
private int nIssuesThe number of issues found. -
nNumerical
private int nNumericalThe number of numerical issues found. -
nRepeat
private int nRepeatThe number of times a particular type of issue is reported before skipping any further ones. -
prevmsg
The previous message. -
repeat
private int repeatThe 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:
trueif 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
Compare this plist toplist.- Parameters:
plist- the plist to compare against- Returns:
- the number of differences
-
diff
Compare this plist toplistbut ignore keys inclo.- Parameters:
plist- the referencePlistto compare againstclo- the collection of keys to skip- Returns:
- the number of differences
-
diffDict
Helper method to compare two plist-dictionaries.- Parameters:
reference- the referencePlistplist- thePlistto check
-
diffArray
Helper method to compare two plist-arrays.- Parameters:
reference- the reference arrayarray- the array to check
-
checkRounding
Check if the difference betweenrefandcheckis due to rounding errors.- Parameters:
ref- the reference valuecheck- the value to check- See Also:
-
checkRounding
Check if the difference betweenrefandcheckis due to rounding errors.- Parameters:
ref- the reference valuecheck- the value to checkdigits- the number of significant digits
-
processDiff
Process a difference.- Parameters:
msg- the message to report
-
reportDiff
Report a difference. Nothing is reported if the message is a repetition of the previous message andnRepeathas been reached. If messages have been skipped a summary is reported before continuing with the next issue.- Parameters:
msg- the message to report
-
encodeKey
Utility method to encodebooleanwith tagkey.- Parameters:
key- tag namebool-booleanvalue- Returns:
- encoded String
-
encodeKey
Utility method to encodeintwith tagkey.- Parameters:
key- tag nameinteger-intvalue- Returns:
- encoded String
-
encodeKey
Utility method to encodedoublewith tagkey.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 namereal-doublevalue- Returns:
- encoded String
- floating point values are saved as
-
encodeKey
Utility method to encodeStringwith tagkey.- Parameters:
key- tag namestring-Stringvalue- Returns:
- encoded String
-
encodeKey
Utility method to encodeintarray with tagkey.- Parameters:
key- tag namearray-int[]value- Returns:
- encoded String
-
encodeKey
Utility method to encode firstlenentries ofintarray with tagkey.- Parameters:
key- tag namearray-int[]valuelen- number elements to encode- Returns:
- encoded String
-
encodeKey
Utility method to encodedoublearray with tagkey.Note: floating point values are saved as bit strings to avoid rounding errors when saving/restoring the state of the model.
- Parameters:
key- tag namearray-double[]value- Returns:
- encoded String
-
encodeKey
Utility method to encode firstlenentries ofdoublearray with tagkey.Note: floating point values are saved as bit strings to avoid rounding errors when saving/restoring the state of the model.
- Parameters:
key- tag namearray-double[]valuelen- number elements to encode- Returns:
- encoded String
-
encodeKey
Utility method to encodedoublematrix with tagkey.Note: floating point values are saved as bit strings to avoid rounding errors when saving/restoring the state of the model.
- Parameters:
key- tag namematrix-double[][]value- Returns:
- encoded String
-
encodeKey
Utility method to encodeStringarray with tagkey.- Parameters:
key- tag namearray-String[]value- Returns:
- encoded String
-
encodeKey
Utility method to encode firstlenentries ofStringarray with tagkey.- Parameters:
key- tag namearray-String[]valuelen- number elements to encode- Returns:
- encoded String
-
encodeArray
Helper method to encodeintarray- Parameters:
array-int[]value- Returns:
- encoded String
-
encodeArray
Helper method to encode firstlenelements ofintarray- Parameters:
array-int[]valuelen- number elements to encode- Returns:
- encoded String
-
encodeArray
Helper method to encodedoublearrayNote: 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
Helper method to encode firstlenelements ofdoublearrayNote: floating point values are saved as bit strings to avoid rounding errors when saving/restoring the state of the model.
- Parameters:
array-double[]valuelen- number elements to encode- Returns:
- encoded String
-
encodeArray
Helper method to encodedoublematrix- Parameters:
array-double[][]value- Returns:
- encoded String
-
encodeArray
Helper method to encodeStringarray- Parameters:
array-String[]value- Returns:
- encoded String
-
encodeArray
Helper method to encode firstlenelements ofStringarray- Parameters:
array-String[]valuelen- number elements to encode- Returns:
- encoded String
-
list2int
Utility method to convert a list ofInteger's to an array ofint's.- Parameters:
list-List<Integer>value- Returns:
int[]array
-
list2double
Utility method to convert a list ofDouble's to an array ofdouble's.- Parameters:
list-List<Double>value- Returns:
double[]array
-