Back to index

wims  3.65+svn20090927
Public Member Functions | Protected Member Functions | Static Protected Member Functions
SharpTools.FunctionSum Class Reference

SUM
usage: =SUM(parameter list)
returns the arithmetic sum of the specified parameters
example: =SUM(-1,2,57) returns 58.0 More...

Inheritance diagram for SharpTools.FunctionSum:
Inheritance graph
[legend]
Collaboration diagram for SharpTools.FunctionSum:
Collaboration graph
[legend]

List of all members.

Public Member Functions

Number evaluate (SharpTableModel table, Node node, int row, int col) throws ParserException
 This should be implemented in each function.
String getUsage ()
 Return the usage of the function.
String getDescription ()
 Return the description of the function.
boolean requireParams ()
 Whether this function requires parameters.

Protected Member Functions

boolean isRange (Node param)
Node getFirst (Node param)
void checkParamsExist (Node func) throws ParserException

Static Protected Member Functions

static float getSingleParameter (SharpTableModel table, Node node, int row, int col) throws ParserException
 This gets the first float number of a parameter li st, for functions only accepting a single parameter such as ABS, COS , etc.

Detailed Description

SUM
usage: =SUM(parameter list)
returns the arithmetic sum of the specified parameters
example: =SUM(-1,2,57) returns 58.0

Definition at line 146 of file Function.java.


Member Function Documentation

void SharpTools.Function.checkParamsExist ( Node  func) throws ParserException [inline, protected, inherited]

Definition at line 42 of file Function.java.

                                                                      {
       
       if (func.getParams().size()==0){
           throw exception;
       }
    }

Here is the caller graph for this function:

Number SharpTools.FunctionSum.evaluate ( SharpTableModel  table,
Node  node,
int  row,
int  col 
) throws ParserException [inline, virtual]

This should be implemented in each function.

Parameters:
tablethe SharpTabelModel
nodethe function node starting with the funciton name with a chain of parameters
colthe int column coordinate
rowthe int row coordinate
Exceptions:
ParserException

Implements SharpTools.Function.

Definition at line 147 of file Function.java.

                                                                                                      {
    
       // requires parameters
       checkParamsExist(node);
       
       float sum = 0;

       LinkedList params = node.getParams();
       if (params != null) {

           // go over the parameters
           Iterator it = params.iterator();

           while (it.hasNext()) {

              // get this parameter
              Node exp = (Node)it.next();

              // if it's a range of cells
              if (isRange(exp)) {      
                  CellPoint[] addr =
                     getFirst(exp).getAddressRange(row, col);
                  // for a range, go over the whole range
                  for (int i = addr[0].getRow(); i <= addr[1].getRow(); i++)
                     for (int j = addr[0].getCol(); j <= addr[1].getCol(); j++)
                         // get the numeric value of that cell
                         sum += table.getNumericValueAt(i, j).floatValue();
              }
              else {
                  // evaluate this parameter's expression (sub-formula)
                  sum += Formula.evaluate(table, exp.getExp(), row, col).floatValue();
              }
           }
           
       }
       return (Number)(new Float(sum));
    }

Here is the call graph for this function:

String SharpTools.FunctionSum.getDescription ( ) [inline, virtual]

Return the description of the function.

Implements SharpTools.Function.

Definition at line 189 of file Function.java.

                                   {
       return SharpTools.translation.getProperty("sum_desc");
       //return "Adds all the numbers in a set of values.";
    }
Node SharpTools.Function.getFirst ( Node  param) [inline, protected, inherited]

Definition at line 37 of file Function.java.

                                        {
       return (Node)param.getExp().getFirst();
    }    

Here is the call graph for this function:

Here is the caller graph for this function:

static float SharpTools.Function.getSingleParameter ( SharpTableModel  table,
Node  node,
int  row,
int  col 
) throws ParserException [inline, static, protected, inherited]

This gets the first float number of a parameter li st, for functions only accepting a single parameter such as ABS, COS , etc.

Parameters:
tablethe SharpTabelModel
nodethe formula unit
colthe int column coordinate
rowthe int row coordinate
Returns:
the float number

Definition at line 61 of file Function.java.

                              {
       //     Node param = node.getNextParam();
       LinkedList params = node.getParams();

       if (params.size() != 1)
           throw new ParserException("#PARAM?");

       LinkedList exp = ((Node)params.getFirst()).getExp();
       
       return Formula.evaluate(table, exp, row, col).floatValue();

    }

Here is the call graph for this function:

Here is the caller graph for this function:

String SharpTools.FunctionSum.getUsage ( ) [inline, virtual]

Return the usage of the function.

Implements SharpTools.Function.

Definition at line 185 of file Function.java.

                             {
       return "SUM(value1,value2,...)";
    }
boolean SharpTools.Function.isRange ( Node  param) [inline, protected, inherited]

Definition at line 29 of file Function.java.

                                          {
       LinkedList exp = param.getExp();
       return exp.size() == 1 &&
           ((Node)exp.getFirst()).isType(Node.COLON);
           //((Node)param.getExp().getFirst()).isType(Node.COLON);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean SharpTools.Function.requireParams ( ) [inline, inherited]

Whether this function requires parameters.

By default yes.

See also:
FunctionPI
FunctionE

Reimplemented in SharpTools.FunctionE, and SharpTools.FunctionPI.

Definition at line 136 of file Function.java.

{ return true; }

Here is the caller graph for this function:


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