Back to index

wims  3.65+svn20090927
Public Member Functions | Static Public Attributes | Private Attributes
SharpTools.Cell Class Reference

This is a wrapper class for all objects in the table. More...

Collaboration diagram for SharpTools.Cell:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Cell ()
 Creates an empty cell.
 Cell (Object datum)
 This constructor constructs a cell that will not have cells referencing it and are not formulas.
 Cell (Object datum, TreeSet reference)
 The constructor creates a new data cell which is not a formula.
 Cell (Formula thing, Object eVal, TreeSet reference)
 This version of the constructor constructs a formula cell.
Formula getFormula ()
 This method returns the formula associated with the cell or null if it does not exist.
Object getValue ()
 If it is a data cell, it returns the data of the cell.
void setValue (Object datum)
 Sets the value field of the cell.
void setData (Object datum)
 This method changes the cell to a data cell with value datum.
void setFormula (Formula form)
 This method sets the cell to be a formula cell.
boolean isEmpty ()
 Returns true if cell at specified position is empty.
boolean hasRefs ()
 This method returns true if there are cells that reference this one.
TreeSet getRefs ()
 This method gets the list of cells that reference this one.
void removeRef (CellPoint reference)
 This method removes a cell from reference list.
void addRef (CellPoint reference)
 This method adds a cell to the dependency list.
int getType ()
 This method is useful for determining what information a cell holds.
boolean isFormula ()
 This method returns true IFF it is a formula cell.
boolean isErrorCell ()
 This method determines a cell is a formula cell that has a error.
int compare (Cell x, boolean ascending)
 This is a method similar to compareTo except that it is not consistent with the equals method.
String toString ()

Static Public Attributes

static final int TEXT = 0
 The integer code that denotes the cell holds text.
static final int NUMBER = 1
 The integer code that denotes the cell holds numbers.
static final int FORMULA = 2
 The integer code that denotes the cell holds a formula.

Private Attributes

Object value
 Value of the cell.
Formula expression
 This expression contains the string and internal representation of the formula if it exists.
TreeSet refs
 The list of cells that reference this cell.

Detailed Description

This is a wrapper class for all objects in the table.

A cell has a value which is either text or a number. If it is a formula cell it also has an expression associated with it. In addition, a cell has a list of all cells that reference it.

Author:
Ricky Chin
Version:
Revision:
1.27

Definition at line 22 of file Cell.java.


Constructor & Destructor Documentation

SharpTools.Cell.Cell ( ) [inline]

Creates an empty cell.

Definition at line 49 of file Cell.java.

                  {
        value = null;
        expression = null;
        refs = null;
    }
SharpTools.Cell.Cell ( Object  datum) [inline]

This constructor constructs a cell that will not have cells referencing it and are not formulas.

Basically only used for creating the row and column labels.

Warning: Do not use this with Formulas

Parameters:
datumthe value of the "label" cell (not a Formula)

Definition at line 63 of file Cell.java.

                              {
        value = datum;
        expression = null;
        refs = null;
    }
SharpTools.Cell.Cell ( Object  datum,
TreeSet  reference 
) [inline]

The constructor creates a new data cell which is not a formula.

Note: A normal cell's data is stored in value field but expression (i.e. formula) field is null.

Parameters:
datumthe value of the cell (text or number)
referencethe list of cells that reference this one (can be null)

Definition at line 77 of file Cell.java.

                                                 {
        value = datum;
        expression = null;
        refs = reference;
    }
SharpTools.Cell.Cell ( Formula  thing,
Object  eVal,
TreeSet  reference 
) [inline]

This version of the constructor constructs a formula cell.

Parameters:
thinginternal represenation of the formula
eValthe evaluated value of the formula (thing)
referencethe list of cells that reference this one (can be null)

Definition at line 90 of file Cell.java.

                                                               {
        expression = thing;
        value = eVal;
        refs = reference;
    }

Member Function Documentation

void SharpTools.Cell.addRef ( CellPoint  reference) [inline]

This method adds a cell to the dependency list.

Parameters:
referencea new cell that references this one that needs to be added to the reference list

Definition at line 206 of file Cell.java.

                                            {
       //     System.out.println("add ref "+reference+" to ("+this);
        if (refs == null) {// check if refs is initiated
            refs = new TreeSet();
        }
        refs.add(reference);   
    }

Here is the caller graph for this function:

int SharpTools.Cell.compare ( Cell  x,
boolean  ascending 
) [inline]

This is a method similar to compareTo except that it is not consistent with the equals method.

It is used for sorting. Cells are rated in increasing order: blank, error, string, number (including formulas). If two cells are blank or errors then they are "equal" by this compare method. Numbers and strings are compared the usual way.

Parameters:
xcell to compare this to
Returns:
-1 if this < x, 0 if this = x, 1 if this > x

Definition at line 256 of file Cell.java.

                                                  {
        //if this is blank which is lowest value
        if (this.value.equals("")) {
            //x is not blank so this is less than
            if (!x.value.equals("")) {
                if (ascending) {
                    return 1;
                } else {
                    return -1;
                }
            } else {               //otherwise equal
                return 0;
            }
        } else {
            if (x.value.equals("")) {
                if (ascending) {
                    return -1;
                }else {
                    return 1;
                }
            } else {               //both have values
                if (this.isErrorCell()) {
                    if (x.isErrorCell()) {
                        return 0;
                    } else {
                        return -1;
                    }
                } else {
                    if (x.isErrorCell()) {
                        return 1;
                    } else {
                        if (this.getType() == Cell.TEXT) {
                            if (x.getType() == Cell.TEXT) {
                                String temp = (String)this.value;
                                return temp.compareToIgnoreCase((String)x.value);
                            } else {
                                return -1;
                            }
                        } else {
                            if (x.getType() == Cell.TEXT) {
                                return 1;
                            } else {
                                Float first = (Float)this.value;
                                Float second = (Float)x.value;
                                return first.compareTo(second);
                            }
                        }
                    }
                }
            }
        }
    } 

Here is the call graph for this function:

Here is the caller graph for this function:

This method returns the formula associated with the cell or null if it does not exist.

Returns:
the formula (string and internal object) or null if does not exist

Definition at line 103 of file Cell.java.

                                {
        return expression;
    }

Here is the caller graph for this function:

TreeSet SharpTools.Cell.getRefs ( ) [inline]

This method gets the list of cells that reference this one.

This method should be used after the cell's value has been changed to find out which cells need to be updated.

Returns:
all cells that reference this cell

Definition at line 183 of file Cell.java.

                             {
       return refs;
    }

Here is the caller graph for this function:

int SharpTools.Cell.getType ( ) [inline]

This method is useful for determining what information a cell holds.

To check if a cell holds a certain type just see if getType() == Cell.CODE where CODE is any of the cell constants.

Returns:
the integer code of the type of data this cell holds

Definition at line 221 of file Cell.java.

                         {
        if (expression != null) return Cell.FORMULA;
        if (value instanceof Number) return Cell.NUMBER;
        return Cell.TEXT;
    }

Here is the caller graph for this function:

Object SharpTools.Cell.getValue ( ) [inline]

If it is a data cell, it returns the data of the cell.

If it is a formula, it returns the previously evaluated value of the formula.

Returns:
the value (data or evaluated) of the cell

Definition at line 115 of file Cell.java.

                             {
        return value;
    }

Here is the caller graph for this function:

This method returns true if there are cells that reference this one.

Returns:
true only if there are cells that reference this one

Definition at line 172 of file Cell.java.

                             {
        return (refs != null && !refs.isEmpty());
    }

Here is the caller graph for this function:

Returns true if cell at specified position is empty.

Returns:
true if empty, false is not

Definition at line 160 of file Cell.java.

                             {
       if(value.equals("") && expression == null)
           return true;
       else
           return false;
    }

This method determines a cell is a formula cell that has a error.

Returns:
true if cell is an error cell

Definition at line 241 of file Cell.java.

                                 {
        return ((isFormula()) && (value instanceof ParserException));
    }

Here is the call graph for this function:

Here is the caller graph for this function:

This method returns true IFF it is a formula cell.

Returns:
true iff a formula cell

Definition at line 232 of file Cell.java.

                               {
        return (expression != null);
    }

Here is the caller graph for this function:

void SharpTools.Cell.removeRef ( CellPoint  reference) [inline]

This method removes a cell from reference list.

Parameters:
referencethe cell to be removed from the reference list

Definition at line 192 of file Cell.java.

                                               {
       //     System.out.println("remove ref "+reference+" from "+this);
       if (refs != null) {
           refs.remove(reference);
           if (refs.isEmpty()) refs = null;
       }
    }

Here is the caller graph for this function:

void SharpTools.Cell.setData ( Object  datum) [inline]

This method changes the cell to a data cell with value datum.

This method useful because changing the value does not affect the value of the reference list.

Warning: If the cell is going to be set to a formula, you must use setFormula() because this present method sets the associated formula field, expression, to null.

Parameters:
datumthe new value of cell

Definition at line 140 of file Cell.java.

                                      {
        value = datum;
        expression = null;
    }  

Here is the caller graph for this function:

void SharpTools.Cell.setFormula ( Formula  form) [inline]

This method sets the cell to be a formula cell.

It puts the formula object into the expression field. The Table of Cells is responsible for recalculating and setting the appropriate value in the value field of this cell.

Parameters:
formthe internal representation of formula to set this cell to

Definition at line 153 of file Cell.java.

                                         {
        expression = form;
    }

Here is the caller graph for this function:

void SharpTools.Cell.setValue ( Object  datum) [inline]

Sets the value field of the cell.

Parameters:
datumthe object to set the value of cell to

Definition at line 125 of file Cell.java.

                                       {
        value = datum;
    }

Here is the caller graph for this function:

String SharpTools.Cell.toString ( ) [inline]

Definition at line 309 of file Cell.java.

                             {
        
        if (expression != null)
            return "="+expression.toString();
       else
           return value.toString();
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

This expression contains the string and internal representation of the formula if it exists.

Definition at line 40 of file Cell.java.

final int SharpTools.Cell.FORMULA = 2 [static]

The integer code that denotes the cell holds a formula.

Definition at line 31 of file Cell.java.

final int SharpTools.Cell.NUMBER = 1 [static]

The integer code that denotes the cell holds numbers.

Definition at line 28 of file Cell.java.

TreeSet SharpTools.Cell.refs [private]

The list of cells that reference this cell.

When a cell is changes, all cells on this list should notified.

Definition at line 46 of file Cell.java.

final int SharpTools.Cell.TEXT = 0 [static]

The integer code that denotes the cell holds text.

Definition at line 25 of file Cell.java.

Object SharpTools.Cell.value [private]

Value of the cell.

In a formula, value holds the evaluated value.

Definition at line 34 of file Cell.java.


The documentation for this class was generated from the following file: