infix2postfix
Class Infix2PostfixClient

java.lang.Object
  extended byinfix2postfix.Infix2PostfixClient
Direct Known Subclasses:
BooleanClient, MathClient

public abstract class Infix2PostfixClient
extends java.lang.Object

This class represents generic client interface for,

 1. Infix to Postfix converter
 2. Postfix evaluator
 
functionality. It hides details of invoking other components like Infix2PostfixConverter and PostfixEvaluator and provides understandable interface for adding operators/variables etc to the expression specification.

Author:
Maulin H. Vasavada

Field Summary
private  Infix2PostfixConverter i2pc
          Infix to postfix converter object reference
protected  OperandManager operandManager
          Operand Manager reference
private  PostfixEvaluator postfixEval
          Postfix evaluator object reference
 
Constructor Summary
protected Infix2PostfixClient()
           
  Infix2PostfixClient(Infix2PostfixConverter i2pc, PostfixEvaluator postfixEval)
          Constructor with parameters.
 
Method Summary
protected abstract  void addDefaultOperators()
          Adds list of default operators available for the expression evaluation.
 void addOperator(Operator operator)
          Adds an operator in the list of "valid operators".
 java.lang.Object evaluate(java.lang.String expression)
          Evaluates the given infix expression.
protected static VariableHolder getDefaultVariableHolder()
          Returns default "variable holder".
 OperandManager getOperandManager()
          Returns operand manager associated with this client.
 java.lang.Object getVariableValue(java.lang.Object variable)
          Returns value of the given variable.
 void removeOperator(java.lang.String symbol)
          Removes operator from the "valid operators" list.
 void setVariable(java.lang.Object variable, java.lang.Object value)
          Sets variable and its value to the "valid variables" definition/list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

i2pc

private Infix2PostfixConverter i2pc
Infix to postfix converter object reference


postfixEval

private PostfixEvaluator postfixEval
Postfix evaluator object reference


operandManager

protected OperandManager operandManager
Operand Manager reference

Constructor Detail

Infix2PostfixClient

protected Infix2PostfixClient()

Infix2PostfixClient

public Infix2PostfixClient(Infix2PostfixConverter i2pc,
                           PostfixEvaluator postfixEval)
Constructor with parameters.

See Also:
Infix2PostfixConverter, PostfixEvaluator
Method Detail

getDefaultVariableHolder

protected static VariableHolder getDefaultVariableHolder()
Returns default "variable holder".


addDefaultOperators

protected abstract void addDefaultOperators()
Adds list of default operators available for the expression evaluation.

See Also:
MathClient.addDefaultOperators(), BooleanClient.addDefaultOperators()

evaluate

public java.lang.Object evaluate(java.lang.String expression)
                          throws InvalidSymbolTypeException,
                                 InvalidOperatorException,
                                 InvalidOperandException,
                                 InvalidExpressionFormatException,
                                 InvalidPostfixExpressionException
Evaluates the given infix expression. Evaluation is done in two steps,
 1. Expression is converted into the equivalent postfix noation
 2. That postfix notation is evaluated
 

Returns:
Object Result of the expression evaluation
Throws:
InvalidSymbolTypeException
InvalidOperatorException
InvalidOperandException
InvalidExpressionFormatException
InvalidPostfixExpressionException

addOperator

public void addOperator(Operator operator)
Adds an operator in the list of "valid operators".

See Also:
Operator

removeOperator

public void removeOperator(java.lang.String symbol)
Removes operator from the "valid operators" list.


setVariable

public void setVariable(java.lang.Object variable,
                        java.lang.Object value)
                 throws InvalidVariableSpecificationException
Sets variable and its value to the "valid variables" definition/list.
This definition/list is managed by VariableHolder object.
Value of the variable must comply to the "validity criteria" for operands. This criteria is defined by OperandManager's isOperand() method.

Throws:
InvalidVariableSpecificationException - If the "validity criteria" defined by the associated OperandManager fails for this variable
See Also:
VariableHolder, OperandManager.isOperand(Object)

getVariableValue

public java.lang.Object getVariableValue(java.lang.Object variable)
Returns value of the given variable.


getOperandManager

public OperandManager getOperandManager()
Returns operand manager associated with this client.

Returns:
OperandManager Operand manager associated with this client