exe
Class questionCollection

java.lang.Object
  extended by exe.questionCollection
Direct Known Subclasses:
XMLquestionCollection

public class questionCollection
extends java.lang.Object

This class is used to store a collection of question objects. A questionCollection object contains a reference to the PrintWriter output stream to which it is to write question information and maintains a Vector of the questions that have been added to the collection. Using a questionCollection in a script-producing program provides a simple mechanism for managing questions and properly inserting them into the showfile.

Modifications to this class have been made that allow the user to use probability functions to control the insertion of questions into the showfile. These changes make it possible to evenly distribute questions throughout an animation and precisely control when questions are asked.

In order to use the question support provided by questionCollection, a script-producing program must import the package exe. Note that a questionCollection only allows the insertion of questions of the types fibQuestion, mcQuestion, msQuestion, and tfQuestion. Therefore, this class is intended for use with programs that produce scripts in the ANIMAL or old GAIGS formats.

Author:
? (original author), Ben Tidman (probability modifications and original comments), Andrew Jungwirth (editing and Javadoc comments)

Constructor Summary
questionCollection(java.io.PrintWriter out)
          Constructs a new questionCollection by specifying the PrintWriter output stream to which this collection should write its information.
questionCollection(java.io.PrintWriter out, int numq)
          Constructs a new questionCollection by specifying the PrintWriter output stream to which this collection should write its information and the maximum number of questions that can be added to this collection.
questionCollection(java.io.PrintWriter out, int numq, int nump)
          Constructs a new questionCollection by specifying the PrintWriter output stream to which this collection should write its information, the maximum number of questions that can be added to this collection, and the number of possibilities to add questions to this collection.
 
Method Summary
 boolean addQuestion(question q)
          Adds a question to this questionCollection.
 boolean addQuestion(question q, boolean always)
          Adds a question to this questionCollection and gives the user the option to ignore the probability functions to ensure that the question will be added.
 void adjustProbability()
          Recalculates the probability of inserting a question into this questionCollection.
 void animalInsertQuestion(int index)
          Deprecated. Replaced by animalInsertQuestion(String). Since calls to addQuestion do not always add a question to this collection (due to the probability functions), a question's id might be different from its index in the Vector, causing this method to insert a different question than the programmer intended. Therefore, this method is unreliable when using the new probability functions and remains only to support old code.
 void animalInsertQuestion(java.lang.String ID)
          Inserts the ANIMAL format reference for the question with id ID in this questionCollection at the current point in the showfile.
 void animalWriteQuestionsAtEOSF()
          Writes out the information for each question stored in this collection in the ANIMAL format.
 void incPos()
          Increments countp and then adjusts the probability of inserting a question accordingly.
 void insertQuestion(int index)
          Deprecated. Replaced by insertQuestion(String). Since calls to addQuestion do not always add a question to this collection (due to the probability functions), a question's id might be different from its index in the Vector, causing this method to insert a different question than the programmer intended. Therefore, this method is unreliable when using the new probability functions and remains only to support old code.
 void insertQuestion(java.lang.String ID)
          Inserts the old GAIGS format reference for the question with id ID in this questionCollection at the current point in the showfile.
 void writeQuestionsAtEOSF()
          Writes out the information for each question stored in this collection in the old GAIGS format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

questionCollection

public questionCollection(java.io.PrintWriter out)
Constructs a new questionCollection by specifying the PrintWriter output stream to which this collection should write its information.

This constructor creates a questionCollection that does not use any of the new probability functions. Therefore, this constructor can be used by script-producing programs that use different methods to determine when questions should be added to the showfile.

Parameters:
out - Indicates the PrintWriter output stream to which this questionCollection should write its information.

questionCollection

public questionCollection(java.io.PrintWriter out,
                          int numq)
Constructs a new questionCollection by specifying the PrintWriter output stream to which this collection should write its information and the maximum number of questions that can be added to this collection.

Invoking this constructor creates a questionCollection that uses the value passed to numq to determine the probability of adding a question when addQuestion is called.

Parameters:
out - Specifies the PrintWriter output stream to which this questionCollection should write its information.
numq - Indicates the maximum number of questions that can be added to this questionCollection. This value is used to determine the probability of adding questions to this collection.

questionCollection

public questionCollection(java.io.PrintWriter out,
                          int numq,
                          int nump)
Constructs a new questionCollection by specifying the PrintWriter output stream to which this collection should write its information, the maximum number of questions that can be added to this collection, and the number of possibilities to add questions to this collection.

Calling this constructor creates a questionCollection that uses the value passed to numq to determine the probability of adding a question when addQuestion is called and uses the value passed to nump to evenly distribute the questions throughout the showfile's snapshots.

Parameters:
out - Indicates the PrintWriter output stream to which this questionCollection should write its information.
numq - Sets the maximum number of questions that can be added to this questionCollection. This value is used to determine the probability of adding questions to this collection.
nump - Specifies the number of opportunities to add a question to this questionCollection. This number is used to evenly distribute questions throughout the showfile.
Method Detail

addQuestion

public boolean addQuestion(question q)
Adds a question to this questionCollection. If this collection was created by calling questionCollection(PrintWriter), the question will always be added to this collection. If either of the other two constructors was used to create this questionCollection, the probability functions will be used to determine whether the question is added to this collection. Note that, in these cases, the question will never be added if the maximum number of questions has been reached.

Parameters:
q - Indicates the question that should be added to this collection. Note that only fibQuestion, mcQuestion, msQuestion, and tfQuestion objects can be added to a questionCollection; any other type of object will never be added to this collection.
Returns:
Gives a value of true if the specified question was added to this collection; otherwise, false is returned.

addQuestion

public boolean addQuestion(question q,
                           boolean always)
Adds a question to this questionCollection and gives the user the option to ignore the probability functions to ensure that the question will be added. This method functions identically to addQuestion(question), except that it allows the user to force adding the question to this collection as long as the maximum number of questions has not already been reached.

Parameters:
q - Indicates the question that should be added to this collection. Note that only fibQuestion, mcQuestion, msQuestion, and tfQuestion objects can be added to a questionCollection; any other type of object will never be added to this collection.
always - Specifies if the probability functions should be used to determine whether the question is added or ignored. A value of true bypasses the probability functions and causes the question to be added as long as the maximum number of questions has not already been reached. A value of false makes this method function identically to addQuestion(question).
Returns:
Yields a value of true if the given question was added to this collection; otherwise returns false.

incPos

public void incPos()
Increments countp and then adjusts the probability of inserting a question accordingly. This method is used internally by the class and should probably have been made private but was left public to ensure compatibility with old code. There will likely never be any need to call on this method explicitly.


adjustProbability

public void adjustProbability()
Recalculates the probability of inserting a question into this questionCollection. This method is called by incPos() and should probably have been made private but was left public to ensure compatibility with old code. There will likely never be any need to call on this method explicitly.


insertQuestion

public void insertQuestion(int index)
Deprecated. Replaced by insertQuestion(String). Since calls to addQuestion do not always add a question to this collection (due to the probability functions), a question's id might be different from its index in the Vector, causing this method to insert a different question than the programmer intended. Therefore, this method is unreliable when using the new probability functions and remains only to support old code.

Inserts the old GAIGS format reference for the question stored at index index in this questionCollection's Vector of questions at the current point in the showfile.

Parameters:
index - Specifies which question's reference should be inserted into the showfile by giving its index in this collection's Vector of questions. If the value of index is not a valid index to this Vector, no question reference is inserted.

insertQuestion

public void insertQuestion(java.lang.String ID)
Inserts the old GAIGS format reference for the question with id ID in this questionCollection at the current point in the showfile.

This method does a linear search on the Vector of questions to find the question with an id that matches ID. If a match is found, the reference for the matching question is inserted into the current point in the animation file; otherwise, no change is made to the showfile.

Parameters:
ID - Indicates the id value of the question that should be asked in the current snapshot of the animation. If no question is found with an id that matches ID, no question reference is inserted into the showfile. If a match is found, a reference to the matching question is inserted at the current point in the specified PrintWriter output stream.

animalInsertQuestion

public void animalInsertQuestion(int index)
Deprecated. Replaced by animalInsertQuestion(String). Since calls to addQuestion do not always add a question to this collection (due to the probability functions), a question's id might be different from its index in the Vector, causing this method to insert a different question than the programmer intended. Therefore, this method is unreliable when using the new probability functions and remains only to support old code.

Inserts the ANIMAL format reference for the question stored at index index in this questionCollection's Vector of questions at the current point in the showfile.

Parameters:
index - Specifies which question's reference should be inserted into the showfile by giving its index in this collection's Vector of questions. If the value of index is not a valid index to this Vector, no question reference is inserted.

animalInsertQuestion

public void animalInsertQuestion(java.lang.String ID)
Inserts the ANIMAL format reference for the question with id ID in this questionCollection at the current point in the showfile.

This method does a linear search on the Vector of questions to find the question with an id that matches ID. If a match is found, the reference for the matching question is inserted into the current point in the animation file; otherwise, no change is made to the showfile.

Parameters:
ID - Indicates the id value of the question that should be asked in the current snapshot of the animation. If no question is found with an id that matches ID, no question reference is inserted into the showfile. If a match is found, a reference to the matching question is inserted at the current point in the specified PrintWriter output stream.

writeQuestionsAtEOSF

public void writeQuestionsAtEOSF()
Writes out the information for each question stored in this collection in the old GAIGS format. Calling this method after the rest of the animation file has been written causes the question information to be appended to the end of the file so that the questions can be added to the animation at the snapshots in which their references appear.


animalWriteQuestionsAtEOSF

public void animalWriteQuestionsAtEOSF()
Writes out the information for each question stored in this collection in the ANIMAL format. Calling this method after the rest of the animation file has been written causes the question information to be appended to the end of the file so that the questions can be added to the animation at the snapshots in which their references appear.