package dkohl.bayes.probability;

/**
 * An assigned variable
 * 
 * @author Daniel Kohlsdorf
 */
public class Assignment {

	public static final String NOT_ASSIGNED = "NOT_ASSIGNED";

	/**
	 * The variable specifying the domain.
	 */
	private Variable variable;

	/**
	 * The assigned value
	 */
	private String value;

	public Assignment(Variable variable, String value) {
		super();
		this.variable = variable;
		this.value = value;
	}

	/**
	 * Is this assignment a valid one given my domain?
	 * 
	 * @return true if the assignment is valid
	 */
	public boolean valid() {
		for (String outcome : variable.getDomain()) {
			if (outcome.equals(value)) {
				return true;
			}
		}
		return false;
	}

	public Variable getVariable() {
		return variable;
	}

	public void setVariable(Variable variable) {
		this.variable = variable;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(variable);
		sb.append(" = ");
		sb.append(value);
		return sb.toString();
	}
}
