From 9ec521f64fa64ee3c8ff3d876d269e10ff1fd8fc Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Mon, 27 May 2019 15:28:44 +0100 Subject: [PATCH] Values constructors treat null as empty. --- prism/src/parser/Values.java | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/prism/src/parser/Values.java b/prism/src/parser/Values.java index eb18807b..eda0e9cd 100644 --- a/prism/src/parser/Values.java +++ b/prism/src/parser/Values.java @@ -58,18 +58,25 @@ public class Values implements Cloneable //implements Comparable } /** - * Construct a new Values object by copying an existing one + * Construct a new Values object by copying an existing one. + * If the existing one is null, it is treated as empty. */ @SuppressWarnings("unchecked") public Values(Values v) { - names = (ArrayList)v.names.clone(); - values = (ArrayList)v.values.clone(); + if (v == null) { + names = new ArrayList(); + values = new ArrayList(); + } else { + names = (ArrayList) v.names.clone(); + values = (ArrayList) v.values.clone(); + } } /** * Construct a new Values object by merging two existing ones. * There is no checking for duplicates. + * Either can be null and, if so, is treated as empty. */ public Values(Values v1, Values v2) { @@ -79,6 +86,7 @@ public class Values implements Cloneable //implements Comparable /** * Construct a new Values object by copying existing State object. + * If it is null, it is treated as empty. * Need access to model info for variable names. * @param s State object to copy. * @param modelInfo Corresponding modelInfo (for variable info/ordering) @@ -86,9 +94,9 @@ public class Values implements Cloneable //implements Comparable public Values(State s, ModelInfo modelInfo) { this(); - int i, n; - n = s.varValues.length; - for (i = 0; i < n; i++) { + if (s == null) return; + int n = s.varValues.length; + for (int i = 0; i < n; i++) { addValue(modelInfo.getVarName(i), s.varValues[i]); } } @@ -106,7 +114,8 @@ public class Values implements Cloneable //implements Comparable } /** - * Add multiple values. + * Add multiple values, specified as a {@link Values} object {@code v}. + * If {@code v} is null, it is treated as empty. * (Note: there is no checking for duplication/inconsistencies/etc.) */ public void addValues(Values v)