1 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 ; 23 24 31 class MinMaxFunDef extends AbstractAggregateFunDef { 32 static final ReflectiveMultiResolver MinResolver = new ReflectiveMultiResolver( 33 "Min", 34 "Min(<Set>[, <Numeric Expression>])", 35 "Returns the minimum value of a numeric expression evaluated over a set.", 36 new String []{"fnx", "fnxn"}, 37 MinMaxFunDef.class); 38 39 static final MultiResolver MaxResolver = new ReflectiveMultiResolver( 40 "Max", 41 "Max(<Set>[, <Numeric Expression>])", 42 "Returns the maximum value of a numeric expression evaluated over a set.", 43 new String []{"fnx", "fnxn"}, 44 MinMaxFunDef.class); 45 46 private final boolean max; 47 48 public MinMaxFunDef(FunDef dummyFunDef) { 49 super(dummyFunDef); 50 this.max = dummyFunDef.getName().equals("Max"); 51 } 52 53 public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) { 54 final ListCalc listCalc = 55 compiler.compileList(call.getArg(0)); 56 final Calc calc = call.getArgCount() > 1 ? 57 compiler.compileScalar(call.getArg(1), true) : 58 new ValueCalc(call); 59 return new AbstractCalc(call) { 60 public Object evaluate(Evaluator evaluator) { 61 List memberList = evaluateCurrentList(listCalc, evaluator); 62 return max ? 63 max(evaluator.push(), memberList, calc) : 64 min(evaluator.push(), memberList, calc); 65 } 66 67 public Calc[] getCalcs() { 68 return new Calc[] {listCalc, calc}; 69 } 70 71 public boolean dependsOn(Dimension dimension) { 72 return anyDependsButFirst(getCalcs(), dimension); 73 } 74 }; 75 } 76 } 77 78 | Popular Tags |