com.scudata.expression.mfn.channel.Id 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.channel;
import com.scudata.common.MessageManager;
import com.scudata.common.RQException;
import com.scudata.dm.Context;
import com.scudata.expression.ChannelFunction;
import com.scudata.expression.Expression;
import com.scudata.expression.IParam;
import com.scudata.resources.EngineMessage;
/**
* Ϊ?ܵ??????ȡָ??????ʽ?IJ?ֵͬ?γɵ????е????з??صĽ????????
* ch.id(xi,??;n) ֻ??һ??xiʱ???س?һ?????У?ÿ??xi?ҵ?n???????ң?nʡ?Է???????
* @author RunQian
*
*/
public class Id extends ChannelFunction {
public Object calculate(Context ctx) {
if (param == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("id" + mm.getMessage("function.missingParam"));
}
// û??????n??????ȡ??????
int n = Integer.MAX_VALUE;
IParam expParam;
if (param.getType() == IParam.Semicolon) {
if (param.getSubSize() != 2) {
MessageManager mm = EngineMessage.get();
throw new RQException("id" + mm.getMessage("function.invalidParam"));
}
expParam = param.getSub(0);
if (expParam == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("id" + mm.getMessage("function.missingParam"));
}
IParam countParam = param.getSub(1);
if (countParam == null || !countParam.isLeaf()) {
MessageManager mm = EngineMessage.get();
throw new RQException("id" + mm.getMessage("function.invalidParam"));
}
Object count = countParam.getLeafExpression().calculate(ctx);
if (!(count instanceof Number)) {
MessageManager mm = EngineMessage.get();
throw new RQException("id" + mm.getMessage("function.paramTypeError"));
}
n = ((Number)count).intValue();
if (n < 1) {
return null;
}
} else {
expParam = param;
}
Expression []exps;
if (expParam.isLeaf()) {
exps = new Expression[] {expParam.getLeafExpression()};
} else {
int size = expParam.getSubSize();
exps = new Expression[size];
for (int i = 0; i < size; ++i) {
IParam sub = expParam.getSub(i);
if (sub == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("id" + mm.getMessage("function.missingParam"));
}
exps[i] = sub.getLeafExpression();
}
}
return channel.id(exps, n, option);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy