public class Question extends SurveyObj
Modifier and Type | Class and Description |
---|---|
static class |
Question.MalformedOptionException
Thrown by the Parser.
|
static class |
Question.OptionNotFoundException
Thrown whenever the user or system attempts to find an option by text, input cell, etc.
|
Modifier and Type | Field and Description |
---|---|
Component |
answer
Answer to the question, if it exists.
|
Block |
block
The enclosing block for this question.
|
protected BranchMap |
branchMap
Map from answer options to branch destinations (
Block ). |
String |
correlation
A correlation label.
|
Component |
data
Data to be displayed when the user takes the survye.
|
Boolean |
exclusive
True if respondents may only answer one of the answer options.
|
Boolean |
freetext
True if this question requires a text response.
|
String |
freetextDefault
Set if this question requires a text response and should display example text.
|
Pattern |
freetextPattern
Set if this question requires a text response and must conform to a regular expression.
|
Map<String,Component> |
options
Map from component identifiers to answer option objects (
Component ). |
Boolean |
ordered
True if the answer options have a natural ordering (e.g., Likert scales).
|
Map<String,String> |
otherValues
Map from other input column headers to their values, when they exist for this question.
|
boolean |
permitBreakoff
Indicates whether respondents may submit their results immediately after answering this questions, regardless of
its position in the survey.
|
String |
quid
Unique question identifier.
|
Boolean |
randomize
True if the answer options may be randomized.
|
List<Integer> |
sourceLineNos
Source data line numbers corresponding to this question.
|
Constructor and Description |
---|
Question(Component data,
int row,
int col)
Used by the
edu.umass.cs.surveyman.input parsers. |
Question(String data)
Constructor for the programmatic creation of questions.
|
Question(String data,
boolean ordered,
boolean exclusive)
Creates a new question object using the string data.
|
Question(String data,
int row,
int col)
Creates a question whose identifier is based on the question's input location and whose associated data
Component is . |
Modifier and Type | Method and Description |
---|---|
void |
addOption(Component component)
Adds the input component as an answer option to the question.
|
void |
addOption(Component component,
Block branchTo)
Adds an answer option as part of a branch question.
|
void |
addOption(Component component,
Block branchTo,
boolean exclusive,
boolean ordered)
Adds an answer option as part of a branch question.
|
void |
addOption(Component component,
boolean exclusive,
boolean ordered)
Adds the input component as an answer option to the question.
|
void |
addOption(String surfaceText)
Add an option with the input surface text.
|
void |
addOption(String surfaceText,
boolean exclusive,
boolean ordered)
Adds an option to the question.
|
void |
addOptions(String... surfaceTexts)
Adds options with the input surface text.
|
boolean |
before(Question q)
Tests whether this question precedes the input question, according to their enclosing blocks.
|
static boolean |
customQuestion(String quid)
Determines whether the input question id corresponds to a known custom question pattern.
|
boolean |
equals(Object o)
Two questions are equal if the following are equal:
|
Block |
getBranchDest(Component c)
Returns the branch destination for the input question.
|
Set<Block> |
getBranchDestinations()
Loops through the branch destinations for this question and returns the set of blocks this question branches to.
|
Component |
getOptById(String oid)
Returns the answer option associated with this question having the input
Component identifier. |
Component[] |
getOptListByIndex()
Returns a sorted array of the answer options.
|
int |
getSourceCol()
Getter for the input source column.
|
int |
getSourceRow()
Getter for the input source line.
|
List<Question> |
getVariants()
For each question, returns the set of all equivalent questions (including itself).
|
int |
hashCode()
Hashcodes are computed from the quid.
|
boolean |
isBranchQuestion()
Tests whether this question is a branch question.
|
protected String |
jsonize() |
protected static String |
jsonize(List<Question> questionList) |
static void |
makeOrderedRadioQuestions(Question[] questions,
String... surfaceStrings) |
static String |
makeQuestionId(int row,
int col)
Creates a question identifier corresponding to the input data location.
|
static void |
makeUnorderedCheckQuestions(Question[] questions,
String... surfaceStrings) |
static void |
makeUnorderedRadioQuestions(Question[] questions,
String... surfaceStrings)
Convenience method for quickly creating a series of questions with the default settings.
|
void |
setBranchDest(Component c,
Block dest)
Sets the branch destination of this question at the input option to the input destination.
|
String |
toString()
Returns a string of the question data.
|
protected void |
updateFromSurvey(Survey s) |
public String quid
public Component data
public Component answer
public Map<String,Component> options
Component
).protected BranchMap branchMap
Block
). This may be left
empty if there is no branching.public List<Integer> sourceLineNos
public Map<String,String> otherValues
public Block block
public Boolean exclusive
public Boolean ordered
public Boolean randomize
public Boolean freetext
public Pattern freetextPattern
public String freetextDefault
public boolean permitBreakoff
public String correlation
public Question(Component data, int row, int col)
edu.umass.cs.surveyman.input
parsers.data
- The parsed, internal representation of the data in a cell.row
- The input row (literal or calculated, as with JSON).col
- The input column (literal or calculated, as with JSON).public Question(String data, int row, int col)
Component
is .data
- The data associated with this question.row
- This question's initial input row index.col
- The question column index.public Question(String data, boolean ordered, boolean exclusive)
data
- The data associated with this question.ordered
- True if the question's responses are ordered.exclusive
- True if the question is a radio question.public Question(String data)
data
- The data associated with this question.public static boolean customQuestion(String quid)
quid
- The identifier of the question we are testing.public static String makeQuestionId(int row, int col)
row
- This question's initial input row index.col
- The question column index.protected void updateFromSurvey(Survey s)
public void addOption(String surfaceText, boolean exclusive, boolean ordered) throws SurveyException
surfaceText
- The answer option text to display.exclusive
- Boolean indicating whether this should be a radio button question. Must agree with the default
question setting.ordered
- Boolean indicating whether the answer options are ordered. Must agree with the default question
setting.SurveyException
public void addOption(String surfaceText) throws SurveyException
surfaceText
- The text this option should display.SurveyException
public void addOptions(String... surfaceTexts) throws SurveyException
surfaceTexts
- The surface texts to display.SurveyException
public void addOption(Component component, boolean exclusive, boolean ordered) throws SurveyException
component
- The option to add.exclusive
- Boolean indicating whether this should be a radio button question. Must agree with the default
question setting.ordered
- Boolean indicating whether the answer options are ordered. Must agree with the default question
setting.SurveyException
public void addOption(Component component) throws SurveyException
component
- The option to add.SurveyException
public void addOption(Component component, Block branchTo, boolean exclusive, boolean ordered) throws SurveyException
component
- The option to add.branchTo
- The block this option points to.exclusive
- Boolean indicating whether this should be a radio button question. Must agree with the default
question setting.ordered
- Boolean indicating whether the answer options are ordered. Must agree with the default question
setting.SurveyException
public void addOption(Component component, Block branchTo) throws SurveyException
component
- The option to add.branchTo
- The block this option points to.SurveyException
public Set<Block> getBranchDestinations()
public boolean isBranchQuestion()
public Block getBranchDest(Component c) throws SurveyException
c
- The answer option whose branch destination we want to know.SurveyException
public void setBranchDest(Component c, Block dest) throws SurveyException
c
- The answer option whose branch destination we need to set.dest
- The branch destination for the input answer option.SurveyException
public Component getOptById(String oid) throws SurveyException
Component
identifier.oid
- The input Component
identifier.Component
subclass.Question.OptionNotFoundException
- if there is no answer option associated
with this question.SurveyException
public Component[] getOptListByIndex() throws SurveyException
Component
array of the answer options, sorted by their relative
indices.Question.MalformedOptionException
- if there is an error with the options'
indices.SurveyException
public boolean before(Question q)
before
.q
- Question to compare.true
if the input question follows this question. false
if randomization and/or partial
ordering cannot determine a strict ordering.public int getSourceRow()
int
corresponding to the first input source line.public int getSourceCol()
int
corresponding to the QUESTION column.public List<Question> getVariants()
protected String jsonize() throws SurveyException
SurveyException
protected static String jsonize(List<Question> questionList) throws SurveyException
SurveyException
public static void makeUnorderedRadioQuestions(Question[] questions, String... surfaceStrings)
questions
- An array that will be populated with new question objects.surfaceStrings
- The strings corresponding to the text the user will see.public static void makeOrderedRadioQuestions(Question[] questions, String... surfaceStrings)
public static void makeUnorderedCheckQuestions(Question[] questions, String... surfaceStrings)
public String toString()
public boolean equals(Object o)
Copyright © 2015. All rights reserved.