package edu.umich.soar.hpp;


/**
 * Qualitative constraint - name/value combination
 */
public class HPPConstraint implements Comparable<HPPConstraint> {
		
	/**
	 * Supports read-only access to the constraint name
	 * 
	 * @return constraint name
	 */
	public String getName() {
		return myName;
	}
	
	/**
	 * Supports read-only access to the constraint value
	 * 
	 * @return constraint value
	 */
	public String getValue() {
		return myValue;
	}	
	
	/**
	 * Basic constructor
	 * 
	 * @param name constraint name
	 * @param value constraint value
	 */
	public HPPConstraint(String name, String value) {
		myName = name;
		myValue = value;
	}
	
	/**
	 * Utility constructor - takes the name of an existing variable
	 * 
	 * @param variable source of constraint name
	 * @param value constraint value
	 */
	public HPPConstraint(HPPVariable variable, String value) {
		this(variable.getName(), value);
	}	
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return ( myName + "=" + myValue );
	}
	
	/**
	 * Utility function to perform qualitative equivalence test
	 * 
	 * @param varName variable name
	 * @param varValue variable value
	 * @return true if both name and value are equal to constraint name/value
	 */
	public boolean satisfiedBy(String varName, String varValue) {
		return ( ( getName().compareTo(varName)==0 ) && ( getValue().compareTo(varValue)==0 ) );
	}	
	
	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	public int compareTo(HPPConstraint o) {
		return ( ( satisfiedBy(o.getName(), o.getValue()) )?(0):(1) );
	}
	
	private final String myName;
	private final String myValue;
}
