Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include multiplicities only for repeatable groups in TreeReference.toString() method #469

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/org/javarosa/core/model/FormDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public TreeReference getChildInstanceRef(List<IFormElement> elements, List<Integ
IFormElement temp = elements.get(i);
if (temp instanceof GroupDef && ((GroupDef) temp).getRepeat()) {
TreeReference repRef = FormInstance.unpackReference(temp.getBind());
ref.markAsRepeatable(repRef.size() - 1);
if (repRef.isParentOf(ref, false)) {
int repMult = multiplicities.get(i);
ref.setMultiplicity(repRef.size() - 1, repMult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,10 @@ public String toString (boolean includePredicates, boolean zeroIndexMult) {
case INDEX_TEMPLATE: sb.append("[@template]"); break;
case INDEX_REPEAT_JUNCTURE: sb.append("[@juncture]"); break;
default:
if ((i > 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;
}
Expand Down Expand Up @@ -672,4 +674,8 @@ public TreeReference removePredicates() {
}
return predicateless;
}

public void markAsRepeatable(int i) {
data.get(i).markAsRepeatable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class TreeReferenceLevel implements Externalizable, Serializable {
private String name;
private int multiplicity = MULT_UNINIT;
private List<XPathExpression> 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<TreeReferenceLevel> refs;
Expand All @@ -36,14 +37,15 @@ public TreeReferenceLevel() {
// for externalization
}

public TreeReferenceLevel(String name, int multiplicity, List<XPathExpression> predicates) {
public TreeReferenceLevel(String name, int multiplicity, List<XPathExpression> 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);
}


Expand All @@ -56,23 +58,23 @@ 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<XPathExpression> xpe) {
return new TreeReferenceLevel(name, multiplicity, xpe).intern();
return new TreeReferenceLevel(name, multiplicity, xpe, isRepeatable).intern();
}

public List<XPathExpression> getPredicates() {
return this.predicates;
}

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 {
Expand Down Expand Up @@ -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;
}
}