public class FormIndex extends Object implements Serializable
FormIndex is an immutable index which is structured to provide quick access to a specific node in a
FormDef (tree of IFormElement representing a blank form) or a
FormInstance (tree of
TreeElement representing a form instance that can be filled).
It also includes a TreeReference representing the XPath path of that node.
The XML node referred to by a FormIndex can correspond to either a question or a group. The index is constructed as a
linked list of levels.
A FormIndex can refer to:
- a node at the top level of the form (only localIndex is used)
- a node nested in a group hierarchy (localIndex and nextLevel are used)
- a node nested in a repeat (localIndex, nextLevel and instanceIndex are all used)
When a FormIndex list refers to a nested node, that root FormIndex represents the path root and links to subsequent
levels using the nextLevel field. The @{link #getReference} method returns the reference of the FormIndex at
the end of the list.
Consider the following instance from a blank form with friends as a repeat group and school_info as a
non-repeat group:
<instance> <data id="my_form"> <address/> <dob/> <school_info> <favorite_class/> <favorite_teacher/> </school_info> <friends> <firstname/> </friends> </data> </instance> </pre>Thedobquestion's path is/data/dob. The index that refers to it has alocalIndexof 1. Thefriendsgroup's path is/data/friends. The index that refers to it has alocalIndexof 3. Thefavorite_teacherquestion's path is/data/school_info/favorite_teacher. The index that refers to it has alocalIndexof 2 which isschool_info's index at the form root. It also has anextLevelset which itself has alocalIndexof 1 because it is the second node in the school_info group. Thefirstnamequestion's path is/data/friends[N]/firstnamewhere @{N} is a 0-based index representing which of potentially severalfriendsrepeat group instances'firstnameis desired (also referred to as multiplicity). Sincefriendsis a repeat group, the filled instance can contain several instances of thefriendsnode. The index that refers to it always starts with alocalIndexof 3 which isfriends's index at the form root. It also has aninstanceIndexwhich represents which of the potentially severalfriendsto use. To index afirstnamenode, anextLevelis added which always has a @{code localIndex} of 0. To go from aFormIndexto a form element in a blank form,FormDef.getChild(FormIndex)can be used. To go from aFormIndexto a node in a filled form,DataInstance.resolveReference(TreeReference)can be used along withgetReference(). No circularity is allowed. That is, noFormIndex's ancestor can be itself. Datatype Productions: FormIndex = BOF | EOF | CompoundIndex(nextIndex:FormIndex,Location) Location = Empty | Simple(localLevel:int) | WithMult(localLevel:int, multiplicity:int)
| Constructor and Description |
|---|
FormIndex(FormIndex nextLevel,
FormIndex currentLevel)
Constructs an index which references an element past the level of
specificity of the current context, founded by the currentLevel
index.
|
FormIndex(FormIndex nextLevel,
int localIndex,
int instanceIndex,
TreeReference reference)
Constructs a @{code FormIndex} for a node that has children and that may have repeat instances in a filled form.
|
FormIndex(FormIndex nextLevel,
int localIndex,
TreeReference reference)
Constructs a @{code FormIndex} for a node that has children.
|
FormIndex(int localIndex,
int instanceIndex,
TreeReference reference)
Constructs a @{code FormIndex} for a node that does not have any children but that may have repeat instances in a
filled form.
|
FormIndex(int localIndex,
TreeReference reference)
Constructs a @{code FormIndex} for a node that does not have any children.
|
| Modifier and Type | Method and Description |
|---|---|
void |
assignRefs(FormDef f) |
int |
compareTo(Object o) |
static FormIndex |
createBeginningOfFormIndex()
Returns an index before the start of the form
|
static FormIndex |
createEndOfFormIndex()
Returns an index after the end of the form
|
FormIndex |
diff(FormIndex subIndex)
Takes in a form index which is a subset of this index, and returns the
total difference between them.
|
boolean |
equals(Object o) |
int |
getDepth() |
int |
getElementMultiplicity()
For the fully qualified element, get the multiplicity of the element's reference
|
int |
getInstanceIndex() |
int |
getLocalIndex() |
TreeReference |
getLocalReference() |
FormIndex |
getNextLevel() |
FormIndex |
getPreviousLevel() |
TreeReference |
getReference() |
FormIndex |
getTerminal() |
int |
hashCode() |
boolean |
isBeginningOfFormIndex() |
boolean |
isEndOfFormIndex() |
boolean |
isInForm() |
static boolean |
isSubElement(FormIndex parent,
FormIndex child) |
static boolean |
isSubIndex(FormIndex parent,
FormIndex child) |
boolean |
isTerminal()
Identifies whether this is a terminal index, in other words whether this
index references with more specificity than the current context
|
FormIndex |
snip() |
String |
toString() |
static FormIndex |
trimNegativeIndices(FormIndex index)
Trims any negative indices from the end of the passed in index.
|
public FormIndex(int localIndex,
TreeReference reference)
localIndex - An integer index into a flat list of elementsreference - A reference to the instance element identified by this indexpublic FormIndex(int localIndex,
int instanceIndex,
TreeReference reference)
instanceIndex identifies which of these instances should be referred to.localIndex - An integer index into a flat list of elementsinstanceIndex - An integer index expressing the multiplicity of the current levelreference - A reference to the instance element identified by this indexpublic FormIndex(FormIndex nextLevel, int localIndex, TreeReference reference)
nextLevel - An index into the referenced element's indexlocalIndex - An index to an element at the current level, a child
element of which will be referenced by the nextLevel index.reference - A reference to the instance element identified by this index;public FormIndex(FormIndex nextLevel, int localIndex, int instanceIndex, TreeReference reference)
nextLevel - An index into the referenced element's indexlocalIndex - An index to an element at the current level, a child
element of which will be referenced by the nextLevel index.instanceIndex - How many times the element referenced has been
repeated.reference - A reference to the instance element identified by this index;public static FormIndex createBeginningOfFormIndex()
public static FormIndex createEndOfFormIndex()
public boolean isInForm()
public int getLocalIndex()
public int getInstanceIndex()
public int getElementMultiplicity()
public FormIndex getNextLevel()
public TreeReference getLocalReference()
public TreeReference getReference()
public FormIndex getTerminal()
public boolean isTerminal()
public boolean isEndOfFormIndex()
public boolean isBeginningOfFormIndex()
public int compareTo(Object o)
public FormIndex snip()
public FormIndex diff(FormIndex subIndex)
subIndex - public int getDepth()
public static FormIndex trimNegativeIndices(FormIndex index)
index - public void assignRefs(FormDef f)
public FormIndex getPreviousLevel()
Copyright © 2024. All rights reserved.