gov.sns.tools.formula
Class OperatorFactory

java.lang.Object
  |
  +--gov.sns.tools.formula.OperatorFactory

public class OperatorFactory
extends java.lang.Object

OperatorFactory provides all of the operators that the formula interpreter uses. This set includes the standard arithmetic operators, logical operators along with an operator that wraps function calls and an operator that pushes Value instances onto the value stack. OperatorFactory is a factory class and should not be instantiated. The operators are fetched as the formula is being parsed during formula compilation. During formula evaluation, each operator executes its operate method.

See Also:
Operator, UnaryOperator, BinaryOperator, ValueOperator, FunctionOperator, FormulaGrammarBase.compile(java.lang.String), FormulaGrammarBase#evaluate

Constructor Summary
protected OperatorFactory()
          Creates a new instance of OperatorFactory.
 
Method Summary
static gov.sns.tools.formula.Operator additionOperator()
          Get an operator that implements addition.
static gov.sns.tools.formula.Operator andOperator()
          Get an operator that implements the logical and operation.
static gov.sns.tools.formula.Operator divisionOperator()
          Get an operator that implements division.
static gov.sns.tools.formula.Operator functionOperator(Function function, int numArgs)
          Get an operator that wraps a function operation.
static gov.sns.tools.formula.Operator multiplicationOperator()
          Get an operator that implements multiplication.
static gov.sns.tools.formula.Operator orOperator()
          Get an operator that implements the logical or operation.
static gov.sns.tools.formula.Operator powerOperator()
          Get an operator that implements the power operator, e.g.
static gov.sns.tools.formula.Operator subtractionOperator()
          Get an operator that implements subtraction.
static gov.sns.tools.formula.Operator unaryMinusOperator()
          Get an operator that implements the unary minus operation.
static gov.sns.tools.formula.Operator valueOperator(gov.sns.tools.formula.Value value)
          Get an operator that can push a value onto the value stack.
static gov.sns.tools.formula.Operator xorOperator()
          Get an operator that implements the logical xor operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OperatorFactory

protected OperatorFactory()
Creates a new instance of OperatorFactory. Never instantiate the factory.

Method Detail

unaryMinusOperator

public static gov.sns.tools.formula.Operator unaryMinusOperator()
Get an operator that implements the unary minus operation.


additionOperator

public static gov.sns.tools.formula.Operator additionOperator()
Get an operator that implements addition.


subtractionOperator

public static gov.sns.tools.formula.Operator subtractionOperator()
Get an operator that implements subtraction.


multiplicationOperator

public static gov.sns.tools.formula.Operator multiplicationOperator()
Get an operator that implements multiplication.


divisionOperator

public static gov.sns.tools.formula.Operator divisionOperator()
Get an operator that implements division.


powerOperator

public static gov.sns.tools.formula.Operator powerOperator()
Get an operator that implements the power operator, e.g. x**y reading "x to the y power".


andOperator

public static gov.sns.tools.formula.Operator andOperator()
Get an operator that implements the logical and operation.


orOperator

public static gov.sns.tools.formula.Operator orOperator()
Get an operator that implements the logical or operation.


xorOperator

public static gov.sns.tools.formula.Operator xorOperator()
Get an operator that implements the logical xor operation.


functionOperator

public static gov.sns.tools.formula.Operator functionOperator(Function function,
                                                              int numArgs)
Get an operator that wraps a function operation.

Parameters:
function - The function to wrap
numArgs - Number of arguments to provide to the function
Returns:
An operator that wraps the specified function.

valueOperator

public static gov.sns.tools.formula.Operator valueOperator(gov.sns.tools.formula.Value value)
Get an operator that can push a value onto the value stack. During formula parsing, constants and variables are encountered and this operator is pushed onto the operator stack at that time. During formula evaluation, when this operator is executed it pushes its value onto the value stack.

Parameters:
value - The value to push onto the stack.
Returns:
An operator that can push the value onto the stack.