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

cz.vutbr.web.csskit.TermImpl Maven / Gradle / Ivy

package cz.vutbr.web.csskit;

import cz.vutbr.web.css.Term;

/**
 * Term
 * 
 * @author Karel Piwko, 2008
 */
public class TermImpl implements Term {

	protected T value;
	protected Operator operator = null;

	protected TermImpl() {
	}
	
	public Operator getOperator() {
		return operator;
	}

	public Term setOperator(Operator operator) {
		this.operator = operator;
		return this;
	}

	/**
	 * @return the value
	 */
	public T getValue() {
		return value;
	}

	/**
	 * @param value
	 *            the value to set
	 */
	public Term setValue(T value) {
		this.value = value;
		return this;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		if(operator != null) sb.append(operator.value());
		if(value!=null) sb.append(value.toString());

		return sb.toString();
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((operator == null) ? 0 : operator.hashCode());
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof TermImpl))
			return false;
		@SuppressWarnings("unchecked")
		TermImpl other = (TermImpl) obj;
		if (operator == null) {
			if (other.operator != null)
				return false;
		} else if (!operator.equals(other.operator))
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}

	@SuppressWarnings("unchecked")
    public Term shallowClone() {
		try {
			return (Term) super.clone();
		} catch (CloneNotSupportedException e) {
			throw new RuntimeException(e);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy