1 package edu.psu.geovista.app.spreadsheet.functions;
2
3 import edu.psu.geovista.app.spreadsheet.table.SSTableModel;
4 import edu.psu.geovista.app.spreadsheet.formula.Node;
5 import edu.psu.geovista.app.spreadsheet.exception.ParserException;
6 import edu.psu.geovista.app.spreadsheet.exception.NoReferenceException;
7
8 import java.util.Iterator;
9 import java.util.LinkedList;
10
11 /*
12 * Description:
13 * <code>COUNT</code><br>
14 * usage: <code>=COUNT(parameter list)</code><br>
15 * returns Given a function the number of parameters specified<br>
16 * example: <code>=COUNT(A1:A7)</code> returns <code>7.0</code>
17 * Date: Mar 25, 2003
18 * Time: 10:42:38 AM
19 * @author Jin Chen
20 */
21
22 public class FunctionCount extends Function {
23
24 public Number evaluate( Node node) throws ParserException,NoReferenceException {
25 int count=0;
26 // requires parameters
27 checkParamsExist(node);
28 LinkedList params = node.getParams();//only 1 element
29 Node exp=(Node)params.getFirst() ;// expresion Node(type=Node.EXP). e.g. a1:a2
30 if (exp.getType() ==Node.EXP ){
31 Node paraNode=((Node)exp.getParams().getFirst());// colon Node(type=Node.COLON) e.g.: a1:a2
32 if (paraNode.getType() ==Node.COLON ){
33 SelectionRange range=processColonNode(paraNode);
34 if (range.getType() ==SelectionRange.SINGLE_COLUMN ){
35 count=range.getRowCount() ;
36 }
37 else if ( range.getType() ==SelectionRange.SINGLE_ROW ){
38 count=range.getColumnCount() ;
39 }
40
41 }
42 }
43 return new Integer(count);
44 }//evaluate
45
46 public String getUsage() {
47 return "COUNT(value1,value2,...)";
48 }
49
50 public String getDescription() {
51 return "Counts the number of cells that contain numbers and numbers within the list of arguments.";
52 }
53 }
This page was automatically generated by Maven