com.scudata.expression.fn.math.Round Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esproc Show documentation
Show all versions of esproc Show documentation
SPL(Structured Process Language) A programming language specially for structured data computing.
package com.scudata.expression.fn.math;
import com.scudata.common.MessageManager;
import com.scudata.common.RQException;
import com.scudata.dm.Context;
import com.scudata.expression.Function;
import com.scudata.expression.IParam;
import com.scudata.resources.EngineMessage;
import com.scudata.util.Variant;
public class Round extends Function {
/**
* ??????ʽ????Ч?ԣ???Ч???׳??쳣
*/
public void checkValidity() {
if (param == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("round" + mm.getMessage("function.missingParam"));
}
}
public Object calculate(Context ctx) {
if (param.isLeaf()) {
Object o = param.getLeafExpression().calculate(ctx);
return Variant.round(o);
} else {
if (param.getSubSize() != 2) {
MessageManager mm = EngineMessage.get();
throw new RQException("round" + mm.getMessage("function.invalidParam"));
}
IParam p1 = param.getSub(0);
IParam p2 = param.getSub(1);
if (p1 == null || p2 == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("round" + mm.getMessage("function.invalidParam"));
}
Object o1 = p1.getLeafExpression().calculate(ctx);
Object o2 = p2.getLeafExpression().calculate(ctx);
if (o2 instanceof Number) {
return Variant.round(o1, ((Number)o2).intValue());
} else if (o2 == null) {
return Variant.round(o1);
} else {
MessageManager mm = EngineMessage.get();
throw new RQException("round" + mm.getMessage("function.paramTypeError"));
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy