com.scudata.expression.mfn.sequence.Calc 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.mfn.sequence;
import com.scudata.common.MessageManager;
import com.scudata.common.RQException;
import com.scudata.dm.Context;
import com.scudata.dm.Sequence;
import com.scudata.expression.Expression;
import com.scudata.expression.IParam;
import com.scudata.expression.SequenceFunction;
import com.scudata.resources.EngineMessage;
/**
* ??????е?ij????ijЩԪ?ؼ??????ʽ
* A.calc(k,x) A.calc(p,x)
* @author RunQian
*
*/
public class Calc extends SequenceFunction {
/**
* ??????ʽ????Ч?ԣ???Ч???׳??쳣
*/
public void checkValidity() {
if (param == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("calc" + mm.getMessage("function.missingParam"));
} else if (param.getSubSize() != 2) {
MessageManager mm = EngineMessage.get();
throw new RQException("calc" + mm.getMessage("function.invalidParam"));
}
}
public Object calculate(Context ctx) {
IParam sub1 = param.getSub(0);
IParam sub2 = param.getSub(1);
if (sub1 == null || sub2 == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("calc" + mm.getMessage("function.invalidParam"));
}
Object param1 = sub1.getLeafExpression().calculate(ctx);
Expression exp2 = sub2.getLeafExpression();
if (param1 instanceof Number) {
return srcSequence.calc(((Number)param1).intValue(), exp2, ctx);
} else if (param1 instanceof Sequence) {
return srcSequence.calc((Sequence)param1, exp2, ctx);
} else {
MessageManager mm = EngineMessage.get();
throw new RQException("calc" + mm.getMessage("function.paramTypeError"));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy