KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/VarFunDef.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>Var</code> MDX builtin function
26  * (and its synonym <code>Variance</code>).
27  *
28  * @author jhyde
29  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/VarFunDef.java#3 $
30  * @since Mar 23, 2006
31  */

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