|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcox.jmatt.java.MathTools.MathSet
public class MathSet
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
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.
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 NumbersThe 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.
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!
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)
.
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.
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.
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 |
---|
public static final java.lang.String EMPTY
public static final java.lang.String DEFAULT_FORMAT
public static final java.lang.String SHELF_KEY
MathSet
demo panel to store a parsed or pizza'd set on The Shelf. Literal value is 'MathSet_SHELF_KEY'.
public static final java.lang.String SYM_COMPLEX
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.
public static final java.lang.String SYM_IMAGINARY
public static final java.lang.String SYM_REAL
public static final java.lang.String SYM_RATIONAL
public static final java.lang.String SYM_INTEGER
public static final java.lang.String SYM_WHOLE
public static final java.lang.String SYM_NATURAL
public static final java.lang.String SYM_IRRATIONAL
public static final java.lang.String DEBUG_PROBLEM_FORMAT
public static final java.lang.String DEBUG_ANSWER_FORMAT
public static final java.lang.String DEBUG_QUESTION_FORMAT
public static final java.lang.String SIMPLE_SUPER_PROB
public static final java.lang.String SIMPLE_SUPER_ANS
public static final java.lang.String SIMPLE_SUB_PROB
public static final java.lang.String SIMPLE_SUB_ANS
public static final java.lang.String DATA_STRING_DELIMITER
Method Detail |
---|
public static final MathSet createInstance(java.lang.String pSets)
MSet
using the parameter string supplied. If the pSets is null or blank, the empty set is returned.
public final MathSet newInstance(java.lang.String pSets)
MathSet
.
public static final MathSet createFromPizza(java.lang.String pPizza, boolean pIsFile, boolean pGRAS)
MathSet
from a Properties pizza. It may be raw String data, loaded from a file or loaded from a resource stream.
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.public MathSet fromPizza(java.lang.String pPizza, boolean pIsFile, boolean pGRAS)
public static final MathSet createFromGlobalPizza(java.lang.String pPrefix)
MathEngine.bread()
to load the
data from the Global Pizza.
pPrefix
- The Global Pizza block parameter prefix used to create an instance.public final MathSet fromGlobalPizza(java.lang.String pPrefix)
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 MathSet
s each define symbols for use as replacement tokens. The tokens defined are:
MathTestFormatter
replacement token key for the set. (SYM_INTEGER). See below for details.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
.
public MathSet getRealNumbers()
public static final MathSet complexNumbers()
MathSet
containing the number sets Complex, Real, Rational, Integer, Whole, Natural and Irrational. It also includes the
(Complex!) subset of purely imaginary numbers.
public MathSet getComplexNumbers()
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.
public MathSet getEmptySet()
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:
pSets
- The set String to add to the current instance.
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.
public final boolean isClosed()
public java.lang.String getUSet()
MathSet
.
public void setDescription(java.lang.String pDesc)
MathSet
. Ignored if null or empty OR the set has been closed.
pDesc
- The description of what the set it.public java.lang.String getDescription()
public void setName(java.lang.String pName)
MathSet
a name. This has NO effect on its contents or manipulation, it is meta-data.
public java.lang.String getName()
public final boolean contains(java.lang.String pSet)
MathSet
contains the set specified. The names must match exactly and it must not contain a colon. This method
does close the set.
pSet
- The set to check for existence (presence within this instance).public MathSet select(java.lang.String pSet)
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!
pSet
- The set to select. Must exist!public MathSet selectInCopy(java.lang.String pSet)
public java.lang.String getSelectedSet()
public java.lang.String[] getSupersets()
public java.lang.String getSupersetString()
public java.lang.String getSymbolString()
public java.lang.String[] getSymbols()
public java.lang.String[] getSubsets()
public boolean hasSuperset(java.lang.String pSet)
pSet
- The potential superset to check.public boolean hasSuperset(java.lang.String pBaseSet, java.lang.String pSet)
pBaseSet
- The set whose supersets to check.pSet
- The potential superset to check.public boolean hasSubset(java.lang.String pSet)
pSet
- The potential subset to check.public boolean hasSubset(java.lang.String pBaseSet, java.lang.String pSet)
pBaseSet
- The set whose subsets to check.pSet
- The potential subset to check.public java.lang.String randomSuperset()
public MathSet randomSupersetToClone()
public MathSet randomSupersetFromClone()
public java.lang.String randomSubset()
public MathSet randomSubsetToClone()
public MathSet randomSubsetFromClone()
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!
sub2sup
- Set to determine which relationship is desired, as described above.
public java.lang.String randomSet()
MathSet
.
public final java.lang.String dumpInfo()
MathSet
. Does not close the set but may not display valid information until closure.
public java.lang.String toPizza()
MathSet
into pizza (Properties
) format. This method DOES close the set!
public final MathSet copyOf()
MathSet
. This set is closed if necessary.
public static final void setDefaultFormat(java.lang.String pFormat)
public final void setNewDefaultFormat(java.lang.String pFormat)
public final void setFormat(java.lang.String pFormat)
MathSet
. Null or blank sets to the current default format.
public final void setFormatInCopy(java.lang.String pFormat)
public final void setFormatInBoth(java.lang.String pFormat)
public void unClone()
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!
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.public java.lang.String format(java.lang.String pTemplate)
public java.lang.String format()
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 |
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.public Question createQuestion(java.lang.String pProb, java.lang.String pAns)
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.
pProb
- The Problem formatting template.pAns
- The Answer template.public Question createRandomQuestion(boolean pSuper)
pSuper
- 'true' for a superset question, 'false' for subset.public Question createSimpleQuestion(java.lang.String pSet, java.lang.String pCloneSet, boolean pSuper)
createRandomQuestion()
in that it uses the selected
sets rather than random ones.
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.public java.lang.String dataString(boolean pLongString)
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.
pLongString
- Set 'true' for one long String, 'false' for multiline.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |