package logic;

import check.No;
import check.Result;
import check.Yes;
import model.Trace;

/**
 * An atomic proposition.
 * 
 * @author Franck van Breugel
 */
public final class AtomicProposition extends Formula {
	private String name;

	/**
	 * Initializes this atomic proposition with the given name
	 * 
	 * @param name the name of this atomic proposition
	 * @pre. name != null
	 */
	public AtomicProposition(String name) {
		super();
		this.name = name;
	}

	@Override
	public boolean equals(Object object) {
		if (object != null && this.getClass() == object.getClass()) {
			AtomicProposition other = (AtomicProposition) object;
			return this.name.equals(other.name);
		} else {
			return false;
		}
	}
	
	@Override
	public int hashCode() {
		return this.name.hashCode();
	}
	
	@Override
	public String toString() {
		return this.name;
	}

	@Override
	protected Result isSatisfied(Trace trace, int index) {
		if (trace.get(index).contains(this.name)) {
			return new Yes();
		} else {
			return new No();
		}
	}
}
