Back to index

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

MEDIAN
usage: =MEDIAN(parameter list)
returns the median (the value in the middle) of the specified parameters
example: =MEDIAN(1,2,5) returns 2.0 More...

Inheritance diagram for SharpTools.FunctionMedian:
Inheritance graph
[legend]
Collaboration diagram for SharpTools.FunctionMedian:
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

MEDIAN
usage: =MEDIAN(parameter list)
returns the median (the value in the middle) of the specified parameters
example: =MEDIAN(1,2,5) returns 2.0

Definition at line 283 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.FunctionMedian.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 285 of file Function.java.

                                                                {
       // requires parameters
       checkParamsExist(node);

       // get number of values
       int nCells = (int)(new FunctionCount()).
           evaluate(table, node, row, col).floatValue();

       float[] values = new float[nCells];

       // get all the values
       
       int index = 0;
       
       LinkedList params = node.getParams();
       
       if (params != null) {

           Iterator it = params.iterator();

           while (it.hasNext()) {
              // the first parameter
              Node exp = (Node)it.next();
              
              if (isRange(exp)) {
                  // if it's a range get each cell's value
                  CellPoint[] addr =
                     getFirst(exp).getAddressRange(row, col);
                  
                  for (int i = addr[0].getRow(); i <= addr[1].getRow(); i++)
                     for (int j = addr[0].getCol(); j <= addr[1].getCol(); j++){
                         values[index++] =
                            table.getNumericValueAt(i, j).floatValue();
                     }
              }
              else {
                  // otherwise get this expression's value
                  values[index++] =
                     Formula.evaluate(table, exp.getExp(), row, col).floatValue();
              }
           }
           
       }

       // sort the values array
       for (int m = 0; m < nCells-1; m++)
           for (int n = m; n < nCells-1; n++)
              if (values[m]>values[n]) {
                  float tmp = values[m];
                  values[m] = values[n];
                  values[n] = tmp;
              }

       // get the median
       int half = nCells/2;
       
       if (nCells != half*2)
           return new Float(values[half]);
       else
           return new Float((values[half-1]+values[half])/2);
    }

Here is the call graph for this function:

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

Return the description of the function.

Implements SharpTools.Function.

Definition at line 352 of file Function.java.

                                   {
       return SharpTools.translation.getProperty("median_desc");
       //return "Returns the median (value in the middle) of its arguments.";
    }    
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.FunctionMedian.getUsage ( ) [inline, virtual]

Return the usage of the function.

Implements SharpTools.Function.

Definition at line 348 of file Function.java.

                             {
       return "MEDIAN(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: