cox.jmatt.java.MathTools
Enum MEquation.Equation

java.lang.Object
  extended by java.lang.Enum<MEquation.Equation>
      extended by cox.jmatt.java.MathTools.MEquation.Equation
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<MEquation.Equation>
Enclosing class:
MEquation

public static enum MEquation.Equation
extends java.lang.Enum<MEquation.Equation>

This enum specifies the standard types of equations contained within the MEquations class. Each equation is documented in 'standard form' but contains additional formats for MathML, OpenOffice and LaTeX. This format can be accessed via the 'getFormat()' method using one of the specified keys.

The calculations are listed for each Equation. Elements starting with 'K' represent Knobs: 'K0' is Knob[0], 'K1' is Knob[1] etc.

The actual formats for each equation are standard Question.fillTemplate() Strings. The first element in the replacement token array ('[0]') holds the variable and the rest hold the placeholders in order: [1] is A, [2] is B etc. The relation stored in each format is equals ('=') and it is the only occurrence of this character in the raw templates.


Enum Constant Summary
TYPE_100
          Equation type: X + A = B, 2 Knobs.
TYPE_150
          Equation type: X - A = B, 2 Knobs.
TYPE_200
          Equation type: Ax = B, 2 Knobs.
TYPE_300
          Equation type: X/A = B, 2 Knobs.
TYPE_325
          Equation type: X/A + B = C, 3 Knobs.
TYPE_350
          Equation type: X/A - B = C, 3 Knobs.
TYPE_400
          Equation type: Ax + B = C, 3 Knobs.
TYPE_450
          Equation type: Ax - B = C, 3 Knobs.
TYPE_500
          Equation type: A(x + B) = C, 3 Knobs.
TYPE_515
          Equation type: A(x + B) + C = D, 4 Knobs.
TYPE_530
          Equation type: A(x + B) - C = D, 4 Knobs.
TYPE_550
          Equation type: A(x - B) = C, 3 Knobs.
TYPE_565
          Equation type: A(x - B) + C = D, 4 Knobs.
TYPE_580
          Equation type: A(x - B) - C = D, 4 Knobs.
TYPE_600
          Equation type: (Ax + B)/C = D, 3 Knobs.
TYPE_650
          Equation type: (Ax - B)/C = D, 3 Knobs.
TYPE_700
          Equation type: (Ax + B)/C + D = E, 4 Knobs.
TYPE_725
          Equation type: (Ax + B)/C - D = E, 4 Knobs.
TYPE_750
          Equation type: (Ax - B)/C + D = E, 4 Knobs.
TYPE_775
          Equation type: (Ax - B)/C - D = E, 4 Knobs.
TYPE_ERROR
          TYPE_ constant used as an error marker, '-1' Knobs.
 
Field Summary
static int LATEX
          Constant used for RAW LaTeX format.
static int MATHML
          Constant used for MathML format.
static int OPEN_OFFICE
          Constant used for OpenOffice format.
static int STANDARD
          Constant used for Standard format.
 
Method Summary
abstract  boolean bird()
          Blind Inequality Reverse Detection.
 java.lang.String getFormat(int pKey, java.lang.String pRelation)
          This method is used generically to fetch any intrinsic format.
 int numKnobs()
          Query a particular TYPE_ as to the number of Knobs it requires.
abstract  java.lang.String preformat(int[] pVals)
          Preformat the data from the equation type.
 java.lang.String preformat(java.lang.String pKnobs)
          Preformat the data from the equation type.
abstract  java.lang.String solveFor(int... pPlaceHolders)
          This method allows an Equation enum member to be used to create an equation or inequality that does NOT solve nicely.
 java.lang.String[] tokens(int[] pVals)
          This method returns the preformat data as a String array.
 java.lang.String[] tokens(java.lang.String pKnobs)
          Preformat to tokens but with Knobs for data.
static MEquation.Equation valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static MEquation.Equation[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

TYPE_ERROR

public static final MEquation.Equation TYPE_ERROR
TYPE_ constant used as an error marker, '-1' Knobs. It is also used to debug several internal methods.


TYPE_100

public static final MEquation.Equation TYPE_100
Equation type: X + A = B, 2 Knobs. X = K0, A = K1, B = X + A.


TYPE_150

public static final MEquation.Equation TYPE_150
Equation type: X - A = B, 2 Knobs. X = K0, A = K1, B = X - A.


TYPE_200

public static final MEquation.Equation TYPE_200
Equation type: Ax = B, 2 Knobs. X = K0, A = K1, B = A * X.


TYPE_300

public static final MEquation.Equation TYPE_300
Equation type: X/A = B, 2 Knobs. A = K0 (forced nonzero), B = K1, x = A * B.


TYPE_325

public static final MEquation.Equation TYPE_325
Equation type: X/A + B = C, 3 Knobs. A = K0 (not [-1,1]), B = K1, C = K2, X = A(C - B).


TYPE_350

public static final MEquation.Equation TYPE_350
Equation type: X/A - B = C, 3 Knobs. A = K0 (not [-1,1]), B = K1, C = K2, X = A(C + B).


TYPE_400

public static final MEquation.Equation TYPE_400
Equation type: Ax + B = C, 3 Knobs. x = K0, A = K1, B = K2, C = A*x + B.


TYPE_450

public static final MEquation.Equation TYPE_450
Equation type: Ax - B = C, 3 Knobs. x = K0, A = K1, B = K2, C = A*x - B.


TYPE_500

public static final MEquation.Equation TYPE_500
Equation type: A(x + B) = C, 3 Knobs. x = K0, A = K1, B = K2, C = A*(x + B).


TYPE_515

public static final MEquation.Equation TYPE_515
Equation type: A(x + B) + C = D, 4 Knobs. x = K0, A = K1, B = K2, C = K3, D = A(x + B) + C.


TYPE_530

public static final MEquation.Equation TYPE_530
Equation type: A(x + B) - C = D, 4 Knobs. x = K0, A = K1, B = K2, C = K3, D = A(x + B) - C.


TYPE_550

public static final MEquation.Equation TYPE_550
Equation type: A(x - B) = C, 3 Knobs. x = K0, A = K1, B = K2, C = A*(x - B).


TYPE_565

public static final MEquation.Equation TYPE_565
Equation type: A(x - B) + C = D, 4 Knobs. x = K0, A = K1, B = K2, C = K3, D = A(x - B) + C.


TYPE_580

public static final MEquation.Equation TYPE_580
Equation type: A(x - B) - C = D, 4 Knobs. x = K0, A = K1, B = K2, C = K3, D = A(x - B) - C.


TYPE_600

public static final MEquation.Equation TYPE_600
Equation type: (Ax + B)/C = D, 3 Knobs. A = K0 (not in [-1,1]), x = K1, C = K2 (not in [-1,1]), D = (Ax + B)/C, B in {1,2...} such that C divides Ax + B


TYPE_650

public static final MEquation.Equation TYPE_650
Equation type: (Ax - B)/C = D, 3 Knobs. A = K0 (not in [-1,1]), x = K1, C = K2 (not in [-1,1]), D = (Ax + B)/C, B in {1,2...} such that C divides Ax - B


TYPE_700

public static final MEquation.Equation TYPE_700
Equation type: (Ax + B)/C + D = E, 4 Knobs. x = K0, A = K1 (not [-1,1]), C = K2 (not [-1,1]), D = K3, E = (Ax + B)/C + D. B calculated such that C|(Ax + B).


TYPE_725

public static final MEquation.Equation TYPE_725
Equation type: (Ax + B)/C - D = E, 4 Knobs. x = K0, A = K1 (not [-1,1]), C = K2 (not [-1,1]), D = K3, E = (Ax + B)/C - D. B calculated such that C|(Ax + B).


TYPE_750

public static final MEquation.Equation TYPE_750
Equation type: (Ax - B)/C + D = E, 4 Knobs. x = K0, A = K1 (not [-1,1]), C = K2 (not [-1,1]), D = K3, E = (Ax + B)/C + D. B calculated such that C|(Ax + B).


TYPE_775

public static final MEquation.Equation TYPE_775
Equation type: (Ax - B)/C - D = E, 4 Knobs. x = K0, A = K1 (not [-1,1]), C = K2 (not [-1,1]), D = K3, E = (Ax + B)/C + D. B calculated such that C|(Ax + B).

Field Detail

STANDARD

public static final int STANDARD
Constant used for Standard format.

See Also:
Constant Field Values

OPEN_OFFICE

public static final int OPEN_OFFICE
Constant used for OpenOffice format.

See Also:
Constant Field Values

MATHML

public static final int MATHML
Constant used for MathML format. The elements are not enclosed in <mrow> or <math> tags.

See Also:
Constant Field Values

LATEX

public static final int LATEX
Constant used for RAW LaTeX format. This is just the equation and no enclosing formatting.

See Also:
Constant Field Values
Method Detail

values

public static MEquation.Equation[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (MEquation.Equation c : MEquation.Equation.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static MEquation.Equation valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
java.lang.NullPointerException - if the argument is null

numKnobs

public int numKnobs()
Query a particular TYPE_ as to the number of Knobs it requires.


getFormat

public java.lang.String getFormat(int pKey,
                                  java.lang.String pRelation)
This method is used generically to fetch any intrinsic format. If no key matches, STANDARD is returned. Although this class and the enum types imply equations, inequalities can also be returned. The relation parameter determines what relation will actually be returned. If null or empty the default is equality.

Parameters:
pKey - One of the format constants listed above.
pRelation - The relation (equality or inequality) type to return. Defaults to '='.

preformat

public abstract java.lang.String preformat(int[] pVals)
Preformat the data from the equation type. This method takes an int[] array and feeds it directly into the computations. IMPORTANT NOTE: If the array supplied is not long enough it is padded to the appropriate length with zero values.

Parameters:
pVals - An array containing raw data for the computations.

preformat

public java.lang.String preformat(java.lang.String pKnobs)

Preformat the data from the equation type. The return value is in the form 'Answer:A B C...:BIRD' up to the number of placeholders in the equation type. BIRD will be 'true' or 'false' and indicates whether or not an inequality should be reversed.

Parameters:
pKnobs - A String containing the requisite number of Knobs.
Returns:
A pre-formatted String containing the answer to the equation and the placeholder values, in order.

tokens

public java.lang.String[] tokens(int[] pVals)

This method returns the preformat data as a String array. Element [0] is the answer and the placeholders increase in order from Element [1]. Inequality reverse detection IS set with this method and the last element in the array (after all placeholders!) is either 'true' or 'false', depending on the call to bird()

Parameters:
pVals - An array containing raw data for the equation type.

tokens

public java.lang.String[] tokens(java.lang.String pKnobs)
Preformat to tokens but with Knobs for data. Inequality reverse detection IS set with this method.

Parameters:
pKnobs - A String containing the requisite number of Knobs.
Returns:
The preformat data as a String[] array: {Answer, A, B, ... , BIRD}.

bird

public abstract boolean bird()

Blind Inequality Reverse Detection. This method indicates whether or not an inequality should be reversed based on the numbers used to build it. It is 'blind' because it makes no assumptions about whether or not it actually IS building an inequality, it always presumes so.

NOTE: This method is valid immediately after a call to preformat() or tokens() ONLY!! Any other time its value is meaningless.


solveFor

public abstract java.lang.String solveFor(int... pPlaceHolders)

This method allows an Equation enum member to be used to create an equation or inequality that does NOT solve nicely. The arguments are the placeholders, in order. The return value is String to allow fractions to be presented (typewriter format) and to allow inequality reversal to be indicated. If the values indicate that an inequality should be reversed the String '(REV)' appears at the end of the return value.

Parameters:
pPlaceHolders - The placeholders required for the Equation desired.