CogPar
A versatile parser for mathematical expressions.
 All Classes Functions Variables
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | List of all members
uk.co.cogitolearning.cogpar.FunctionExpressionNode Class Reference

An ExpressionNode that handles mathematical functions. More...

Inheritance diagram for uk.co.cogitolearning.cogpar.FunctionExpressionNode:
Inheritance graph
[legend]
Collaboration diagram for uk.co.cogitolearning.cogpar.FunctionExpressionNode:
Collaboration graph
[legend]

Public Member Functions

 FunctionExpressionNode (int function, ExpressionNode argument)
 Construct a function by id and argument.
int getType ()
 Returns the type of the node, in this case ExpressionNode.FUNCTION_NODE.
double getValue ()
 Returns the value of the sub-expression that is rooted at this node.
void accept (ExpressionNodeVisitor visitor)
 Implementation of the visitor design pattern.

Static Public Member Functions

static int stringToFunction (String str)
 Converts a string to a function id.
static String getAllFunctions ()
 Returns a string with all the function names concatenated by a | symbol.

Static Public Attributes

static final int SIN = 1
 function id for the sin function
static final int COS = 2
 function id for the cos function
static final int TAN = 3
 function id for the tan function
static final int ASIN = 4
 function id for the asin function
static final int ACOS = 5
 function id for the acos function
static final int ATAN = 6
 function id for the atan function
static final int SQRT = 7
 function id for the sqrt function
static final int EXP = 8
 function id for the exp function
static final int LN = 9
 function id for the ln function
static final int LOG = 10
 function id for the log function
static final int LOG2 = 11
 function id for the log2 function
- Static Public Attributes inherited from uk.co.cogitolearning.cogpar.ExpressionNode
static final int VARIABLE_NODE = 1
 Node id for variable nodes.
static final int CONSTANT_NODE = 2
 Node id for constant nodes.
static final int ADDITION_NODE = 3
 Node id for addition nodes.
static final int MULTIPLICATION_NODE = 4
 Node id for multiplication nodes.
static final int EXPONENTIATION_NODE = 5
 Node id for exponentiation nodes.
static final int FUNCTION_NODE = 6
 Node id for function nodes.

Private Attributes

int function
 the id of the function to apply to the argument
ExpressionNode argument
 the argument of the function

Detailed Description

An ExpressionNode that handles mathematical functions.

Some pre-defined functions are handled, others can easily be added.

Definition at line 32 of file FunctionExpressionNode.java.

Constructor & Destructor Documentation

uk.co.cogitolearning.cogpar.FunctionExpressionNode.FunctionExpressionNode ( int  function,
ExpressionNode  argument 
)

Construct a function by id and argument.

Parameters
functionthe id of the function to apply
argumentthe argument of the function

Definition at line 74 of file FunctionExpressionNode.java.

Member Function Documentation

void uk.co.cogitolearning.cogpar.FunctionExpressionNode.accept ( ExpressionNodeVisitor  visitor)

Implementation of the visitor design pattern.

Calls visit on the visitor and then passes the visitor on to the accept method of the argument.

Parameters
visitorthe visitor

Implements uk.co.cogitolearning.cogpar.ExpressionNode.

Definition at line 188 of file FunctionExpressionNode.java.

static String uk.co.cogitolearning.cogpar.FunctionExpressionNode.getAllFunctions ( )
static

Returns a string with all the function names concatenated by a | symbol.

This string is used in Tokenizer.createExpressionTokenizer to create a regular expression for recognizing function names.

Returns
a string containing all the function names

Definition at line 137 of file FunctionExpressionNode.java.

double uk.co.cogitolearning.cogpar.FunctionExpressionNode.getValue ( )

Returns the value of the sub-expression that is rooted at this node.

The argument is evaluated and then the function is applied to the resulting value.

Implements uk.co.cogitolearning.cogpar.ExpressionNode.

Definition at line 148 of file FunctionExpressionNode.java.

static int uk.co.cogitolearning.cogpar.FunctionExpressionNode.stringToFunction ( String  str)
static

Converts a string to a function id.

If the function is not found this method throws an error.

Parameters
strthe name of the function
Returns
the id of the function

Definition at line 98 of file FunctionExpressionNode.java.


The documentation for this class was generated from the following file: