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

net.sf.gluebooster.java.booster.basic.math.Operator Maven / Gradle / Ivy

package net.sf.gluebooster.java.booster.basic.math;

import net.sf.gluebooster.java.booster.essentials.objects.BoostedObject;
import net.sf.gluebooster.java.booster.essentials.utils.TextBoostUtils;

/**
 * An operator.
 * 
 * @author cbauer
 *
 * @param 
 */
public class Operator extends BoostedObject {

	/**
	 * The level of abstraction of this operator
	 */
	private int abstractionLevel;

	/**
	 * Can this operator be split into more other operators? True, if not.
	 */
	private boolean elementary = false;

	public Operator() {

	}

	/**
	 * 
	 * @param name
	 *            the name of the operation.
	 */
	public Operator(Object name, int abstractionLevel) {
		setName(name);
		setAbstractionLevel(abstractionLevel);
	}

	/**
	 * 
	 * @param name
	 *            the name of the operation.
	 */
	public Operator(Object name, int abstractionLevel, boolean elementary) {
		this(name, abstractionLevel);
		setElementary(elementary);
	}

	public void setElementary(boolean elementary) {
		this.elementary = elementary;
	}

	public int getAbstractionLevel() {
		return abstractionLevel;
	}

	public void setAbstractionLevel(int abstractionLevel) {
		this.abstractionLevel = abstractionLevel;
	}


	@Override
	public boolean equals(Object obj) {
		return obj != null && obj instanceof Operator
				&& (getName().equals(((Operator) obj).getName()));
	}

	@Override
	public int hashCode() {
		Object name = getName();
		return name == null ? null : name.hashCode();
	}

	@Override
	public String toString() {

		return getName().toString();
	}

	/**
	 * Tests if this operator is the operator of a given node
	 * 
	 * @param node
	 *            the node which operator is to be compared.
	 * @return true if equals
	 */
	public boolean isOperatorOf(Operation node) {
		return equals(node.getOperator());
	}

	public boolean isElementary() {
		return elementary;
	}

	/**
	 * Has this operator a given name
	 * 
	 * @param name
	 *            the name to compare
	 * @return true if this name equals name
	 */
	public boolean hasName(Object name) {
		return name.equals(getName());
	}

	@Override
	public String asSourcecode(StringBuilder result, Object... parameters)
			throws Exception {
		String name = super.asSourcecode(result, parameters);
		TextBoostUtils.append(result, name, ".setAbstractionLevel(",
				abstractionLevel, ");\n");

		TextBoostUtils.append(result, name, ".setElementary(", elementary,
				");\n");

		return name;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy