From 1ef1970e88de3947ea4d5e2f7665fc0b55172216 Mon Sep 17 00:00:00 2001 From: grzegorz Date: Mon, 22 Jul 2019 15:15:33 +0200 Subject: [PATCH] Include multiplicities only for repeatable groups in TreeReference.toString() method --- .../java/org/javarosa/core/model/FormDef.java | 1 + .../core/model/instance/TreeReference.java | 10 ++++++-- .../model/instance/TreeReferenceLevel.java | 25 ++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/javarosa/core/model/FormDef.java b/src/main/java/org/javarosa/core/model/FormDef.java index 44afc6a06..e3f0e6460 100644 --- a/src/main/java/org/javarosa/core/model/FormDef.java +++ b/src/main/java/org/javarosa/core/model/FormDef.java @@ -368,6 +368,7 @@ public TreeReference getChildInstanceRef(List elements, List 0 || mult != 0) && mult !=-4) { - sb.append("[").append(mult + (zeroIndexMult ? 0 : 1)).append("]"); + if (data.get(i).isRepeatable()) { + if ((i > 0 || mult != 0) && mult !=-4) { + sb.append("[").append(mult + (zeroIndexMult ? 0 : 1)).append("]"); + } } break; } @@ -672,4 +674,8 @@ public TreeReference removePredicates() { } return predicateless; } + + public void markAsRepeatable(int i) { + data.get(i).markAsRepeatable(); + } } \ No newline at end of file diff --git a/src/main/java/org/javarosa/core/model/instance/TreeReferenceLevel.java b/src/main/java/org/javarosa/core/model/instance/TreeReferenceLevel.java index 99b097743..3860d4b1c 100644 --- a/src/main/java/org/javarosa/core/model/instance/TreeReferenceLevel.java +++ b/src/main/java/org/javarosa/core/model/instance/TreeReferenceLevel.java @@ -24,6 +24,7 @@ public class TreeReferenceLevel implements Externalizable, Serializable { private String name; private int multiplicity = MULT_UNINIT; private List predicates; + private boolean isRepeatable; /** A cache for reference levels, to avoid keeping a bunch of the same levels floating around at run-time. */ private static CacheTable refs; @@ -36,14 +37,15 @@ public TreeReferenceLevel() { // for externalization } - public TreeReferenceLevel(String name, int multiplicity, List predicates) { + public TreeReferenceLevel(String name, int multiplicity, List predicates, boolean isRepeatable) { this.name = name; this.multiplicity = multiplicity; this.predicates = predicates; + this.isRepeatable = isRepeatable; } public TreeReferenceLevel(String name, int multiplicity) { - this(name, multiplicity, null); + this(name, multiplicity, null, false); } @@ -56,11 +58,11 @@ public String getName() { } public TreeReferenceLevel setMultiplicity(int mult) { - return new TreeReferenceLevel(name, mult, predicates).intern(); + return new TreeReferenceLevel(name, mult, predicates, isRepeatable).intern(); } public TreeReferenceLevel setPredicates(List xpe) { - return new TreeReferenceLevel(name, multiplicity, xpe).intern(); + return new TreeReferenceLevel(name, multiplicity, xpe, isRepeatable).intern(); } public List getPredicates() { @@ -68,11 +70,11 @@ public List getPredicates() { } public TreeReferenceLevel shallowCopy() { - return new TreeReferenceLevel(name, multiplicity, ArrayUtilities.listCopy(predicates)).intern(); + return new TreeReferenceLevel(name, multiplicity, ArrayUtilities.listCopy(predicates), isRepeatable).intern(); } public TreeReferenceLevel setName(String name) { - return new TreeReferenceLevel(name, multiplicity, predicates).intern(); + return new TreeReferenceLevel(name, multiplicity, predicates, isRepeatable).intern(); } public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException { @@ -132,4 +134,15 @@ public TreeReferenceLevel intern() { return refs.intern(this); } } + + void markAsRepeatable() { + isRepeatable = true; + } + + /** + * @return true if the current level represents a repeatable group, otherwise false + */ + boolean isRepeatable() { + return isRepeatable; + } }