cox.jmatt.java.MathTools.test
Class MTest

java.lang.Object
  extended by cox.jmatt.java.MathTools.test.MTest

public class MTest
extends java.lang.Object

MTest is a simple container for MTestElements. It makes provision for holding them in the order in which they are entered, formatting them and presenting the results. The Problem and Answer parts can be printed individually or sequentially, the internal formats can be used or one can be specified for Problem and Answer separately.

Formatting via this class does not change any of the data formatted with one exception. When the element content is actually formatted all newline characters are replaced with the value set in the setNewline() method. This occurs after the content is pulled from the test elements and before it is printed so the original data doesn't change.


Constructor Summary
MTest()
          This is the only constructor needed.
 
Method Summary
 void add(MTestElement mElement)
          Add a MTestElement to the internal list.
 void addBlock(java.lang.String pContent)
          Add a TEXT_BLOCK MTFI element.
 void addGraphMark(java.lang.String pContent)
          Add a GRAPH_MARK MTFI element.
 void addLine(java.lang.String pContent)
          Add a TEXT_LINE MTFI element.
 void addNote(java.lang.String pContent)
          Add a TEXT_NOTE MTFI element.
 void addPageBreak()
          Add a PAGE_BREAK MTFI element.
 java.lang.String format()
          Format each element, in order, per the zero-argument format() method.
 java.lang.String format(java.lang.String pTemplate)
          This method formats each element according to the template String passed in.
 java.lang.String formatAnswers()
          This method calls formatAnswer() on each element on the test.
 java.lang.String formatProblems()
          This method calls formatProblem() on each element on the test.
 java.lang.String formatTest()
          Convenience method for formatTest(null).
 java.lang.String formatTest(java.lang.String pKeySep)
          This method calls formatProblems() and formatAnswers() and concatenates the results.
 MTestParser getNewParser()
          Instance method to crate a new parser.
static MTestParser getParser()
          Create and return a new MTestParser.
static java.lang.String replaceNewlines(java.lang.String pRaw)
          This method replaces newline characters ('\n') with whatever value is set, other than '\n' (...
 void reset()
          Reset everything on the test.
static void set_XML_escape(boolean yesNo)
          Set the (static) XML escape flag.
 void setEscapeXML(boolean yesNo)
          Instance shadow to set XML escape.
 void setFormatMTFI(java.lang.String pFormat)
          Set the 'entire' format for MTFI.
 void setLineSeparator(java.lang.String pNewSep)
          Set the separator appended to each element's content when it is formatted.
 void setNewline(char pChar)
          Set the character or character sequence used for newlines.
 void setShowID_MTFI(boolean yesNo)
          Toggle MTFI ID display in formatting token 0.
 java.lang.String toString()
          Overridden.
 java.lang.String toXML()
          Convert all elements to XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MTest

public MTest()

This is the only constructor needed.

Method Detail

setNewline

public final void setNewline(char pChar)

Set the character or character sequence used for newlines. This is the only formatting 'change' MTest makes to any content. There are three choices:

Uppercase or lowercase characters work equally well but ONLY the three characters, as char, are valid values. Any others are ignored.


set_XML_escape

public static void set_XML_escape(boolean yesNo)
Set the (static) XML escape flag. This method also sets MTFI's escape. It is assumed that any Questions will handle themselves.


replaceNewlines

public static java.lang.String replaceNewlines(java.lang.String pRaw)
This method replaces newline characters ('\n') with whatever value is set, other than '\n' (... which is no replacement at all!).


setEscapeXML

public void setEscapeXML(boolean yesNo)
Instance shadow to set XML escape.


setLineSeparator

public void setLineSeparator(java.lang.String pNewSep)
Set the separator appended to each element's content when it is formatted. The default is an empty String ('') and this is set if pNewSep is null.


setFormatMTFI

public void setFormatMTFI(java.lang.String pFormat)
Set the 'entire' format for MTFI. Setting null resets it to default.


setShowID_MTFI

public void setShowID_MTFI(boolean yesNo)
Toggle MTFI ID display in formatting token 0. Defaults to false.


reset

public void reset()
Reset everything on the test. The newline character reverts to '\n', the XML escape reverts to 'true' (this applies to MTFI as well), all elements currently stored are cleared and the default separator(s) are cleared.


getParser

public static MTestParser getParser()
Create and return a new MTestParser.


getNewParser

public MTestParser getNewParser()
Instance method to crate a new parser.


add

public void add(MTestElement mElement)
Add a MTestElement to the internal list. If mElement is null it is silently ignored.

Parameters:
mElement - The MTestElement to add to the test. Ignored if null.

addLine

public void addLine(java.lang.String pContent)
Add a TEXT_LINE MTFI element. Silently ignored if pContent is null or blank.


addBlock

public void addBlock(java.lang.String pContent)
Add a TEXT_BLOCK MTFI element. Silently ignored if pContent is null or blank.


addNote

public void addNote(java.lang.String pContent)
Add a TEXT_NOTE MTFI element. Silently ignored if pContent is null or blank.


addGraphMark

public void addGraphMark(java.lang.String pContent)
Add a GRAPH_MARK MTFI element. If pContent is null or blank a default ID is assigned.


addPageBreak

public void addPageBreak()
Add a PAGE_BREAK MTFI element.


format

public java.lang.String format()
Format each element, in order, per the zero-argument format() method. The internal line separator is appended after each element and all content is newline-replaced.


format

public java.lang.String format(java.lang.String pTemplate)

This method formats each element according to the template String passed in. No validity-checking is done on the template. The line separator is appended to each element and newlines are replaced.

Replacement tokens are per Question.

Parameters:
pTemplate - The template String by which each element is to be formatted.

formatProblems

public java.lang.String formatProblems()

This method calls formatProblem() on each element on the test. The line separator is appended and newlines replaced.


formatAnswers

public java.lang.String formatAnswers()

This method calls formatAnswer() on each element on the test. The line separator is appended and newlines replaced.


formatTest

public java.lang.String formatTest(java.lang.String pKeySep)
This method calls formatProblems() and formatAnswers() and concatenates the results. If pKeySep is not null it is newline-replaced and placed between the Problems and Answers.

Parameters:
pKeySep - A String to be placed between the formatProblems() and formatAnswers() results. Ignored if null.

formatTest

public java.lang.String formatTest()
Convenience method for formatTest(null).


toXML

public java.lang.String toXML()
Convert all elements to XML. The line separator is appended after each element and everything is newline-escaped. No XML-escaping is done here as it is assumed to have taken place already.


toString

public java.lang.String toString()
Overridden. Simply calls formatTest().

Overrides:
toString in class java.lang.Object