1 package edu.psu.geovista.app.spreadsheet.functions;
2
3 import edu.psu.geovista.app.spreadsheet.table.SSTable;
4 import edu.psu.geovista.app.spreadsheet.table.SSTableModel;
5
6 import java.util.HashMap;
7 import java.util.TreeSet;
8
9 /*
10 * Description:
11 * Date: Apr 16, 2003
12 * Time: 11:01:31 AM
13 * @author Jin Chen
14 */
15
16 public class FunctionManager {
17 private SSTable table;
18
19 // a hash table for function handlers
20 private HashMap funcTable;
21
22 public FunctionManager(SSTable tb) {
23 this.table = tb;
24 this.registerFunctions() ;
25 }
26 /***
27 * Adds a function to the function table.
28 *
29 * @param funcName the name of the function
30 * @param func the edu.psu.geovista.app.spreadsheet.functions.Function object
31 * @see edu.psu.geovista.app.spreadsheet.functions.Function
32 */
33 private void register(String funcName, Function func) {
34 funcTable.put(funcName, func);
35 }
36
37 /***
38 * Registers the edu.psu.geovista.app.spreadsheet.functions on the funcTable.
39 * Should be called only once.
40 */
41 public void registerFunctions() {
42 funcTable = new HashMap();
43 register("ABS", new FunctionAbs());
44 register("ACOS", new FunctionAcos());
45 register("ASIN", new FunctionAsin());
46 register("ATAN", new FunctionAtan());
47 register("AVG", new FunctionAverage());
48 register("COS", new FunctionCos());
49 register("E", new FunctionE());
50 register("FUN_COUNT", new FunctionCount());
51 register("INT", new FunctionInt());
52 register("LOG", new FunctionLog());
53 register("MEDIAN", new FunctionMedian(table));
54 register("MYFUN", new FunctionCustomize());
55 register("PI", new FunctionPI());
56 register("ROUND", new FunctionRound());
57 register("SIN", new FunctionSin());
58 register("SQRT", new FunctionSqrt());
59 register("SUM", new FunctionSum(table));
60 register("TAN", new FunctionTan());
61
62 /*
63 register("SUM", new FunctionSum());
64 register("MEAN", new edu.psu.geovista.app.spreadsheet.functions.FunctionAverage());
65 register("AVERAGE", new edu.psu.geovista.app.spreadsheet.functions.FunctionAverage());
66 register("MEDIAN", new FunctionMedian());
67
68 register("INT", new FunctionInt());
69 register("ROUND", new FunctionRound());
70 register("SIN", new FunctionSin());
71 register("COS", new FunctionCos());
72 register("TAN", new FunctionTan());
73 register("ASIN", new FunctionAsin());
74 register("ACOS", new FunctionAcos());
75 register("ATAN", new FunctionAtan());
76 register("SQRT", new FunctionSqrt());
77 register("LOG", new FunctionLog());
78 register("MIN", new FunctionMin());
79 register("MAX", new FunctionMax());
80 register("RANGE", new SelectionRange());
81 register("STDDEV", new FunctionStddev());
82 register("MEANDEV", new FunctionMeandev());
83 register("COUNT", new FunctionCount());
84 register("PI", new FunctionPI());
85 register("E", new FunctionE()); */
86 }
87
88 /*
89 * provide a way to access these function handlers
90 *
91 * @param fname the function name
92 * @return the function object that can evaluate the specified function.
93 *
94 * @see Funciton
95 * @see SharpTools
96 */
97 public Function getFuncHandler(String fname) {
98 Function f=(Function)funcTable.get(fname);
99
100 return f;
101 }
102
103 public Object[] getFunctionNames(){
104 TreeSet ts=new TreeSet(funcTable.keySet());
105 return ts.toArray() ;
106
107 }
108 }
This page was automatically generated by Maven