View Javadoc
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.formula.Formula; 6 import edu.psu.geovista.app.spreadsheet.formula.Cell; 7 import edu.psu.geovista.app.spreadsheet.exception.ParserException; 8 import edu.psu.geovista.app.spreadsheet.exception.NoReferenceException; 9 10 import java.util.Iterator; 11 import java.util.LinkedList; 12 import java.awt.*; 13 14 import edu.psu.geovista.app.spreadsheet.util.Debug; 15 import edu.psu.geovista.app.spreadsheet.SpreadSheetBean; 16 import edu.psu.geovista.app.spreadsheet.table.SSTable; 17 18 /* 19 * Description: 20 * <code>SUM</code><br> 21 * usage: <code>=SUM(parameter list)</code><br> 22 * returns the arithmetic sum of the specified parameters<br> 23 * example: <code>=SUM(-1,2,57)</code> returns <code>58.0</code> 24 * Date: Mar 25, 2003 25 * Time: 10:41:06 AM 26 * @author Jin Chen 27 */ 28 29 public class FunctionSum extends Function { 30 private SSTable tb; 31 32 public FunctionSum(SSTable tb) { 33 this.tb = tb; 34 } 35 36 public Number evaluate( Node node) throws ParserException,NoReferenceException { 37 //SSTable tb=SpreadSheetBean.getTableInstance() ; 38 float sum=0; 39 SelectionRange fr=getRangeArea(node); 40 Point[] range=fr.getRange() ; 41 int sx=(int)range[0].getX() ; 42 int ex=(int)range[1].getX() ; 43 int sy=(int)range[0].getY() ; 44 int ey=(int)range[1].getY() ; 45 if (fr.getType() ==SelectionRange.SINGLE_COLUMN ){ 46 int y=(int)range[0].getY() ; 47 for (int x=sx;x<=ex;x++){ 48 Cell cell=((Cell)tb.getValueAtIndex(x,y)); 49 float v=Formula.processCellValue(cell.getValue()).floatValue(); 50 sum=sum+v; 51 } 52 } 53 else if(fr.getType() ==SelectionRange.SINGLE_ROW) { 54 int x=(int)range[0].getX() ; 55 for (int y=sy;x<=ey;y++){ 56 Cell cell=((Cell)tb.getValueAtIndex(x,y)); 57 float v=Formula.processCellValue(cell.getValue()).floatValue(); 58 sum=sum+v; 59 } 60 } 61 return new Float(sum); 62 63 } 64 65 public String getUsage() { 66 return "SUM(value1,value2,...)"; 67 } 68 69 public String getDescription() { 70 return "Adds all the numbers in a set of values."; 71 } 72 }//edu.psu.geovista.app.spreadsheet.functions.FunctionSum

This page was automatically generated by Maven