KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/StdevPFunDef.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.olap.Exp;
16 import mondrian.calc.Calc;
17 import mondrian.calc.ExpCompiler;
18 import mondrian.calc.ListCalc;
19 import mondrian.calc.impl.ValueCalc;
20 import mondrian.calc.impl.AbstractCalc;
21 import mondrian.mdx.ResolvedFunCall;
22
23 import java.util.List JavaDoc;
24
25 /**
26  * Definition of the <code>StdevP</code> builtin MDX function, and its alias
27  * <code>StddevP</code>.
28  *
29  * @author jhyde
30  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/StdevPFunDef.java#3 $
31  * @since Mar 23, 2006
32  */

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