hussam.math.operations.parser
Class HussamExpressionReader

java.lang.Object
extended by hussam.math.operations.parser.ExpressionReader
extended by hussam.math.operations.parser.HussamExpressionReader
All Implemented Interfaces:
OperationReader

public class HussamExpressionReader
extends ExpressionReader

This class is Version 6 of all previously created readers. I need people to test this class with different expressions. Extra notes using this class: The default reader creates cariables as needed. you can change the implemetation to throw an UnknownExpressionArgumentException if it encountered a new variable while reading! Of course, the default implementation is set to create variables when necessary.

Since:
Version 3
Author:
Hussam Almulhim حسام الملحم
See Also:
Operation

Constructor Summary
HussamExpressionReader()
          Creates a new ExpressionReader.
HussamExpressionReader(OperationsParser parser)
          Creates a new ExpressionReader given this spicific parser.
HussamExpressionReader(OperationsParser parser, OperatorSource source)
          Creates a new ExpressionReader given this spicific operator source and parser.
HussamExpressionReader(OperationsParser parser, OperatorSource source, boolean autoCreateVariables, boolean autoOptimize)
          Creates a new ExpressionReader given this spicific operator source and parser and the auto create variable flag.
HussamExpressionReader(OperatorSource source)
          Creates a new ExpressionReader given this spicific operator source.
 
Method Summary
 java.util.List<Operation>getExpressionOperations()
          This will return a list of all read operations.
 java.util.List<java.lang.String>getExpressionPartitioned()
          This will return a list of all symbols, numbers, words(variables or function names) and Baraks.
 OperatorSourceImplgetOperatorSource()
          gets the OperatorSource for all expressions read!
static voidmain(java.lang.String[] args)
          A test method.
 OperationGroupreadOperation(java.lang.String operationString)
          Reads an expression
 
Methods inherited from class hussam.math.operations.parser.ExpressionReader
getInstance, getInstance, getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HussamExpressionReader

public HussamExpressionReader()
Creates a new ExpressionReader. The operations are automatically optimized, and variables are created automatically.


HussamExpressionReader

public HussamExpressionReader(OperationsParser parser)
Creates a new ExpressionReader given this spicific parser. The operations are automatically optimized, and variables are created automatically.

Parameters:
parser - the parser used to parse expressions.

HussamExpressionReader

public HussamExpressionReader(OperatorSource source)
Creates a new ExpressionReader given this spicific operator source. The operations are automatically optimized, and variables are created automatically.

Parameters:
source - the source used to evaluate expressions.

HussamExpressionReader

public HussamExpressionReader(OperationsParser parser,
OperatorSource source)
Creates a new ExpressionReader given this spicific operator source and parser. The operations are automatically optimized, and variables are created automatically.

Parameters:
parser - The parser used, can be null.
source - The source used to find resources. can be null.

HussamExpressionReader

public HussamExpressionReader(OperationsParser parser,
OperatorSource source,
                              boolean autoCreateVariables,
                              boolean autoOptimize)
Creates a new ExpressionReader given this spicific operator source and parser and the auto create variable flag.

Parameters:
autoOptimize - if true, returns an optimized operation.
parser - the parser to be used. can be null.
source - the operatorsource, can be null.
autoCreateVariables - if true, indicates that the parser should create variables whenever needed. If false, the reader will not create variables, variables should be added by the user.
Method Detail

getOperatorSource

public OperatorSourceImpl getOperatorSource()
Description copied from interface: OperationReader
gets the OperatorSource for all expressions read!

Returns:
the OperatorSource for all expressions read.

getExpressionOperations

public java.util.List<Operation> getExpressionOperations()
This will return a list of all read operations. For example: if you read 3+5, you will get a list containing:
[ConstantNumber, Operand, ConstantNumber]
you will notice that (,) commas are treated as null;

Returns:
a list of operations.

getExpressionPartitioned

public java.util.List<java.lang.String> getExpressionPartitioned()
This will return a list of all symbols, numbers, words(variables or function names) and Baraks. This list is collected from all expressions read.

Returns:
a list of String

readOperation

public OperationGroup readOperation(java.lang.String operationString)
                             throws MathException
Description copied from interface: OperationReader
Reads an expression

Parameters:
operationString - the expression to be evaluated.
Returns:
the Operation from which you can call result() to get the result of the expression.
Throws:
MathException - Thrown if the expression has a problemSyntaxErrorException MathLogicException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
A test method.

Throws:
java.lang.Exception