use of mondrian.calc.impl.AbstractStringCalc in project mondrian by pentaho.
the class FormatFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final Exp[] args = call.getArgs();
final Calc calc = compiler.compileScalar(call.getArg(0), true);
final Locale locale = compiler.getEvaluator().getConnectionLocale();
if (args[1] instanceof Literal) {
// Constant string expression: optimize by
// compiling format string.
String formatString = (String) ((Literal) args[1]).getValue();
final Format format = new Format(formatString, locale);
return new AbstractStringCalc(call, new Calc[] { calc }) {
public String evaluateString(Evaluator evaluator) {
final Object o = calc.evaluate(evaluator);
return format.format(o);
}
};
} else {
// Variable string expression
final StringCalc stringCalc = compiler.compileString(call.getArg(1));
return new AbstractStringCalc(call, new Calc[] { calc, stringCalc }) {
public String evaluateString(Evaluator evaluator) {
final Object o = calc.evaluate(evaluator);
final String formatString = stringCalc.evaluateString(evaluator);
final Format format = new Format(formatString, locale);
return format.format(o);
}
};
}
}
use of mondrian.calc.impl.AbstractStringCalc in project mondrian by pentaho.
the class TupleToStrFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
if (TypeUtil.couldBeMember(call.getArg(0).getType())) {
final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
return new AbstractStringCalc(call, new Calc[] { memberCalc }) {
public String evaluateString(Evaluator evaluator) {
final Member member = memberCalc.evaluateMember(evaluator);
if (member.isNull()) {
return "";
}
StringBuilder buf = new StringBuilder();
buf.append(member.getUniqueName());
return buf.toString();
}
};
} else {
final TupleCalc tupleCalc = compiler.compileTuple(call.getArg(0));
return new AbstractStringCalc(call, new Calc[] { tupleCalc }) {
public String evaluateString(Evaluator evaluator) {
final Member[] members = tupleCalc.evaluateTuple(evaluator);
if (members == null) {
return "";
}
StringBuilder buf = new StringBuilder();
SetToStrFunDef.appendTuple(buf, members);
return buf.toString();
}
};
}
}
Aggregations