uk.org.ogsadai.expression.arithmetic
Class BinaryExpression

java.lang.Object
  extended by uk.org.ogsadai.expression.arithmetic.BinaryExpression
All Implemented Interfaces:
ArithmeticExpression
Direct Known Subclasses:
Div, Minus, Mult, Plus

public abstract class BinaryExpression
extends java.lang.Object
implements ArithmeticExpression

A binary numeric operator in an arithmetic expression.

Author:
The OGSA-DAI Project Team.

Field Summary
protected  int mContextType
          Context dependent type.
protected  Evaluator mEval
          Evaluator for this operator.
protected  ArithmeticExpression mLeftChild
          left child expression.
protected  ColumnMetadata mOriginalType
          Type of this table column.
protected  ArithmeticExpression mRightChild
          right child expression.
protected  ColumnMetadata mType
          Return type.
 
Constructor Summary
BinaryExpression(ArithmeticExpression child1, ArithmeticExpression child2)
          Constructs a new binary numeric operator with the given children.
 
Method Summary
 void configure(TupleMetadata metadata)
          Configures the expression with the metadata.
 void configure(TupleMetadata metadata, java.util.Set<Attribute> correlatedAttributes)
          Configures the expression with the metadata.
 void evaluate(Tuple tuple)
          Evaluates the arithmetic expression on the given input tuple.
 ArithmeticExpression[] getChildren()
          Returns the children of this arithmetic expression.
 ArithmeticExpression getLeftExpression()
          Gets left operand expression.
 ColumnMetadata getMetadata()
          Get the result type that is returned when evaluating this expression with tuples of the given type.
 java.lang.Object getResult()
          Returns the result of the evaluation.
 ArithmeticExpression getRightExpression()
          Gets right operand expression.
abstract  java.lang.Number localEvaluate(java.lang.Number lhs, java.lang.Number rhs)
          Performs operation specific evaluation.
protected abstract  void printOperator(java.lang.StringBuffer buf)
          Append the operator name (e.g.
 void resetType()
          Reset type to original.
 void setContextType(int type)
          Set context type for an expression.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface uk.org.ogsadai.expression.arithmetic.ArithmeticExpression
accept
 

Field Detail

mEval

protected Evaluator mEval
Evaluator for this operator.


mLeftChild

protected ArithmeticExpression mLeftChild
left child expression.


mRightChild

protected ArithmeticExpression mRightChild
right child expression.


mType

protected ColumnMetadata mType
Return type.


mOriginalType

protected ColumnMetadata mOriginalType
Type of this table column.


mContextType

protected int mContextType
Context dependent type.

Constructor Detail

BinaryExpression

public BinaryExpression(ArithmeticExpression child1,
                        ArithmeticExpression child2)
Constructs a new binary numeric operator with the given children.

Parameters:
child1 - left hand child expression
child2 - right hand child expression
Method Detail

setContextType

public void setContextType(int type)
Set context type for an expression.

Specified by:
setContextType in interface ArithmeticExpression
Parameters:
type - context tuple type

resetType

public void resetType()
Reset type to original.

Specified by:
resetType in interface ArithmeticExpression

localEvaluate

public abstract java.lang.Number localEvaluate(java.lang.Number lhs,
                                               java.lang.Number rhs)
Performs operation specific evaluation.

Parameters:
lhs - left hand side value
rhs - right hand side value
Returns:
result of the evaluation

evaluate

public final void evaluate(Tuple tuple)
                    throws ExpressionEvaluationException
Evaluates the arithmetic expression on the given input tuple.

Specified by:
evaluate in interface ArithmeticExpression
Parameters:
tuple - input tuple
Throws:
ExpressionEvaluationException - if expression can not be evaluated

getResult

public final java.lang.Object getResult()
Returns the result of the evaluation. In the expression is an aggregation function the result is aggregated from all input tuples up to this point.

Specified by:
getResult in interface ArithmeticExpression
Returns:
result of the evaluation

getChildren

public ArithmeticExpression[] getChildren()
Returns the children of this arithmetic expression.

Specified by:
getChildren in interface ArithmeticExpression
Returns:
child expressions

configure

public void configure(TupleMetadata metadata)
               throws TypeMismatchException
Configures the expression with the metadata. This method must be called before evaluating the expression or calling getMetadata(). This method is also used for type validation.

Specified by:
configure in interface ArithmeticExpression
Parameters:
metadata - tuple metadata
Throws:
TypeMismatchException - when the operand types are incompatible

configure

public void configure(TupleMetadata metadata,
                      java.util.Set<Attribute> correlatedAttributes)
               throws TypeMismatchException
Configures the expression with the metadata. This method must be called before evaluating the expression or calling getMetadata(). This method is also used for type validation. A set of correlated attributes can be passed in to support type validation of correlated attributes.

Specified by:
configure in interface ArithmeticExpression
Parameters:
metadata - tuple metadata
correlatedAttributes - set of correlated attributes, containing their types.
Throws:
TypeMismatchException - when the operand types are incompatible

getMetadata

public ColumnMetadata getMetadata()
Get the result type that is returned when evaluating this expression with tuples of the given type.

Specified by:
getMetadata in interface ArithmeticExpression
Returns:
result type

printOperator

protected abstract void printOperator(java.lang.StringBuffer buf)
Append the operator name (e.g. "+") to the given string buffer.

Parameters:
buf - buffer

getLeftExpression

public ArithmeticExpression getLeftExpression()
Gets left operand expression.

Returns:
left operand expression

getRightExpression

public ArithmeticExpression getRightExpression()
Gets right operand expression.

Returns:
right operand expression.

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object