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

panda.el.opt.AbstractOpt Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.el.opt;

import panda.el.ELContext;
import panda.el.ELException;
import panda.el.Operator;
import panda.el.obj.ELObj;

/**
 * abstract class for Operator
 */
public abstract class AbstractOpt implements Operator {
	/**
	 * @return the operator string
	 */
	public abstract String operator();

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		
		if (obj.equals(operator())) {
			return true;
		}
		return super.equals(obj);
	}

	public String toString() {
		return String.valueOf(operator());
	}

	/**
	 * calculate item
	 * @param ec EL Context
	 * @param obj object
	 * @return calculated result
	 */
	protected Object calculateItem(ELContext ec, Object obj) {
		if (obj == null) {
			return null;
		}
		if (obj instanceof Number) {
			return obj;
		}
		if (obj instanceof Boolean) {
			return obj;
		}
		if (obj instanceof String) {
			return obj;
		}
		if (obj instanceof ELObj) {
			return ((ELObj)obj).getObj(ec);
		}
		if (obj instanceof Operator) {
			return ((Operator)obj).calculate(ec);
		}
		throw new ELException("Unknown calculate value: " + obj);

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy