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) boolean
The flag to indicate if the comparison should fail fast, i.e.(package private) static final int
The number of repeated messages to report before skipping further messages.private int
The number of issues found.private int
The number of numerical issues found.private int
The number of times a particular type of issue is reported before skipping any further ones.private static final int
The number of significant digits.private String
The previous message.private int
The number of times the previous message was repeated.private static final long
Required 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 void
checkRounding
(Double ref, Double check) Check if the difference betweenref
andcheck
is due to rounding errors.private void
checkRounding
(Double ref, Double check, Integer digits) Check if the difference betweenref
andcheck
is due to rounding errors.int
Compare this plist toplist
.int
diff
(Plist plist, Collection<String> clo) Compare this plist toplist
but ignore keys inclo
.private void
Helper method to compare two plist-arrays.private void
Helper method to compare two plist-dictionaries.private static String
encodeArray
(double[] array) Helper method to encodedouble
arrayprivate static String
encodeArray
(double[][] array) Helper method to encodedouble
matrixprivate static String
encodeArray
(double[] array, int len) Helper method to encode firstlen
elements ofdouble
arrayprivate static String
encodeArray
(int[] array) Helper method to encodeint
arrayprivate static String
encodeArray
(int[] array, int len) Helper method to encode firstlen
elements ofint
arrayprivate static String
encodeArray
(String[] array) Helper method to encodeString
arrayprivate static String
encodeArray
(String[] array, int len) Helper method to encode firstlen
elements ofString
arraystatic String
Utility method to encodeboolean
with tagkey
.static String
Utility method to encodedouble
with tagkey
.static String
Utility method to encodedouble
array with tagkey
.static String
Utility method to encodedouble
matrix with tagkey
.static String
Utility method to encode firstlen
entries ofdouble
array with tagkey
.static String
Utility method to encodeint
with tagkey
.static String
Utility method to encodeint
array with tagkey
.static String
Utility method to encode firstlen
entries ofint
array with tagkey
.static String
Utility method to encodeString
with tagkey
.static String
Utility method to encodeString
array with tagkey
.static String
Utility method to encode firstlen
entries ofString
array with tagkey
.boolean
failfast()
Check if in fail-fast mode.void
failfast
(boolean failfast) Set the fail-fast mode to stop comparisons after the first issue encountered.int
Get the number of issues found.int
Get the number of major issues found.int
Get 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 void
processDiff
(String msg) Process a difference.void
quiet()
Set quiet mode to suppress all differences.private void
reportDiff
(String msg) Report a difference.void
verbose()
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, values
Methods 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:
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
Compare this plist toplist
.- Parameters:
plist
- the plist to compare against- Returns:
- the number of differences
-
diff
Compare this plist toplist
but ignore keys inclo
.- Parameters:
plist
- the dictionary to compare againstclo
- the collection of keys to skip- Returns:
- the number of differences
-
diffDict
Helper method to compare two plist-dictionaries.- Parameters:
reference
- the reference plistplist
- the plist to check
-
diffArray
Helper method to compare two plist-arrays.- Parameters:
reference
- the reference arrayarray
- the array to check
-
checkRounding
Check if the difference betweenref
andcheck
is due to rounding errors.- Parameters:
ref
- the reference valuecheck
- the value to check- See Also:
-
checkRounding
Check if the difference betweenref
andcheck
is 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 andnRepeat
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
Utility method to encodeboolean
with tagkey
.- Parameters:
key
- tag namebool
-boolean
value- Returns:
- encoded String
-
encodeKey
Utility method to encodeint
with tagkey
.- Parameters:
key
- tag nameinteger
-int
value- Returns:
- encoded String
-
encodeKey
Utility method to encodedouble
with 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
-double
value- Returns:
- encoded String
- floating point values are saved as
-
encodeKey
Utility method to encodeString
with tagkey
.- Parameters:
key
- tag namestring
-String
value- Returns:
- encoded String
-
encodeKey
Utility method to encodeint
array with tagkey
.- Parameters:
key
- tag namearray
-int[]
value- Returns:
- encoded String
-
encodeKey
Utility method to encode firstlen
entries ofint
array with tagkey
.- Parameters:
key
- tag namearray
-int[]
valuelen
- number elements to encode- Returns:
- encoded String
-
encodeKey
Utility method to encodedouble
array 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 firstlen
entries ofdouble
array 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 encodedouble
matrix 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 encodeString
array with tagkey
.- Parameters:
key
- tag namearray
-String[]
value- Returns:
- encoded String
-
encodeKey
Utility method to encode firstlen
entries ofString
array with tagkey
.- Parameters:
key
- tag namearray
-String[]
valuelen
- number elements to encode- Returns:
- encoded String
-
encodeArray
Helper method to encodeint
array- Parameters:
array
-int[]
value- Returns:
- encoded String
-
encodeArray
Helper method to encode firstlen
elements ofint
array- Parameters:
array
-int[]
valuelen
- number elements to encode- Returns:
- encoded String
-
encodeArray
Helper method to encodedouble
arrayNote: 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 firstlen
elements ofdouble
arrayNote: 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 encodedouble
matrix- Parameters:
array
-double[][]
value- Returns:
- encoded String
-
encodeArray
Helper method to encodeString
array- Parameters:
array
-String[]
value- Returns:
- encoded String
-
encodeArray
Helper method to encode firstlen
elements ofString
array- 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
-