package edu.umich.soar.hpp;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

/**
 * Class that holds information to describe a sparse
 * conditional-probability table (CPT).
 * 
 * Each entry expresses a distribution over variable values
 * given that a set of conditions hold.
 */
public class HPPCPTEntry {
	
	/**
	 * Supports read-only access to condition set
	 * 
	 * @return iterator to condition set
	 */
	public Iterator<HPPConstraint> getConditions() {
		return myConditions.iterator();
	}
		
	/**
	 * Supports read-only access to value distribution
	 * 
	 * @return iterator to value distribution
	 */
	public Iterator<HPPCPTValue> getValues() {
		return myValues.iterator();
	}
	
	/**
	 * Appends a condition to the set
	 * 
	 * @param newCondition condition to be added to the set
	 */
	public void addCondition(HPPConstraint newCondition) {
		myConditions.add(newCondition);
	}
	
	/**
	 * Appends a value to the distribution
	 * 
	 * @param newValue value to be added to the set
	 */
	public void addValue(HPPCPTValue newValue) {
		myValues.add(newValue);
	}
	
	
	/**
	 * Basic constructor - empty initialization for conditions/values
	 */
	public HPPCPTEntry() {
		myConditions = new TreeSet<HPPConstraint>();
		myValues = new TreeSet<HPPCPTValue>();
	}	
	
	/**
	 * Advanced constructor - supports custom initialization of conditions/values
	 * 
	 * @param conditions initial conditions, null to ignore
	 * @param values initial value distribution, null to ignore
	 */
	public HPPCPTEntry(HPPConstraint[] conditions, HPPCPTValue[] values) {
		this();
		
		if (conditions != null) {
			for (HPPConstraint c : conditions) {
				addCondition(c);
			}
		}
		
		if (values != null) {
			for (HPPCPTValue v : values) {
				addValue(v);
			}
		}
	}
	
	private final Set<HPPConstraint> myConditions;
	private final Set<HPPCPTValue> myValues;
}
