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

com.scudata.expression.operator.Greater Maven / Gradle / Ivy

Go to download

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

The newest version!
package com.scudata.expression.operator;

import com.scudata.array.ConstArray;
import com.scudata.array.IArray;
import com.scudata.common.MessageManager;
import com.scudata.common.RQException;
import com.scudata.dm.Context;
import com.scudata.expression.Relation;
import com.scudata.resources.EngineMessage;
import com.scudata.util.Variant;

/**
 * ???????>
 * @author RunQian
 *
 */
public class Greater extends Relation {
	public Greater() {
		priority = PRI_GT;
	}

	/**
	 * ??????ʽ????Ч?ԣ???Ч???׳??쳣
	 */
	public void checkValidity() {
		if (left == null) {
			MessageManager mm = EngineMessage.get();
			throw new RQException("\">\"" + mm.getMessage("operator.missingLeftOperation"));
		} else if (right == null) {
			MessageManager mm = EngineMessage.get();
			throw new RQException("\">\"" + mm.getMessage("operator.missingRightOperation"));
		}
		
		left.checkValidity();
		right.checkValidity();
	}

	public Object calculate(Context ctx) {
		if (Variant.compare(left.calculate(ctx), right.calculate(ctx), true) > 0) {
			return Boolean.TRUE;
		} else {
			return Boolean.FALSE;
		}
	}

	/**
	 * ȡ??ֵ????ֵ?ıȽϹ?ϵ
	 * @return ??????Relation?еij???
	 */
	public int getRelation() {
		return GREATER;
	}
	
	/**
	 * ????????ֵ??λ?ã?ȡ??ֵ????ֵ?ıȽϹ?ϵ
	 * @return ??????Relation?еij???
	 */
	public int getInverseRelation() {
		return LESS;
	}

	/**
	 * ?жϸ?????ֵ??Χ?Ƿ????㵱ǰ????????ʽ
	 * @param ctx ??????????
	 * @return ȡֵ????Relation. -1??ֵ??Χ??û????????????ֵ??0??ֵ??Χ??????????????ֵ??1??ֵ??Χ??ֵ??????????
	 */
	public int isValueRangeMatch(Context ctx) {
		IArray leftArray = left.calculateRange(ctx);
		if (leftArray == null) {
			return PARTICALMATCH;
		}
		
		IArray rightArray = right.calculateRange(ctx);
		if (rightArray instanceof ConstArray) {
			Object value = rightArray.get(1);
			int cmp1 = Variant.compare(leftArray.get(1), value, true);
			
			if (cmp1 <= 0) {
				int cmp2 = Variant.compare(leftArray.get(2), value, true);
				return cmp2 <= 0 ? UNMATCH : PARTICALMATCH;
			} else {
				return ALLMATCH;
			}
		} else if (leftArray instanceof ConstArray) {
			Object value = leftArray.get(1);
			int cmp1 = Variant.compare(value, rightArray.get(1), true);
			
			if (cmp1 <= 0) {
				return UNMATCH;
			} else {
				int cmp2 = Variant.compare(value, rightArray.get(2), true);
				return cmp2 <= 0 ? PARTICALMATCH : ALLMATCH;
			}
		} else {
			// ?޷??????жϵ?ʱ?????????ж?
			return PARTICALMATCH;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy