Class ListQuestion
question to support the construction of an
open-ended set of complex values determined by a specified subinterview.
A "loop" is created by creating an instance of a subtype of ListQuestion. The subtype must implement createBody() to create instances of the subinterview for the body of the loop. getNext() should return the next question after the loop has been completed.
Computationally, this question behaves more like a "fork" than a "loop". Semantically, it is as though all the bodies are evaluated together, in parallel, rather than serially one after the other. In the GUI presentation, it is expected that only one body is displayed at a time, and that the user can choose which body is viewed. This avoids having all the loops unrolled all the time in the display of the current path. Internally, each ListQuestion has a sibling that is created automatically, and together, these two questions bracket the set of loop bodies.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA special subtype of Interview to use for the questions in the body of a loop. -
Field Summary
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedListQuestion(Interview interview, String tag) Create a question with a nominated tag. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Remove all the bodies currently allocated for this question, and set the value of the question to indicate no loop body selected.abstract ListQuestion.BodycreateBody(int index) Create a new instance of a body for this loop question.Get the set of bodies currently allocated within the loop.getBody(int index) Get a specified body from the loop.intGet the number of bodies (iterations) currently allocated within the loop.Get the summary text for the end question.Get the question text for the end question.Object[]Get the formatting arguments for the question text for the end question.intGet the number of bodies for this loop that are currently incomplete, as determined byListQuestion.Body.isBodyFinishable().getOther()Get the sibling question that appears at the other end of the loop.Get the currently selected loop body, or null, as selected by by setValue.Get a string representation of the index of the currently selected loop body, or an out of range value (typically less than zero) if none is selected.intgetValue()Get the index of the currently selected loop body, or an out of range value (typically less than zero) if none is selected.intVerify this question is on the current path, and if it is, return the current value.final booleanisEnd()Check if this is the question that appears at the beginning or at the end of the loop.booleanCheck if the question always has a valid response.booleanCheck if the question currently has a valid response.protected voidLoads any state for this question from the given map, using tag as the key.protected voidSave any state for this question in a dictionary, using the tag as the key.voidsetBodies(ListQuestion.Body[] newBodies, int newValue) Set the set of bodies allocated within the loop, and the index of one which should be selected.voidsetValue(int newValue) Set the index of the loop body to be selected.voidSet the index of the loop body to be selected.Methods inherited from class Question
addMarker, equals, export, getChecklistItems, getHelpID, getImage, getInterview, getKey, getNext, getResourceString, getResourceString, getSummary, getTag, getText, getTextArgs, hashCode, hasMarker, isEnabled, isHidden, reload, removeMarker, setHelpID, setImage, setImage, setSummary, setText
-
Constructor Details
-
ListQuestion
-
-
Method Details
-
createBody
Create a new instance of a body for this loop question. The body is a subinterview that contains the questions for the body of the loop. The body does not become one of the set of bodies for the loop until the set is updated withsetBodies(ListQuestion.Body[], int).- Parameters:
index- the position that this body will have within the set of bodies for the loop. This value should be passed through to the Body constructor.- Returns:
- a new instance of a body for this loop question
-
isEnd
public final boolean isEnd()Check if this is the question that appears at the beginning or at the end of the loop. When a ListQuestion is created, a sibling is automatically created that will appear at the end of the loop.- Returns:
- false if this is the main question, that appears at the head of the loop, or true if this is the question that is automatically created to appear at the end of the lop.
-
getOther
Get the sibling question that appears at the other end of the loop. When a ListQuestion is created, a sibling is automatically created that will appear at the end of the loop. From either of these questions, you can use this method to get at the other one.- Returns:
- the sibling question that appears at the other end of the loop
-
getSelectedBody
Get the currently selected loop body, or null, as selected by by setValue.- Returns:
- the currently selected loop body, or null, if none.
-
getValue
public int getValue()Get the index of the currently selected loop body, or an out of range value (typically less than zero) if none is selected.- Returns:
- the index of the currently selected loop body, or an out of range value (typically less than zero) if none is selected
- See Also:
-
setValue
public void setValue(int newValue) Set the index of the loop body to be selected. If the value is out of range, no loop body will be selected.- Parameters:
newValue- the index of the loop body to be selected- See Also:
-
setValue
Set the index of the loop body to be selected. If the value is out of range, no loop body will be selected. -
getValueOnPath
Verify this question is on the current path, and if it is, return the current value.- Returns:
- the current value of this question
- Throws:
Interview.NotOnPathFault- if this question is not on the current path- See Also:
-
getStringValue
Get a string representation of the index of the currently selected loop body, or an out of range value (typically less than zero) if none is selected.- Specified by:
getStringValuein classQuestion- Returns:
- a string representing the current response to this question, or null.
- See Also:
-
isValueValid
public boolean isValueValid()Check if the question currently has a valid response. For a ListQuestion, this is normally true.- Specified by:
isValueValidin classQuestion- Returns:
- true if the question currently has a valid response, and false otherwise.
-
isValueAlwaysValid
public boolean isValueAlwaysValid()Check if the question always has a valid response. For a ListQuestion, this is normally false.- Specified by:
isValueAlwaysValidin classQuestion- Returns:
- true if the question always has a valid response, and false otherwise.
-
clear
-
getEndSummary
Get the summary text for the end question. When a ListQuestion is created, a sibling is automatically created that will appear at the end of the loop. Override this method to override the default behavior to get the summary text from the standard resource bundle. The tag for the end question is the same as the tag for the main question, with ".end" appended.- Returns:
- the summary text for the end question
- See Also:
-
getEndText
Get the question text for the end question. When a ListQuestion is created, a sibling is automatically created that will appear at the end of the loop. Override this method to override the default behavior to get the question text from the standard resource bundle. The tag for the end question is the same as the tag for the main question, with ".end" appended.- Returns:
- the question text for the end question
- See Also:
-
getEndTextArgs
Get the formatting arguments for the question text for the end question. When a ListQuestion is created, a sibling is automatically created that will appear at the end of the loop. Override this method to override the default behavior to return null.- Returns:
- the formatting arguments for the question text for the end question
- See Also:
-
load
Description copied from class:QuestionLoads any state for this question from the given map, using tag as the key. If the loaded value is not null then calls methodsetValue(String)passing the value. -
save
-
getBodies
Get the set of bodies currently allocated within the loop.- Returns:
- the set of bodies currently allocated within the loop
- See Also:
-
getBodyCount
public int getBodyCount()Get the number of bodies (iterations) currently allocated within the loop.- Returns:
- the number of bodies currently allocated within the loop
-
getBody
Get a specified body from the loop.- Parameters:
index- the position of the desired body within the set of bodies currently allocated within the loop.- Returns:
- the specified body
- Throws:
ArrayIndexOutOfBoundsException- if index does not identify a valid body
-
setBodies
Set the set of bodies allocated within the loop, and the index of one which should be selected. The bodies will normally come from a combination of the bodies returned from getBodies() or new ones created by createBody().- Parameters:
newBodies- the set of bodies to be taken as the new set of loop bodiesnewValue- the index of the body which should be the selected body.- See Also:
-
getIncompleteBodyCount
public int getIncompleteBodyCount()Get the number of bodies for this loop that are currently incomplete, as determined byListQuestion.Body.isBodyFinishable().- Returns:
- the number of bodies for this loop that are currently incomplete.
-