infix2postfix
Class OperandManager

java.lang.Object
  extended byinfix2postfix.OperandManager
Direct Known Subclasses:
BooleanOperandManager, NumericOperandManager

public abstract class OperandManager
extends java.lang.Object

This class acts as a "validity criteria" for operands. It also provides functionality to return appropriate type of operands after parsing the valid operands.

Author:
Maulin H. Vasavada

Field Summary
protected  VariableHolder varHolder
          Variable holder reference
 
Constructor Summary
OperandManager()
          No-arg constructor.
OperandManager(VariableHolder varHolder)
          Constructor that accepts custom variable holder object.
 
Method Summary
protected static VariableHolder getDefaultVariableHolder()
          Defines default "variable holder" object.
 VariableHolder getVariableHolder()
          Returns associated variable holder object.
 java.lang.Object getVariableValue(java.lang.Object variable)
          Returns the value of a given variable.
abstract  boolean isOperand(java.lang.Object symbol)
          Defines the validity criteria for operands accepted by this operand manager.
 boolean isVariable(java.lang.Object symbol)
          Verifies if the given symbol is a "valid variable" according to the associated "variable holder" object.
 void setVariable(java.lang.Object variable, java.lang.Object value)
          Sets the variable and its value in the "valid variable" list.
 void setVariableHolder(VariableHolder varHolder)
          Sets the "variable holder" object for this operand manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

varHolder

protected VariableHolder varHolder
Variable holder reference

Constructor Detail

OperandManager

public OperandManager()
No-arg constructor. This uses the default variable holder defined by method getDefaultVariableHolder().

See Also:
VariableHolder, getDefaultVariableHolder()

OperandManager

public OperandManager(VariableHolder varHolder)
Constructor that accepts custom variable holder object.

See Also:
VariableHolder, getDefaultVariableHolder()
Method Detail

getVariableHolder

public VariableHolder getVariableHolder()
Returns associated variable holder object.

See Also:
VariableHolder

isVariable

public boolean isVariable(java.lang.Object symbol)
Verifies if the given symbol is a "valid variable" according to the associated "variable holder" object.

Returns:
boolean true if the given symbol is a valid variable;false otherwise
See Also:
VariableHolder

setVariableHolder

public void setVariableHolder(VariableHolder varHolder)
Sets the "variable holder" object for this operand manager.

See Also:
VariableHolder

setVariable

public void setVariable(java.lang.Object variable,
                        java.lang.Object value)
Sets the variable and its value in the "valid variable" list. If the variable is already there it will overwrite the older value otherwise it will add the new variable entry in the list.
The value of the variable must satisfy "validity criteria" defined for this operand manager (look at method isOperand()).

Parameters:
variable - Variable to be added in the list
value - Value of the variable being added
See Also:
isOperand(Object)

getVariableValue

public java.lang.Object getVariableValue(java.lang.Object variable)
Returns the value of a given variable. If no variable found then null is return.


getDefaultVariableHolder

protected static VariableHolder getDefaultVariableHolder()
Defines default "variable holder" object. Default variable holder uses java.util.Hashtable to hold variables and their values.

See Also:
VariableHolder

isOperand

public abstract boolean isOperand(java.lang.Object symbol)
Defines the validity criteria for operands accepted by this operand manager. A "valid variable" is also considered to be an operand.

Returns:
boolean true if the given symbol satisfies validity criteria for operands defined by this operand manager;false otherwise