All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scudata.expression.mfn.cursor.Skip Maven / Gradle / Ivy

Go to download

SPL(Structured Process Language) A programming language specially for structured data computing.

There is a newer version: 20241126
Show newest version
package com.scudata.expression.mfn.cursor;

import com.scudata.common.MessageManager;
import com.scudata.common.RQException;
import com.scudata.dm.Context;
import com.scudata.expression.CursorFunction;
import com.scudata.expression.Expression;
import com.scudata.expression.IParam;
import com.scudata.resources.EngineMessage;

/**
 * ????ָ???????????ݣ?ʡ???????????У?????ʵ????????????
 * cs.skip(n)
 * @author RunQian
 *
 */
public class Skip extends CursorFunction {
	public Object calculate(Context ctx) {
		if (param == null) {
			long n = cursor.skip();
			if (n < Integer.MAX_VALUE) {
				return new Integer((int)n);
			} else {
				return new Long(n);
			}
		} else if (param.isLeaf()) {
			Object obj = param.getLeafExpression().calculate(ctx);
			if (!(obj instanceof Number)) {
				MessageManager mm = EngineMessage.get();
				throw new RQException("skip" + mm.getMessage("function.paramTypeError"));
			}

			long n = ((Number)obj).longValue();
			n = cursor.skip(n);
			if (n < Integer.MAX_VALUE) {
				return new Integer((int)n);
			} else {
				return new Long(n);
			}
		} else {
			if (param.getType() != IParam.Semicolon || param.getSubSize() != 2) {
				MessageManager mm = EngineMessage.get();
				throw new RQException("skip" + mm.getMessage("function.invalidParam"));
			}

			Expression []exps;
			IParam sub = param.getSub(1);
			if (sub == null) {
				MessageManager mm = EngineMessage.get();
				throw new RQException("skip" + mm.getMessage("function.invalidParam"));
			} else if (sub.isLeaf()) {
				exps = new Expression[]{sub.getLeafExpression()};
			} else {
				int count = sub.getSubSize();
				exps = new Expression[count];
				for (int i = 0; i < count; ++i) {
					IParam p = sub.getSub(i);
					if (p == null || !p.isLeaf()) {
						MessageManager mm = EngineMessage.get();
						throw new RQException("skip" + mm.getMessage("function.invalidParam"));
					}

					exps[i] = p.getLeafExpression();
				}
			}

			int n = cursor.skipGroup(exps, ctx);
			return new Integer(n);
		}
	}
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy