csheets.core.formula
Class Formula

java.lang.Object
  extended by csheets.core.formula.Formula
All Implemented Interfaces:
Expression, Serializable
Direct Known Subclasses:
TestCase

public class Formula
extends Object
implements Expression

A formula in a cell.

Author:
Einar Pehrson
See Also:
Serialized Form

Constructor Summary
Formula(Cell cell, Expression expression)
          Creates a new formula.
 
Method Summary
 Object accept(ExpressionVisitor visitor)
          Accepts to visit the given expression visitor.
 Value evaluate()
          Evaluates the expression and returns the result.
 Cell getCell()
          Returns the cell to which the formula belongs.
 Expression getExpression()
          Returns the expression in the formula.
 SortedSet<Reference> getReferences()
          Returns the references in the expression.
 boolean hasCircularReference()
          Checks if the given formula has any circular references.
 String toString()
          Returns a string representation of the formula.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Formula

public Formula(Cell cell,
               Expression expression)
Creates a new formula.

Parameters:
cell - the cell to which the formula belongs
expression - the expression in the formula
Method Detail

evaluate

public Value evaluate()
               throws IllegalValueTypeException
Description copied from interface: Expression
Evaluates the expression and returns the result.

Specified by:
evaluate in interface Expression
Returns:
the result of the evaluation
Throws:
IllegalValueTypeException - if a value of an unexpected type was encountered when evaluating the expression

accept

public Object accept(ExpressionVisitor visitor)
Description copied from interface: Expression
Accepts to visit the given expression visitor.

Specified by:
accept in interface Expression
Parameters:
visitor - the visitor

getCell

public Cell getCell()
Returns the cell to which the formula belongs.

Returns:
the cell to which the formula belongs

getExpression

public Expression getExpression()
Returns the expression in the formula.

Returns:
the expression in the formula

getReferences

public SortedSet<Reference> getReferences()
Returns the references in the expression.

Returns:
the references in the expression

hasCircularReference

public boolean hasCircularReference()
Checks if the given formula has any circular references.

Throws:
CircularReferenceException - if the formula contains any circular references

toString

public String toString()
Returns a string representation of the formula.

Overrides:
toString in class Object
Returns:
a string representation of the formula