KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/HierarchizeFunDef.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.calc.Calc;
13 import mondrian.calc.ExpCompiler;
14 import mondrian.calc.ListCalc;
15 import mondrian.calc.impl.AbstractListCalc;
16 import mondrian.mdx.ResolvedFunCall;
17 import mondrian.olap.Evaluator;
18 import mondrian.olap.FunDef;
19
20 import java.util.List JavaDoc;
21
22 /**
23  * Definition of the <code>Hierarchize</code> MDX function.
24  *
25  * @author jhyde
26  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/HierarchizeFunDef.java#3 $
27  * @since Mar 23, 2006
28  */

29 class HierarchizeFunDef extends FunDefBase {
30     static final String JavaDoc[] prePost = {"PRE","POST"};
31     static final ReflectiveMultiResolver Resolver = new ReflectiveMultiResolver(
32             "Hierarchize",
33             "Hierarchize(<Set>[, POST])",
34             "Orders the members of a set in a hierarchy.",
35             new String JavaDoc[] {"fxx", "fxxy"},
36             HierarchizeFunDef.class,
37             prePost);
38
39     public HierarchizeFunDef(FunDef dummyFunDef) {
40         super(dummyFunDef);
41     }
42
43     public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
44         final ListCalc listCalc = (ListCalc) compiler.compile(call.getArg(0),
45                     ExpCompiler.MUTABLE_LIST_RESULT_STYLE_ARRAY);
46         String JavaDoc order = getLiteralArg(call, 1, "PRE", prePost);
47         final boolean post = order.equals("POST");
48         return new AbstractListCalc(call, new Calc[] {listCalc}) {
49             public List JavaDoc evaluateList(Evaluator evaluator) {
50                 List JavaDoc list = listCalc.evaluateList(evaluator);
51                 hierarchize(list, post);
52                 return list;
53             }
54         };
55     }
56 }
57
58 // End HierarchizeFunDef.java
59
Popular Tags