public class Block extends SurveyObj implements Comparable, Serializable
Blocks are the basic unit of state in the survey. They are used to specify control flow. Blocks may contain questions. The order of these questions within the block may be randomized. If the user does not want questions randomized within a block, they must place each question in its own, stationary (non-randomizable) block.
The order of blocks may be randomized.
Modifier and Type | Class and Description |
---|---|
static class |
Block.BranchParadigm
"Branching" refers to atypical control flow in the survey.
|
Modifier and Type | Field and Description |
---|---|
protected Block.BranchParadigm |
branchParadigm
The branch paradigm associated with this block.
|
Question |
branchQ
The branch question associated with this block.
|
static String |
NEXT
The next pointer.
|
Block |
parentBlock
The parent pointer for this block.
|
List<Question> |
questions
The questions that reside directly in this block (not in sub-blocks).
|
List<Block> |
subBlocks
The sub-blocks that this block contains.
|
Constructor and Description |
---|
Block(String strId)
Constructs a block with the appropriate string id.
|
Modifier and Type | Method and Description |
---|---|
void |
addBlock(Block b)
Method to add a subblock to this block programmatically.
|
void |
addBranchQuestion(Question q) |
void |
addQuestion(Question q) |
void |
addQuestions(Question... questions) |
boolean |
before(Block that)
Compares this block to the input block.
|
int |
blockSize()
Counts the number of questions directly in this block and in all sub-blocks.
|
int |
compareTo(Object o)
DO NOT CALL COLLECTIONS.SORT IF YOU HAVE FLOATING BLOCKS -- compareTo is transitive and you may get out-of-order
blocks.
|
boolean |
containsQuestion(Question question) |
boolean |
equals(Object o)
Two blocks are equal if their internal identifiers are equal.
|
List<Question> |
getAllQuestions()
Returns all of the questions for this block and all of its sub-blocks.
|
int |
getBlockDepth()
Returns the depth at which this block exists.
|
int[] |
getBlockId()
Returns the internal block identifier.
|
Set<Block> |
getBranchDestinations() |
Block.BranchParadigm |
getBranchParadigm()
Gets the branch paradigm type.
|
Block |
getFarthestContainingBlock()
Returns the topmost block of this block; if this block is top-level, it returns itself.
|
String |
getParentStrId()
Returns the parent block's source identifier string.
|
static List<Block> |
getSorted(List<Block> blockList)
Sorts the input block list.
|
String |
getStrId()
Returns the identifier for this block in the source file.
|
boolean |
hasBranchQuestion() |
int |
hashCode()
Hashed on the internal block identifier.
|
static int[] |
idToArray(String strId)
Returns a parsed, internal representation of the input identifier string.
|
static String |
idToString(int[] id,
Map<String,Block> blockMap)
Converts an internal block identifier to the string block identifier, according to the language/format specified
for CSVs.
|
static boolean |
isRandomizable(String strId)
Returns whether a block with the input id "float."
|
boolean |
isRandomized()
Returns whether this block may be shuffled along with other "floating" blocks and questions inside its containing
block.
|
boolean |
isSubblockOf(Block b)
Compares this block with the input block and returns true if the input is a descendant of this block.
|
boolean |
isTopLevel()
Returns whether this block is at the top of the survey (has no parents).
|
String |
jsonize() |
static String |
jsonize(List<Block> blockList) |
void |
propagateBranchParadigm()
Sets the appropriate
Block.BranchParadigm for all connected blocks. |
void |
setIdArray(int[] id)
Sets this block's internal block identifier to the input internal block identifier.
|
void |
setParentPointer()
Sets the parent pointer of this block, according to its source string identifier.
|
void |
setStrId(String strId)
Sets the source identifier for this block.
|
static Block[] |
shuffle(List<Block> blockList)
Shuffles the input block list, respecting static vs floating blocks.
|
String |
toString()
Composed of the block identifier and the string representation of its containing questions and sub-blocks.
|
void |
updateBranchParadigm(Block.BranchParadigm branchParadigm) |
public static final String NEXT
public List<Question> questions
public Question branchQ
protected Block.BranchParadigm branchParadigm
public Block parentBlock
public Block(String strId)
strId
- The source identifier string.public String getStrId()
public void setStrId(String strId)
strId
- The source identifier string.public static boolean isRandomizable(String strId)
strId
- The source identifier string.public static int[] idToArray(String strId)
strId
- The source identifier string.public String getParentStrId()
public static String idToString(int[] id, Map<String,Block> blockMap)
id
- A SurveyMan internal block identifier.public void setParentPointer()
public void updateBranchParadigm(Block.BranchParadigm branchParadigm)
public Block.BranchParadigm getBranchParadigm()
public void propagateBranchParadigm() throws SurveyException
Block.BranchParadigm
for all connected blocks.SurveyException
public boolean isRandomized()
public boolean isTopLevel()
public boolean before(Block that)
that
- The block to compare.public boolean isSubblockOf(Block b)
b
- The block to compare.public void setIdArray(int[] id)
id
- The input block identifier.public int getBlockDepth()
public int[] getBlockId()
public static List<Block> getSorted(List<Block> blockList)
blockList
- The block list to be sortedpublic int blockSize()
public boolean equals(Object o)
public int hashCode()
public List<Question> getAllQuestions()
public boolean containsQuestion(Question question)
public static Block[] shuffle(List<Block> blockList)
blockList
- The block list to be shuffled.public String jsonize() throws SurveyException
SurveyException
public static String jsonize(List<Block> blockList) throws SurveyException
SurveyException
public boolean hasBranchQuestion()
public void addBranchQuestion(Question q)
public void addQuestion(Question q) throws SurveyException
SurveyException
public void addQuestions(Question... questions) throws SurveyException
SurveyException
public void addBlock(Block b) throws SurveyException
b
- The block we want to add as a subblock.SurveyException
public Block getFarthestContainingBlock()
public String toString()
public int compareTo(Object o)
compareTo
in interface Comparable
o
- The object to compare.Copyright © 2015. All rights reserved.