KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/IsFunDef.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-2006 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.*;
13 import mondrian.calc.Calc;
14 import mondrian.calc.ExpCompiler;
15 import mondrian.calc.TupleCalc;
16 import mondrian.calc.impl.AbstractBooleanCalc;
17 import mondrian.mdx.ResolvedFunCall;
18
19 /**
20  * Definition of the <code>IS</code> MDX function.
21  *
22  * @see IsNullFunDef
23  * @author jhyde
24  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/IsFunDef.java#3 $
25  * @since Mar 23, 2006
26  */

27 class IsFunDef extends FunDefBase {
28     static final ReflectiveMultiResolver Resolver = new ReflectiveMultiResolver(
29             "IS",
30             "<Expression> IS <Expression>",
31             "Returns whether two objects are the same",
32             new String JavaDoc[] {"ibmm", "ibll", "ibhh", "ibdd", "ibtt"},
33             IsFunDef.class);
34
35     public IsFunDef(FunDef dummyFunDef) {
36         super(dummyFunDef);
37     }
38
39     public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
40         final int category = call.getArg(0).getCategory();
41         switch (category) {
42         case Category.Tuple:
43             final TupleCalc tupleCalc0 = compiler.compileTuple(call.getArg(0));
44             final TupleCalc tupleCalc1 = compiler.compileTuple(call.getArg(1));
45             return new AbstractBooleanCalc(call, new Calc[] {tupleCalc0, tupleCalc1}) {
46                 public boolean evaluateBoolean(Evaluator evaluator) {
47                     Member[] o0 = tupleCalc0.evaluateTuple(evaluator);
48                     Member[] o1 = tupleCalc1.evaluateTuple(evaluator);
49                     return equalTuple(o0, o1);
50                 }
51             };
52         default:
53             assert category == call.getArg(1).getCategory();
54             final Calc calc0 = compiler.compile(call.getArg(0));
55             final Calc calc1 = compiler.compile(call.getArg(1));
56             return new AbstractBooleanCalc(call, new Calc[] {calc0, calc1}) {
57                 public boolean evaluateBoolean(Evaluator evaluator) {
58                     Object JavaDoc o0 = calc0.evaluate(evaluator);
59                     Object JavaDoc o1 = calc1.evaluate(evaluator);
60                     return o0 == o1;
61                 }
62             };
63         }
64     }
65 }
66
67 // End IsFunDef.java
68
Popular Tags