cox.jmatt.java.MathTools
Class MathSet

java.lang.Object
  extended by cox.jmatt.java.MathTools.MathSet

public class MathSet
extends java.lang.Object

This class acts as an immutable container for sets and provides equipment for formatting questions involving them. Even though the class is named MathSet, it is in truth a container for holding sets and for preserving superset-subset relationships between them. As such it is primarily designed to format and present set/subset questions and not to manipulate them.

When working with this class, a chain of sets means a collection of contained sets moving from the most general (universal) set ('largest') to the most specific ('smallest') in the group. For instance, the Real number chain is

'R ⊃ Q ⊃ Z ⊃ W ⊃ N'
The Universal Set is the ONE superset of all other sets and there can be only one! MathSet automatically takes the first set added as the universal set, so build with care.

A freshly-created MathSet can have sets added to it but that is all. Once it is closed, either explicitly via the 'closeSet()' method or implicitly by another method that calls it, the container becomes immutable. No more data can be added and all subset and superset relationships are calculated. In addition to sets, a MathSet can have a name and a description. These serve no mathematical purpose and exist only to allow naming and description of an instance.

Once closed, any set within the MathSet can be selected via the 'select()' method. This method allows access to the selected set's supersets, subsets and formatting symbols. The Universal Set is selected by default.

Creating and Adding Sets

A set added to a MathSet instance must have two things: a name and a position somewhere within a chain. It may also have two or more symbols associated with it for formatting purposes. All of this is accomplished via Set Descriptor Notation which is used to add sets to a MathSet.

Set Descriptor Notation uses colons and '@' signs, so these characters may not appear within a set's name. Spaces and other characters are allowed and are ignored. Colons are used to separate set names within a chain and the '@' character is used to delimit a set's symbols:

    Real:Rational:Integer
    Integer:Whole@W@Whole Numbers
    
The first line defines three sets: Real, Rational and Integer. If this is the first descriptor added to the MathSet then 'Real' becomes the Universal Set. The second line defines the Whole numbers as a subset of the Integers and also defines three symbols: the name of the set, the single-letter symbol and the formal name of the set.

A MathSet can hold as many sets as desired and each set may define as many symbols as needed. When defining symbols, though, the name of the set MUST be the first symbol since that is how symbols are associated with sets. Sets can be added in any order, provided there is at least one link to the other sets somewhere in the data. MathSet does a good job figuring out the order of set chains as long as the links can be deduced from the data sent in.

Formatting and Formatting

The format() methods are where set symbols come into play. When a set is selected, its symbols become the replacement token array for a call to Question.fillTemplate(). The symbols appear in the same order as they are defined. For the set defined above, '<2>' would be replaced with 'Whole Numbers'. This means that token '<0>' always contains the set's name and it will always be defined!

Set Pizza

The heart of a MathSet is a java.util.Properties object. The 'toPizza()' method closes the set (if necessary) and dumps the contents of this object to a properly-formatted String. The demo panel for this class, MathSetPizza, contains selections to parse descriptors or pizzas into an instance. There are also two selections that will create a MathSet from the demo panel and store it on CapCom's Shelf, thus allowing script access to a demo-defined instance.

The pizza generated by a MathSet includes a LOT of work 'under the hood,' so these files should not be edited manually! The 'toPizza()' and 'fromPizza()' methods should be employed to allow definition and subsequent re-use of large or complicated chains and trees of sets. An instance created from the demo can be accessed from within a script through Console.getObject(MSet.SHELF_KEY).

Subsets and Supersets

This is the primary raison-d'etre for this class. Therefore there are many methods for dealing with them. The 'select()' is the foundational method; it focuses all attention (and subsequent method results) on a particular set. All super- and subsets are in relation to the selected set as are the various formatting methods.

Predefined Sets

Because they are so common, the Real Numbers and the Complex Numbers come packaged within MathSet. There are two static and two instance methods for creating these sets and each set has five symbols defined on it, including one MathTestFormatter-style token key. These values are also defined as static String constants, so customization of these symbols for specific software package is simplicity itself.

My Own Clone

Each MathSet instance maintains an internal copy of itself. Method documentation refers to this as the copy or the clone and it is used primarily in the 'createQuestion()' method. For the most part it is inaccessible, directly, but there are some methods usable to manipulate it.

The internal self-copy is not created until the first method requiring it is called, so any defaults (ie formats) are applied at that time.


Field Summary
static java.lang.String DATA_STRING_DELIMITER
          This is the delimiter String used when building one LONG data string: ':@:'.
static java.lang.String DEBUG_ANSWER_FORMAT
          Debug/testing format used with 'createQuestion()' to display token values.
static java.lang.String DEBUG_PROBLEM_FORMAT
          Debug/testing format used with 'createQuestion()' to display token values.
static java.lang.String DEBUG_QUESTION_FORMAT
          Debugging format for the Question created using the above formats.
static java.lang.String DEFAULT_FORMAT
          The simplest default format possible: <0>.
static java.lang.String EMPTY
          This String is used to represent the empty set.
static java.lang.String SHELF_KEY
          This is the String key used by the MathSet demo panel to store a parsed or pizza'd set on The Shelf.
static java.lang.String SIMPLE_SUB_ANS
          Answer template for SIMPLE_SUB_PROB.
static java.lang.String SIMPLE_SUB_PROB
          Problem template for a simple subset Question using selected sets.
static java.lang.String SIMPLE_SUPER_ANS
          Answer template for SIMPLE_SUPER_PROB.
static java.lang.String SIMPLE_SUPER_PROB
          Problem template for a simple superset Question involving the selected sets.
static java.lang.String SYM_COMPLEX
          This constant is defined in the Complex Number MathSet symbols as a MathTestFormatter replacement token; i.e.
static java.lang.String SYM_IMAGINARY
          Replacement token for purely imaginary numbers.
static java.lang.String SYM_INTEGER
          Replacement token for the set of Integers.
static java.lang.String SYM_IRRATIONAL
          Replacement token for the set of Irrational numbers.
static java.lang.String SYM_NATURAL
          Replacement token for the set of Natural numbers.
static java.lang.String SYM_RATIONAL
          Replacement token for the set of Rational numbers.
static java.lang.String SYM_REAL
          Replacement token for the set of Real numbers.
static java.lang.String SYM_WHOLE
          Replacement token for the set of Whole numbers.
 
Method Summary
 boolean addSets(java.lang.String pSets)
          Add a set or set-chain to the current instance.
 MathSet closeSet()
          Close this MathSet.
static MathSet complexNumbers()
          Create a (closed!) MathSet containing the number sets Complex, Real, Rational, Integer, Whole, Natural and Irrational.
 boolean contains(java.lang.String pSet)
          Query as to whether or not this MathSet contains the set specified.
 MathSet copyOf()
          Create and return a copy of this MathSet.
static MathSet createFromGlobalPizza(java.lang.String pPrefix)
          Create an instance from the Global Pizza.
static MathSet createFromPizza(java.lang.String pPizza, boolean pIsFile, boolean pGRAS)
          Create a MathSet from a Properties pizza.
static MathSet createInstance(java.lang.String pSets)
          Create a MSet using the parameter string supplied.
 Question createQuestion(java.lang.String pProb, java.lang.String pAns)
          This is the basic Question creation method.
 Question createQuestion(java.lang.String pSet, java.lang.String pCloneSet, java.lang.String pProblem, java.lang.String pAnswer)
          This is MathSet's power-formatting method.
 Question createRandomQuestion(boolean pSuper)
          Create a Question of the form 'Is the set of X a [subset, superset] of the set of Y'.
 Question createSimpleQuestion(java.lang.String pSet, java.lang.String pCloneSet, boolean pSuper)
          Create a Question using the SIMPLE_?_PROB and SIMPLE_?_ANS formats.
 java.lang.String dataString(boolean pLongString)
          Create a data String for this MathSet.
 java.lang.String dumpInfo()
          Print some information about the sets contained within this MathSet.
static MathSet emptySet()
          Create an empty MathSet.
 java.lang.String format()
          Format the currently-selected set per the current internal template.
 java.lang.String format(java.lang.String pTemplate)
          Format the currently-selected set per the supplied template.
 java.lang.String format(java.lang.String pSet, java.lang.String pTemplate)
          Select a set and format it per the supplied template String.
 MathSet fromGlobalPizza(java.lang.String pPrefix)
          Instance Global Pizza creation method.
 MathSet fromPizza(java.lang.String pPizza, boolean pIsFile, boolean pGRAS)
          Instance shadow pizza-creation method.
 MathSet getComplexNumbers()
          Complex numbers instance shadow.
 java.lang.String getDescription()
          Retrieve the description, if set.
 MathSet getEmptySet()
          Empty set shadow.
 java.lang.String getName()
          Get the name, if set.
 MathSet getRealNumbers()
          Instance shadow.
 java.lang.String getSelectedSet()
          Return the currently-selected set after closing.
 java.lang.String[] getSubsets()
          Close the set and return an array (copied!) containing all subsets of the selected set.
 java.lang.String[] getSupersets()
          Return an array containing all supersets of the currently-selected set.
 java.lang.String getSupersetString()
          Return a colon-separated list of supersets, per Set Descriptor format.
 java.lang.String[] getSymbols()
          Return the current symbols as a String array.
 java.lang.String getSymbolString()
          Return the symbols for the current set as a single '@'-delimited String, closing if needed.
 java.lang.String getUSet()
          Return the name of the Universal Set for this MathSet.
 boolean hasSubset(java.lang.String pSet)
          Check to see if the selected set has the specified subset.
 boolean hasSubset(java.lang.String pBaseSet, java.lang.String pSet)
          Check for subset containment without requiring selection.
 boolean hasSuperset(java.lang.String pSet)
          Check to see if the selected set has the specified superset.
 boolean hasSuperset(java.lang.String pBaseSet, java.lang.String pSet)
          Check to see if a specified set has a given superset.
 boolean isClosed()
          Test to see whether or not this set is closed.
 MathSet newInstance(java.lang.String pSets)
          Instance shadow to create a MathSet.
 java.lang.String randomSet()
          Fetch a random set from ALL the sets contained within this MathSet.
 java.lang.String randomSubset()
          Return a random subset of the currently-selected set.
 MathSet randomSubsetFromClone()
          Select a random subset from the inner copy.
 MathSet randomSubsetToClone()
          Select a random subset of this set in the inner copy.
 java.lang.String randomSuperset()
          Select a random superset from the selected set's supersets.
 MathSet randomSupersetFromClone()
          Select a random superset from the inner copy and return a self-reference.
 MathSet randomSupersetToClone()
          Send a random superset of the currently-selected set to the inner copy.
static MathSet realNumbers()
          Create a (closed!) MathSet containing the number sets Real, Rational, Integer, Whole, Natural and Irrational.
 MathSet select(java.lang.String pSet)
          Select one of the sets contained within this MathSet as the current set.
 MathSet selectInCopy(java.lang.String pSet)
          Select a particular set in the internal copy.
static void setDefaultFormat(java.lang.String pFormat)
          Set a default format.
 void setDescription(java.lang.String pDesc)
          Set a short String description of this MathSet.
 void setFormat(java.lang.String pFormat)
          Set the internal format for this MathSet.
 void setFormatInBoth(java.lang.String pFormat)
          Convenience method to set the same internal format for both the instance and the internal clone.
 void setFormatInCopy(java.lang.String pFormat)
          Set the format for the internal copy.
 void setName(java.lang.String pName)
          Give this MathSet a name.
 void setNewDefaultFormat(java.lang.String pFormat)
          Instance shadow.
 MathSet shakeShakeShake(boolean sub2sup)
          This method works one of two ways, depending on its parameter.
 java.lang.String toPizza()
          Dump the contents of this MathSet into pizza (Properties) format.
 void unClone()
          Remove (set to null) the internal clone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final java.lang.String EMPTY
This String is used to represent the empty set. The literal value is '{}'.

See Also:
Constant Field Values

DEFAULT_FORMAT

public static final java.lang.String DEFAULT_FORMAT
The simplest default format possible: <0>.

See Also:
Constant Field Values

SHELF_KEY

public static final java.lang.String SHELF_KEY
This is the String key used by the MathSet demo panel to store a parsed or pizza'd set on The Shelf. Literal value is 'MathSet_SHELF_KEY'.

See Also:
Constant Field Values

SYM_COMPLEX

public static final java.lang.String SYM_COMPLEX
This constant is defined in the Complex Number MathSet symbols as a MathTestFormatter replacement token; i.e. it is bracketed with '${' and '}'. If using these tokens, add the symbol value to the replacement set using this key.

See Also:
Constant Field Values

SYM_IMAGINARY

public static final java.lang.String SYM_IMAGINARY
Replacement token for purely imaginary numbers.

See Also:
Constant Field Values

SYM_REAL

public static final java.lang.String SYM_REAL
Replacement token for the set of Real numbers.

See Also:
Constant Field Values

SYM_RATIONAL

public static final java.lang.String SYM_RATIONAL
Replacement token for the set of Rational numbers.

See Also:
Constant Field Values

SYM_INTEGER

public static final java.lang.String SYM_INTEGER
Replacement token for the set of Integers.

See Also:
Constant Field Values

SYM_WHOLE

public static final java.lang.String SYM_WHOLE
Replacement token for the set of Whole numbers.

See Also:
Constant Field Values

SYM_NATURAL

public static final java.lang.String SYM_NATURAL
Replacement token for the set of Natural numbers.

See Also:
Constant Field Values

SYM_IRRATIONAL

public static final java.lang.String SYM_IRRATIONAL
Replacement token for the set of Irrational numbers.

See Also:
Constant Field Values

DEBUG_PROBLEM_FORMAT

public static final java.lang.String DEBUG_PROBLEM_FORMAT
Debug/testing format used with 'createQuestion()' to display token values. Main set tokens are in this String.

See Also:
Constant Field Values

DEBUG_ANSWER_FORMAT

public static final java.lang.String DEBUG_ANSWER_FORMAT
Debug/testing format used with 'createQuestion()' to display token values. Clone set tokens are in this String.

See Also:
Constant Field Values

DEBUG_QUESTION_FORMAT

public static final java.lang.String DEBUG_QUESTION_FORMAT
Debugging format for the Question created using the above formats.

See Also:
Constant Field Values

SIMPLE_SUPER_PROB

public static final java.lang.String SIMPLE_SUPER_PROB
Problem template for a simple superset Question involving the selected sets.

See Also:
Constant Field Values

SIMPLE_SUPER_ANS

public static final java.lang.String SIMPLE_SUPER_ANS
Answer template for SIMPLE_SUPER_PROB.

See Also:
Constant Field Values

SIMPLE_SUB_PROB

public static final java.lang.String SIMPLE_SUB_PROB
Problem template for a simple subset Question using selected sets.

See Also:
Constant Field Values

SIMPLE_SUB_ANS

public static final java.lang.String SIMPLE_SUB_ANS
Answer template for SIMPLE_SUB_PROB.

See Also:
Constant Field Values

DATA_STRING_DELIMITER

public static final java.lang.String DATA_STRING_DELIMITER
This is the delimiter String used when building one LONG data string: ':@:'.

See Also:
Constant Field Values
Method Detail

createInstance

public static final MathSet createInstance(java.lang.String pSets)
Create a MSet using the parameter string supplied. If the pSets is null or blank, the empty set is returned.


newInstance

public final MathSet newInstance(java.lang.String pSets)
Instance shadow to create a MathSet.


createFromPizza

public static final MathSet createFromPizza(java.lang.String pPizza,
                                            boolean pIsFile,
                                            boolean pGRAS)
Create a MathSet from a Properties pizza. It may be raw String data, loaded from a file or loaded from a resource stream.

Parameters:
pPizza - The String containing pizza data OR the name of the file to load.
pIsFile - Is 'pPizza' a filename (true) or raw String (false).
pGRAS - If true, load the file using 'getResourceAsStream()'. Ignored if 'pIsFile' is false.

fromPizza

public MathSet fromPizza(java.lang.String pPizza,
                         boolean pIsFile,
                         boolean pGRAS)
Instance shadow pizza-creation method.


createFromGlobalPizza

public static final MathSet createFromGlobalPizza(java.lang.String pPrefix)
Create an instance from the Global Pizza. This method absolutely requires a valid prefix since it uses MathEngine.bread() to load the data from the Global Pizza.

Parameters:
pPrefix - The Global Pizza block parameter prefix used to create an instance.

fromGlobalPizza

public final MathSet fromGlobalPizza(java.lang.String pPrefix)
Instance Global Pizza creation method.


realNumbers

public static final MathSet realNumbers()

Create a (closed!) MathSet containing the number sets Real, Rational, Integer, Whole, Natural and Irrational. Since the Real Numbers and Complex Numbers are two of the most commonly-used sets, both are defined by default.

In addition to the subset containment, these MathSets each define symbols for use as replacement tokens. The tokens defined are:

Symbol (replacement token) <5> is designed for the (likely) event that none of the predefined tokens will work. The token 5 symbol consists of the literal text of the corresponding 'SYM_' constant, bracketed between '${' and '}'. This way, MathTestFormatter can be loaded with the String containing the appropriate symbol-generation characters under the 'SYM_' key. If, for instance, the text to generate the symbol for the Rational numbers is '{{RAT}}', instantiate a MathTestFormatter, call addProperty(MathSet.SYM_RATIONAL, '{{RAT}}') and run the Strings generated by MathSet through the formatter. Scripts access the key as MSet.SYM_RATIONAL.


getRealNumbers

public MathSet getRealNumbers()
Instance shadow.


complexNumbers

public static final MathSet complexNumbers()
Create a (closed!) MathSet containing the number sets Complex, Real, Rational, Integer, Whole, Natural and Irrational. It also includes the (Complex!) subset of purely imaginary numbers.


getComplexNumbers

public MathSet getComplexNumbers()
Complex numbers instance shadow.


emptySet

public static final MathSet emptySet()

Create an empty MathSet. It contains no subsets or formatting symbols; it is EMPTY! Each call to this method creates a 'new' empty set, they will NOT test as equal!

This set is the return value for some creation methods when an error occurs.


getEmptySet

public MathSet getEmptySet()
Empty set shadow.


addSets

public boolean addSets(java.lang.String pSets)

Add a set or set-chain to the current instance. Each set added is reported at Debug level.

To allow for text file parsing, this method defines two macro commands and a comment character. They are:

Each special command starts with '#' followed by a single letter. Lowercase 'n' and 'd' will also work. If including comments, leave at least one space after the '#' or the name/description might become corrupted.

Parameters:
pSets - The set String to add to the current instance.
Returns:
true if the sets are added, false otherwise.

closeSet

public final MathSet closeSet()

Close this MathSet. When that happens no new sets may be added and any methods that would normally do so return silently. Returns a self-reference for method chaining.


isClosed

public final boolean isClosed()
Test to see whether or not this set is closed. If so, nothing more can be added to it. If not, it can still be edited.


getUSet

public java.lang.String getUSet()
Return the name of the Universal Set for this MathSet.


setDescription

public void setDescription(java.lang.String pDesc)
Set a short String description of this MathSet. Ignored if null or empty OR the set has been closed.

Parameters:
pDesc - The description of what the set it.

getDescription

public java.lang.String getDescription()
Retrieve the description, if set. If not, a blank String is returned.


setName

public void setName(java.lang.String pName)
Give this MathSet a name. This has NO effect on its contents or manipulation, it is meta-data.


getName

public java.lang.String getName()
Get the name, if set. If not, a default name (NOT saved to pizza!) is returned.


contains

public final boolean contains(java.lang.String pSet)
Query as to whether or not this MathSet contains the set specified. The names must match exactly and it must not contain a colon. This method does close the set.

Parameters:
pSet - The set to check for existence (presence within this instance).

select

public MathSet select(java.lang.String pSet)
Select one of the sets contained within this MathSet as the current set. If the supplied name is null, blank or not contained, the Universal Set is selected instead. This method DOES close the set!

Parameters:
pSet - The set to select. Must exist!

selectInCopy

public MathSet selectInCopy(java.lang.String pSet)
Select a particular set in the internal copy. If the internal copy is not yet defined, this method defines it. The instance returned is this one, not the copy.


getSelectedSet

public java.lang.String getSelectedSet()
Return the currently-selected set after closing.


getSupersets

public java.lang.String[] getSupersets()
Return an array containing all supersets of the currently-selected set. The sets are in order from universal set [0] to closest. The set is closed first.


getSupersetString

public java.lang.String getSupersetString()
Return a colon-separated list of supersets, per Set Descriptor format. Close the set first.


getSymbolString

public java.lang.String getSymbolString()
Return the symbols for the current set as a single '@'-delimited String, closing if needed.


getSymbols

public java.lang.String[] getSymbols()
Return the current symbols as a String array. This closes the set.


getSubsets

public java.lang.String[] getSubsets()
Close the set and return an array (copied!) containing all subsets of the selected set. There is no particular order to them.


hasSuperset

public boolean hasSuperset(java.lang.String pSet)
Check to see if the selected set has the specified superset. This method closes the set.

Parameters:
pSet - The potential superset to check.

hasSuperset

public boolean hasSuperset(java.lang.String pBaseSet,
                           java.lang.String pSet)
Check to see if a specified set has a given superset. This differs from the one-argument method in that no selection is required. The internal copy is used to check.

Parameters:
pBaseSet - The set whose supersets to check.
pSet - The potential superset to check.

hasSubset

public boolean hasSubset(java.lang.String pSet)
Check to see if the selected set has the specified subset. This method closes the set.

Parameters:
pSet - The potential subset to check.

hasSubset

public boolean hasSubset(java.lang.String pBaseSet,
                         java.lang.String pSet)
Check for subset containment without requiring selection. Uses the clone.

Parameters:
pBaseSet - The set whose subsets to check.
pSet - The potential subset to check.

randomSuperset

public java.lang.String randomSuperset()
Select a random superset from the selected set's supersets. This method does close the set. If this set has no supersets it returns itself.


randomSupersetToClone

public MathSet randomSupersetToClone()
Send a random superset of the currently-selected set to the inner copy. Close and clone this set if necessary. Returns a self-reference.


randomSupersetFromClone

public MathSet randomSupersetFromClone()
Select a random superset from the inner copy and return a self-reference.


randomSubset

public java.lang.String randomSubset()
Return a random subset of the currently-selected set. This method closes the set. If this set has no subsets it returns itself.


randomSubsetToClone

public MathSet randomSubsetToClone()
Select a random subset of this set in the inner copy. Close and clone as needed. Return a self-reference.


randomSubsetFromClone

public MathSet randomSubsetFromClone()
Select a random subset from the inner copy. Close, clone, return a self-reference.


shakeShakeShake

public MathSet shakeShakeShake(boolean sub2sup)

This method works one of two ways, depending on its parameter. If 'sub2sup' is false, a random subset is sent to the inner copy and a random superset is selected from it, thus guaranteeing a random superset-to-subset relationship between this set and the inner copy. If 'sub2sup' is true, a random superset is sent to the inner copy and a random subset of that one selected here, yielding a random subset-to-superset connection.

This method was designed to provide the ULTIMATE in random, guaranteed set/subset selection. To wit, assume the Strings 'pProb' and 'pAns' contain the Problem and Answer formats for a set-subset question and 'bSubSup' contains the desired 'sub2sup' value. 'Middle Set' is a set close to the middle of the chain and is constant! E.g. 'Integer' for the Complex numbers.

      mySpecialSet.select('Middle Set').shakeShakeShake(bSubSup).createQuestion(pProb, pAns);
      
This simple code snippet creates a Question with random sets and a guaranteed-true 'subset of' or 'superset of' answer!

Parameters:
sub2sup - Set to determine which relationship is desired, as described above.
Returns:
A self-reference.

randomSet

public java.lang.String randomSet()
Fetch a random set from ALL the sets contained within this MathSet.


dumpInfo

public final java.lang.String dumpInfo()
Print some information about the sets contained within this MathSet. Does not close the set but may not display valid information until closure.


toPizza

public java.lang.String toPizza()
Dump the contents of this MathSet into pizza (Properties) format. This method DOES close the set!


copyOf

public final MathSet copyOf()
Create and return a copy of this MathSet. This set is closed if necessary.


setDefaultFormat

public static final void setDefaultFormat(java.lang.String pFormat)
Set a default format. If null or blank, defaults to DEFAULT_FORMAT.


setNewDefaultFormat

public final void setNewDefaultFormat(java.lang.String pFormat)
Instance shadow.


setFormat

public final void setFormat(java.lang.String pFormat)
Set the internal format for this MathSet. Null or blank sets to the current default format.


setFormatInCopy

public final void setFormatInCopy(java.lang.String pFormat)
Set the format for the internal copy. This method does create the copy if it isn't already there and it will close the set.


setFormatInBoth

public final void setFormatInBoth(java.lang.String pFormat)
Convenience method to set the same internal format for both the instance and the internal clone.


unClone

public void unClone()
Remove (set to null) the internal clone. Does not close the set, if it is still open.


format

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

Select a set and format it per the supplied template String. Formatting is per Question.fillTemplate() with the supplied template String and the symbols of the selected set as the replacement array. That is, the replacement token array is the result of splitting the appropriate set descriptor on the character ;@'.

Since the first action taken is to 'select()' the specified set, this method DOES close the set!

Parameters:
pSet - The set to format. If null, blank or absent, the Univeral Set is used.
pTemplate - The formatting template. If null or blank, the default format is used.

format

public java.lang.String format(java.lang.String pTemplate)
Format the currently-selected set per the supplied template. If 'pTemplate' is null or blank the default is used.


format

public java.lang.String format()
Format the currently-selected set per the current internal template.


createQuestion

public Question createQuestion(java.lang.String pSet,
                               java.lang.String pCloneSet,
                               java.lang.String pProblem,
                               java.lang.String pAnswer)

This is MathSet's power-formatting method. Even though MathSet defines few actual formatting tokens, this method defines many. For parameters, this method accepts the set to select in the main (parent) instance, the set to select in the internal copy (clone), the Problem template and the Answer template for the Question returned.

The replacement tokens defined are detailed below. The left column is for the parent and the right for the clone. Methods that require a parameter have it supplied from the other instance. For instance, the parent 'hasSubset()' call is applied to the set selected in the clone and vise versa. These tokens have an asterisk between the parentheses in the description.The 'format' method calls are the zero-argument versions. In the two-argument methods, the set on which the method is called supplies the first argument, even though both happen from the parent set.

Tokens #20 through #27 are derived from the hasSuperset() and hasSubset() tokens, but from the opposite point of view. In these cases the token text reads 'is a superset' or 'is not a superset', meaning the order of the tokens and the sets is more intuitive. For instance, with token #6, 'true' means the parent set does have a subset of the clone's set, which actually means the clone set is the subset! Token #22 is more intuitive; it asserts that the parent set 'is a subset of' the clone set or 'is not a subset of' the clone set. Text-based tokens are supplied for selected and random sets (not random super/sub-sets) and both superset and subset tokens are provided.

Main set
Main.call(Clone)
Clone
Clone.call(Main)
format() <0> <1>
getSelectedSet() <2> <3>
hasSuperset(*) <4> <5>
hasSubset(*) <6> <7>
randomSuperset() <8> <9>
randomSubset() <10> <11>
randomSet() <12> <13>
#13, #14 format() <14> <15>
hasSuperset(*,*)
Called on #12 and #13
<16> <17>
hasSubset(*,*)
Called on #12 and #13
<18> <19>
"_(L)_ is (not) a [sub|super]set of _(R)_"
#0⊃#1?, #1⊃#0? <20> <21>
#0⊂#1?, #1⊂#0? <22> <23>
#12⊃#13?, #13⊃#12? <24> <25>
#12⊂#13?, #13⊂#12? <26> <27>
getUSet() <28> N/A
getName() <29> N/A
getDescription() <30> N/A

Parameters:
pSet - The set to select in the main instance.
pCloneSet - The set to select in the internal copy.
pProblem - The Problem template for the returned Question.
pAnswer - The Answer template for the returned Question.

createQuestion

public Question createQuestion(java.lang.String pProb,
                               java.lang.String pAns)
This is the basic Question creation method. It assumes both this set and the inner copy are ready, it simply formats and returns a Question. replacement tokens are per the power-formatting method and only the Problem/Answer formats are required.

Parameters:
pProb - The Problem formatting template.
pAns - The Answer template.

createRandomQuestion

public Question createRandomQuestion(boolean pSuper)
Create a Question of the form 'Is the set of X a [subset, superset] of the set of Y'. The boolean parameter controls the type of question and the parent's selected set is not altered. Both sets are selected at random.

Parameters:
pSuper - 'true' for a superset question, 'false' for subset.

createSimpleQuestion

public Question createSimpleQuestion(java.lang.String pSet,
                                     java.lang.String pCloneSet,
                                     boolean pSuper)
Create a Question using the SIMPLE_?_PROB and SIMPLE_?_ANS formats. This method differs from createRandomQuestion() in that it uses the selected sets rather than random ones.

Parameters:
pSet - The set to select in the main instance.
pCloneSet - The set to select in the inner copy.
pSuper - 'true' for a superset question, 'false' for subset.

dataString

public java.lang.String dataString(boolean pLongString)
Create a data String for this MathSet. This String can be one (VERY) long String or a newline-separated group of them. Each set is listed, complete with its superset chain and symbols. In the multiline version each set has its own line. In the single-long-String, the individual set descriptors are separated with the character sequence ':@:'. The set is closed before the data String is constructed.

Parameters:
pLongString - Set 'true' for one long String, 'false' for multiline.