com.scudata.expression.mfn.sequence.Pos 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.expression.IParam;
import com.scudata.expression.SequenceFunction;
import com.scudata.resources.EngineMessage;
/**
* ȡָ??Ԫ?????????е?λ??
* A.pos(x), A.pos(x, start)
* @author RunQian
*
*/
public class Pos extends SequenceFunction {
public boolean ifModifySequence() {
return false;
}
/**
* ??????ʽ????Ч?ԣ???Ч???׳??쳣
*/
public void checkValidity() {
if (param == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("pos" + mm.getMessage("function.missingParam"));
}
}
public Object calculate(Context ctx) {
if (param.isLeaf()) {
Object obj = param.getLeafExpression().calculate(ctx);
return srcSequence.pos(obj, option);
} else {
if (param.getSubSize() != 2) {
MessageManager mm = EngineMessage.get();
throw new RQException("pos" + mm.getMessage("function.invalidParam"));
}
IParam sub0 = param.getSub(0);
IParam sub1 = param.getSub(1);
if (sub0 == null || sub1 == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("pos" + mm.getMessage("function.invalidParam"));
}
Object posVal = sub1.getLeafExpression().calculate(ctx);
if (!(posVal instanceof Number)) {
MessageManager mm = EngineMessage.get();
throw new RQException("pos" + mm.getMessage("function.paramTypeError"));
}
int pos = ((Number)posVal).intValue();
Object val = sub0.getLeafExpression().calculate(ctx);
return srcSequence.pos(val, pos, option);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy