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

com.scudata.expression.mfn.sequence.Shift Maven / Gradle / Ivy

Go to download

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

There is a newer version: 20240823
Show newest version
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.shift(i,s)
 * @author RunQian
 *
 */
public class Shift extends SequenceFunction {
	public Object calculate(Context ctx) {
		int pos = 1;
		int move = 1;
		
		if (param == null) {
		} else if (param.isLeaf()) {
			Object obj = param.getLeafExpression().calculate(ctx);
			if (!(obj instanceof Number)) {
				MessageManager mm = EngineMessage.get();
				throw new RQException("shift" + mm.getMessage("function.paramTypeError"));
			}
			
			pos = ((Number)obj).intValue();
			if (pos < 1) {
				MessageManager mm = EngineMessage.get();
				throw new RQException("shift" + mm.getMessage("function.invalidParam"));
			}
		} else if (param.getSubSize() == 2) {
			IParam sub0 = param.getSub(0);
			if (sub0 != null) {
				Object obj = sub0.getLeafExpression().calculate(ctx);
				if (!(obj instanceof Number)) {
					MessageManager mm = EngineMessage.get();
					throw new RQException("shift" + mm.getMessage("function.paramTypeError"));
				}
				
				pos = ((Number)obj).intValue();
				if (pos < 1) {
					MessageManager mm = EngineMessage.get();
					throw new RQException("shift" + mm.getMessage("function.invalidParam"));
				}
			}
			
			IParam sub1 = param.getSub(1);
			if (sub1 != null) {
				Object obj = sub1.getLeafExpression().calculate(ctx);
				if (!(obj instanceof Number)) {
					MessageManager mm = EngineMessage.get();
					throw new RQException("shift" + mm.getMessage("function.paramTypeError"));
				}
				
				move = ((Number)obj).intValue();
				if (move < 1) {
					MessageManager mm = EngineMessage.get();
					throw new RQException("shift" + mm.getMessage("function.invalidParam"));
				}
			}
		} else {
			MessageManager mm = EngineMessage.get();
			throw new RQException("shift" + mm.getMessage("function.invalidParam"));
		}
		
		srcSequence.shift(pos, move);
		return srcSequence;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy