KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > fun > StdevFunDef


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/StdevFunDef.java#3 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2006-2007 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.olap.fun;
11
12 import mondrian.olap.FunDef;
13 import mondrian.olap.Evaluator;
14 import mondrian.olap.Dimension;
15 import mondrian.calc.Calc;
16 import mondrian.calc.ExpCompiler;
17 import mondrian.calc.ListCalc;
18 import mondrian.calc.impl.ValueCalc;
19 import mondrian.calc.impl.AbstractCalc;
20 import mondrian.mdx.ResolvedFunCall;
21
22 import java.util.List JavaDoc;
23
24 /**
25  * Definition of the <code>Stdev</code> builtin MDX function, and its alias
26  * <code>Stddev</code>.
27  *
28  * @author jhyde
29  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/StdevFunDef.java#3 $
30  * @since Mar 23, 2006
31  */

32 class StdevFunDef extends AbstractAggregateFunDef {
33     static final ReflectiveMultiResolver StdevResolver = new ReflectiveMultiResolver(
34             "Stdev",
35             "Stdev(<Set>[, <Numeric Expression>])",
36             "Returns the standard deviation of a numeric expression evaluated over a set (unbiased).",
37             new String JavaDoc[]{"fnx", "fnxn"},
38             StdevFunDef.class);
39
40     static final ReflectiveMultiResolver StddevResolver = new ReflectiveMultiResolver(
41             "Stddev",
42             "Stddev(<Set>[, <Numeric Expression>])",
43             "Alias for Stdev.",
44             new String JavaDoc[]{"fnx", "fnxn"},
45             StdevFunDef.class);
46
47     public StdevFunDef(FunDef dummyFunDef) {
48         super(dummyFunDef);
49     }
50
51     public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
52         final ListCalc listCalc =
53                 compiler.compileList(call.getArg(0));
54         final Calc calc = call.getArgCount() > 1 ?
55                 compiler.compileScalar(call.getArg(1), true) :
56                 new ValueCalc(call);
57         return new AbstractCalc(call) {
58             public Object JavaDoc evaluate(Evaluator evaluator) {
59                 List JavaDoc memberList = evaluateCurrentList(listCalc, evaluator);
60                 return stdev(evaluator.push(), memberList, calc, false);
61             }
62
63             public Calc[] getCalcs() {
64                 return new Calc[] {listCalc, calc};
65             }
66
67             public boolean dependsOn(Dimension dimension) {
68                 return anyDependsButFirst(getCalcs(), dimension);
69             }
70         };
71     }
72 }
73
74 // End StdevFunDef.java
75
Popular Tags