csheets.core.formula.lang
Class CellReference

java.lang.Object
  extended by csheets.core.formula.lang.CellReference
All Implemented Interfaces:
Expression, Reference, Serializable, Comparable<Reference>

public class CellReference
extends Object
implements Reference

A reference to a cell in a spreadsheet.

Author:
Einar Pehrson
See Also:
Serialized Form

Constructor Summary
CellReference(Cell cell)
          Creates a new cell reference to the given address.
CellReference(Cell cell, boolean columnAbsolute, boolean rowAbsolute)
          Creates a new cell reference to the given address, using the given reference mode.
CellReference(Spreadsheet spreadsheet, String reference)
          Creates a new cell reference from a string matching the (@link #PATTERN).
 
Method Summary
 Object accept(ExpressionVisitor visitor)
          Accepts to visit the given expression visitor.
 int compareTo(Reference reference)
          Compares the cell reference with the given cell reference for order.
 Value evaluate()
          Evaluates the expression and returns the result.
 Cell getCell()
          Returns the cell to which the reference points.
 SortedSet<Cell> getCells()
          Returns the cell addresses (or address) that the reference points to.
 boolean isColumnAbsolute()
          Returns whether the column is denoted with an absolute reference.
 boolean isRowAbsolute()
          Returns whether the row is denoted with an absolute reference.
 String toString()
          Returns a string representation of the address of the cell reference on the form "B22", composed of the letter of the column and number of the row that intersect to form the address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CellReference

public CellReference(Cell cell)
Creates a new cell reference to the given address. By default, relative addressing is used.

Parameters:
cell - the cell to which the reference points

CellReference

public CellReference(Cell cell,
                     boolean columnAbsolute,
                     boolean rowAbsolute)
Creates a new cell reference to the given address, using the given reference mode.

Parameters:
cell - the cell to which the reference points
columnAbsolute - if the column is denoted with an absolute reference
rowAbsolute - if the column is denoted with an absolute reference

CellReference

public CellReference(Spreadsheet spreadsheet,
                     String reference)
              throws ParseException
Creates a new cell reference from a string matching the (@link #PATTERN).

Parameters:
spreadsheet - the spreadsheet of the cell
reference - a string representation of the reference
Throws:
ParseException - if the string did not match the pattern
Method Detail

evaluate

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

Specified by:
evaluate in interface Expression
Specified by:
evaluate in interface Reference
Returns:
the result of the evaluation

accept

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

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

getCell

public Cell getCell()
Returns the cell to which the reference points.

Returns:
the cell to which the reference points

getCells

public SortedSet<Cell> getCells()
Description copied from interface: Reference
Returns the cell addresses (or address) that the reference points to.

Specified by:
getCells in interface Reference
Returns:
a naturally ordered set of the references' addresses

isColumnAbsolute

public boolean isColumnAbsolute()
Returns whether the column is denoted with an absolute reference.

Returns:
true if the column is denoted with an absolute reference.

isRowAbsolute

public boolean isRowAbsolute()
Returns whether the row is denoted with an absolute reference.

Returns:
true if the row is denoted with an absolute reference.

compareTo

public int compareTo(Reference reference)
Compares the cell reference with the given cell reference for order.

Specified by:
compareTo in interface Reference
Specified by:
compareTo in interface Comparable<Reference>
Parameters:
reference - the reference to be compared
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

toString

public String toString()
Returns a string representation of the address of the cell reference on the form "B22", composed of the letter of the column and number of the row that intersect to form the address.

Overrides:
toString in class Object
Returns:
a string representation of the address of the cell reference