| 1 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 ; 21 22 29 class HierarchizeFunDef extends FunDefBase { 30 static final String [] 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 [] {"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 order = getLiteralArg(call, 1, "PRE", prePost); 47 final boolean post = order.equals("POST"); 48 return new AbstractListCalc(call, new Calc[] {listCalc}) { 49 public List evaluateList(Evaluator evaluator) { 50 List list = listCalc.evaluateList(evaluator); 51 hierarchize(list, post); 52 return list; 53 } 54 }; 55 } 56 } 57 58 | Popular Tags |