jmathlib.core.tokens
Class Expression

java.lang.Object
  extended by jmathlib.core.interpreter.RootObject
      extended by jmathlib.core.tokens.Token
          extended by jmathlib.core.tokens.OperandToken
              extended by jmathlib.core.tokens.Expression
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ErrorCodes, TokenConstants

public class Expression
extends OperandToken

Class implementing a tree where each node has a variable no of children

See Also:
Serialized Form

Field Summary
 
Fields inherited from class jmathlib.core.tokens.Token
priority
 
Fields inherited from interface jmathlib.core.constants.TokenConstants
ADDSUB_PRIORITY, AND_PRIORITY, ANDAND_PRIORITY, ASSIGN_PRIORITY, BRACKET_PRIORITY, COMPARE_PRIORITY, CONCAT, MATRIX, MULDIV_PRIORITY, OR_PRIORITY, OROR_PRIORITY, PARAMETER, POWER_PRIORITY, RELATION_PRIORITY, SINGLE, ttDelimiter, ttNotSet, ttOperand, ttOperator
 
Fields inherited from interface jmathlib.core.constants.ErrorCodes
ERR_BRACKET_OPEN, ERR_BRACKET_ORDER, ERR_FUNCTION_NOT_FOUND, ERR_FUNCTION_NOT_IMPLEMENTED, ERR_INSUFFICIENT_PARAMETERS, ERR_INVALID_PARAMETER, ERR_LVALUE_REQUIRED, ERR_MATRIX_SINGULAR, ERR_NOT_SQUARE_MATRIX, ERR_OPNOTSUPPORTED, ERR_TOO_MANY_PARAMETERS, ERR_USER_ERROR, ERR_VARIABLE_NOTDEFINED, OK, OK_FUNCTION_PROCESS
 
Constructor Summary
Expression()
          Default constructor - creates an expression with a null operator and no operands
Expression(OperatorToken _data)
          Creates an expression with no operands
Expression(OperatorToken _data, OperandToken operand)
          Creates an expression with one operand
Expression(OperatorToken _data, OperandToken[] _children, int _noChildren)
          Creates an expression with an array of operands
Expression(OperatorToken _data, OperandToken left, OperandToken right)
          Creates an expression with two operands
Expression(OperatorToken _data, OperandToken op1, OperandToken op2, OperandToken op3)
          Creates an expression with three operands
 
Method Summary
 OperandToken evaluate(Token[] ops)
          evaluate the data item held within this node
 OperandToken getChild(int childNo)
          Get the a child with a specific index
 int getChildNo()
           
 java.util.Enumeration getChildren()
          function to access all children of a node within the expression tree
 OperandToken getCurrentChild()
           
 OperatorToken getData()
          retrieves the data object
 OperandToken getLeft()
          Get the first child of this node
 int getNumberOfChildren()
           
 OperandToken getRight()
          Get the last child of this node
 void insert(Token _data)
          insert a child node on this Expression if _data is a Expression then it just gets added to the current node Otherwise a new node is created and this is added to the current node
 boolean isLeaf()
          checks if this is a leaf node of the expression tree
 boolean isNumeric()
          Checks if this operand is a numeric value
 void setChild(int childNo, OperandToken child)
          set the child with a specific index
 void setData(OperatorToken _data)
          Sets the operator of the expression
 java.lang.String toString()
          Converts the expression to a string
 
Methods inherited from class jmathlib.core.tokens.OperandToken
add, asArray, Children, ctranspose, derivative, divide, expand, factorial, integral, isNull, leftDivide, mpower, mPower, multiply, negate, power, scalarDivide, scalarLeftDivide, scalarMultiply, simplify, subst, subtract, transpose
 
Methods inherited from class jmathlib.core.tokens.Token
isDisplayResult, setDisplayResult, toMathMlString
 
Methods inherited from class jmathlib.core.interpreter.RootObject
clone, getContextList, getDebug, getFunctionManager, getGlobalVariables, getGraphicsManager, getInterpreter, getPluginsManager, getVariable, getVariables, getWorkingDirectory, setConstants, setDebug, setWorkingDirectory, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Expression

public Expression()
Default constructor - creates an expression with a null operator and no operands


Expression

public Expression(OperatorToken _data)
Creates an expression with no operands

Parameters:
_data - = the expressions operator

Expression

public Expression(OperatorToken _data,
                  OperandToken operand)
Creates an expression with one operand

Parameters:
_data - = the expressions operator
operand - = the expressions operand

Expression

public Expression(OperatorToken _data,
                  OperandToken left,
                  OperandToken right)
Creates an expression with two operands

Parameters:
_data - = the expressions operator
left - = the left hand operand
right - = the right hand operand

Expression

public Expression(OperatorToken _data,
                  OperandToken op1,
                  OperandToken op2,
                  OperandToken op3)
Creates an expression with three operands

Parameters:
_data - = the expressions operator
first - = the left hand operand
second - = the middle operand
third - = the right hand operand

Expression

public Expression(OperatorToken _data,
                  OperandToken[] _children,
                  int _noChildren)
Creates an expression with an array of operands

Parameters:
data - = the expressions operator
operands - = and array of operands
_noChildren - = the number of operands
Method Detail

getData

public OperatorToken getData()
retrieves the data object

Returns:
the operator assigned to the expression

getNumberOfChildren

public int getNumberOfChildren()
Returns:
the number of children

setData

public void setData(OperatorToken _data)
Sets the operator of the expression

Parameters:
_data - = the expressions operator

getChild

public OperandToken getChild(int childNo)
Get the a child with a specific index

Parameters:
childNo - = the index of the operand
Returns:
the specified operand

setChild

public void setChild(int childNo,
                     OperandToken child)
set the child with a specific index

Parameters:
childNo - = the index of the child
child - = the value to set it to

getLeft

public OperandToken getLeft()
Get the first child of this node

Returns:
the first operand

getRight

public OperandToken getRight()
Get the last child of this node

Returns:
the last operand

insert

public void insert(Token _data)
insert a child node on this Expression if _data is a Expression then it just gets added to the current node Otherwise a new node is created and this is added to the current node

Parameters:
_data - = the operand to add

evaluate

public OperandToken evaluate(Token[] ops)
evaluate the data item held within this node

Specified by:
evaluate in class Token
Parameters:
ops - = the expressions operands
Returns:
the result of the expression as an OperandToken

toString

public java.lang.String toString()
Converts the expression to a string

Specified by:
toString in class Token
Returns:
string representation of expression

isNumeric

public boolean isNumeric()
Checks if this operand is a numeric value

Overrides:
isNumeric in class OperandToken
Returns:
true if this is a number, false if it's an algebraic expression

getChildNo

public int getChildNo()
Returns:
the index number of the current child expression

getCurrentChild

public OperandToken getCurrentChild()
Returns:
the expression being executed

isLeaf

public boolean isLeaf()
checks if this is a leaf node of the expression tree

Overrides:
isLeaf in class OperandToken
Returns:
false if this expression has any children

getChildren

public java.util.Enumeration getChildren()
function to access all children of a node within the expression tree

Returns:
all the nodes children as a enumeration