KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/CorrelationFunDef.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.AbstractDoubleCalc;
20 import mondrian.mdx.ResolvedFunCall;
21
22 import java.util.List JavaDoc;
23
24 /**
25  * Definition of the <code>Correlation</code> MDX function.
26  *
27  * @author jhyde
28  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/CorrelationFunDef.java#3 $
29  * @since Mar 23, 2006
30  */

31 class CorrelationFunDef extends AbstractAggregateFunDef {
32     static final ReflectiveMultiResolver Resolver = new ReflectiveMultiResolver(
33             "Correlation",
34             "Correlation(<Set>, <Numeric Expression>[, <Numeric Expression>])",
35             "Returns the correlation of two series evaluated over a set.",
36             new String JavaDoc[]{"fnxn","fnxnn"},
37             CorrelationFunDef.class);
38
39     public CorrelationFunDef(FunDef dummyFunDef) {
40         super(dummyFunDef);
41     }
42
43     public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
44         final ListCalc listCalc =
45                 compiler.compileList(call.getArg(0));
46         final Calc calc1 =
47                 compiler.compileScalar(call.getArg(1), true);
48         final Calc calc2 = call.getArgCount() > 2 ?
49                 compiler.compileScalar(call.getArg(2), true) :
50                 new ValueCalc(call);
51         return new AbstractDoubleCalc(call, new Calc[] {listCalc, calc1, calc2}) {
52             public double evaluateDouble(Evaluator evaluator) {
53                 List JavaDoc memberList = evaluateCurrentList(listCalc, evaluator);
54                 return correlation(evaluator.push(),
55                         memberList, calc1, calc2);
56             }
57
58             public boolean dependsOn(Dimension dimension) {
59                 return anyDependsButFirst(getCalcs(), dimension);
60             }
61         };
62     }
63 }
64
65 // End CorrelationFunDef.java
66
Popular Tags