Package com.sun.interview
Class ChoiceQuestion
- java.lang.Object
-
- com.sun.interview.Question
-
- com.sun.interview.ChoiceQuestion
-
- Direct Known Subclasses:
TestsInterview.TreeOrFileChoiceQuestion,YesNoQuestion
public abstract class ChoiceQuestion extends Question
Aquestionto which the response is one of a number of choices.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedChoiceQuestion(Interview interview, java.lang.String tag)Create a question with a nominated tag.protectedChoiceQuestion(Interview interview, java.lang.String tag, java.lang.String... choices)Create a question with a nominated tag.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Clear any response to this question, resetting the value back to its initial state.java.lang.String[]getChoices()Get the set of legal responses for this question.java.lang.StringgetDefaultValue()Get the default response for this question.java.lang.String[]getDisplayChoices()Get the display values for the set of legal responses for this question.java.lang.StringgetDisplayValue()Get the display string for the current (default or latest) response to this question.java.lang.StringgetStringValue()Get the response to this question as a string.java.lang.StringgetValue()Get the internal value for the current (default or latest) response to this question.java.lang.StringgetValueOnPath()Verify this question is on the current path, and if it is, return the current value.booleanisValueAlwaysValid()Check if the question always has a valid response.booleanisValueValid()Check if the question currently has a valid response.protected voidsave(java.util.Map<java.lang.String,java.lang.String> data)Save the value for this question in a dictionary, using the tag as the key.protected voidsetChoices(java.lang.String... choices)Set the set of legal responses for this question.protected voidsetChoices(java.lang.String[] choices, boolean localize)Set the set of legal responses for this question.protected voidsetChoices(java.lang.String[] choices, java.lang.String... displayChoices)Set the set of legal responses for this question.voidsetDefaultValue(java.lang.String v)Set the default response for this question, used by the clear method.protected voidsetI18NChoices(java.lang.String... choices)Deprecated.Use the other setChoices() methods, which support i18n as an option.voidsetValue(java.lang.String newValue)Set the current value.-
Methods inherited from class com.sun.interview.Question
addMarker, equals, export, getChecklistItems, getHelpID, getImage, getInterview, getKey, getNext, getResourceString, getResourceString, getSummary, getTag, getText, getTextArgs, hashCode, hasMarker, isEnabled, isHidden, load, reload, removeMarker, setHelpID, setImage, setImage, setSummary, setText
-
-
-
-
Constructor Detail
-
ChoiceQuestion
protected ChoiceQuestion(Interview interview, java.lang.String tag)
Create a question with a nominated tag. If this constructor is used, the choices must be supplied separately.- Parameters:
interview- The interview containing this question.tag- A unique tag to identify this specific question.
-
ChoiceQuestion
protected ChoiceQuestion(Interview interview, java.lang.String tag, java.lang.String... choices)
Create a question with a nominated tag.- Parameters:
interview- The interview containing this question.tag- A unique tag to identify this specific question.choices- The set of legal values for responses to this question.
-
-
Method Detail
-
setChoices
protected void setChoices(java.lang.String[] choices, boolean localize)Set the set of legal responses for this question. If the current value is one of the choices (string equality), it will be set identically equal to that choice; otherwise, the current value will be set to the first choice.- Parameters:
choices- An array of strings identifying the set of legal responses for this question. Depending on the value of the 'localize' argument, the strings will be used literally, or will be used to construct keys to look up resources in the containing interview's resource bundle, in order to get the display strings. In both cases, the current value will always be one of the values in the choices array.localize- if false, the choices will be used directly as the display choices; otherwise the choices will be used to construct keys to get localized values from the interview's resource bundle.- Throws:
java.lang.NullPointerException- if choices is null.- See Also:
getChoices(),setChoices(String[]),setChoices(String[], String[])
-
setChoices
protected void setChoices(java.lang.String[] choices, java.lang.String... displayChoices)Set the set of legal responses for this question. If the current value is one of the choices (string equality), it will be set identically equal to that choice; otherwise, the current value will be set to the first choice.- Parameters:
choices- An array of strings identifying the set of legal responses for this question.displayChoices- An array of strings to be presented to the user that identify the legal responses to this question. The value can also be null, to indicate that the display choices should be determined automatically by obtaining localized values for the entries in the choices array.- Throws:
java.lang.NullPointerException- if choices is null.java.lang.IllegalArgumentException- if displayChoices is not null and is a different length than choices.- See Also:
getChoices(),setChoices(String[]),setChoices(String[], boolean)
-
setI18NChoices
@Deprecated protected void setI18NChoices(java.lang.String... choices)
Deprecated.Use the other setChoices() methods, which support i18n as an option.Set the set of legal responses for this question, using the standard resource bundle for localization.- Parameters:
choices- The set of possible responses for this question. Each entry in the argument array is localized by looking up question-key.choices[i] in the standard resource bundle used by the parent interview. If an appropriate entry is not found, the array value (choices[i]) is used instead.- See Also:
getChoices(),setChoices(java.lang.String[], boolean),Interview.getResourceBundle()
-
getChoices
public java.lang.String[] getChoices()
Get the set of legal responses for this question.- Returns:
- The set of possible responses for this question.
- See Also:
setChoices(java.lang.String[], boolean),getDisplayChoices()
-
setChoices
protected void setChoices(java.lang.String... choices)
Set the set of legal responses for this question. If the current value is one of the choices (string equality), it will be set identically equal to that choice; otherwise, the current value will be set to the first choice.- Parameters:
choices- The set of possible responses for this question.- Throws:
java.lang.NullPointerException- if choices is null.- See Also:
getChoices(),setChoices(String[], boolean),setChoices(String[], String[])
-
getDisplayChoices
public java.lang.String[] getDisplayChoices()
Get the display values for the set of legal responses for this question. The display values will typically be different from the standard values if they have been localized.- Returns:
- The display values for the set of possible responses for this question.
- See Also:
setChoices(java.lang.String[], boolean)
-
getDefaultValue
public java.lang.String getDefaultValue()
Get the default response for this question. It defaults to the first choice in the array of choices set with setChoices.- Returns:
- the default response for this question.
- See Also:
setDefaultValue(java.lang.String)
-
setDefaultValue
public void setDefaultValue(java.lang.String v)
Set the default response for this question, used by the clear method.- Parameters:
v- the default response for this question.- See Also:
getDefaultValue()
-
getValue
public java.lang.String getValue()
Get the internal value for the current (default or latest) response to this question.- Returns:
- The current value.
- See Also:
setValue(java.lang.String),getDisplayChoices()
-
setValue
public void setValue(java.lang.String newValue)
Set the current value.- Specified by:
setValuein classQuestion- Parameters:
newValue- The value to be set. It must be one of the valid choices for this question, as distinct from the display choices.- See Also:
getValue()
-
getDisplayValue
public java.lang.String getDisplayValue()
Get the display string for the current (default or latest) response to this question.- Returns:
- The display string for the current value.
- See Also:
setValue(java.lang.String),getDisplayChoices()
-
getValueOnPath
public java.lang.String getValueOnPath() throws Interview.NotOnPathFaultVerify 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:
getValue()
-
getStringValue
public java.lang.String getStringValue()
Description copied from class:QuestionGet the response to this question as a string.- Specified by:
getStringValuein classQuestion- Returns:
- a string representing the current response to this question, or null.
- See Also:
Question.setValue(String)
-
isValueValid
public boolean isValueValid()
Description copied from class:QuestionCheck if the question currently has a valid response.- Specified by:
isValueValidin classQuestion- Returns:
- true if the question currently has a valid response, and false otherwise.
-
isValueAlwaysValid
public boolean isValueAlwaysValid()
Description copied from class:QuestionCheck if the question always has a valid response. This may be true, for example, for a choice question with a default response.- Specified by:
isValueAlwaysValidin classQuestion- Returns:
- true if the question always has a valid response, and false otherwise.
-
clear
public void clear()
Clear any response to this question, resetting the value back to its initial state.
-
-