package dkohl.bayes.probability;

import com.google.common.base.Preconditions;

/**
 * A probabilistic event
 * 
 * @author Daniel Kohlsdorf
 */
public class Probability {

	/**
	 * The probability for this event
	 */
	private double probability;

	public Probability(double probability) {
		setProbability(probability);
	}

	public double getProbability() {
		return probability;
	}

	/**
	 * Sets this probability to a value p that holds:
	 * 
	 * 0 >= p <= 1, p in R
	 * 
	 * @param probability
	 */
	public void setProbability(double probability) {
		Preconditions.checkArgument(probability <= 1,
				"Probability Error: P >= 1: " + probability);
		Preconditions.checkArgument(probability >= 0,
				"Probability Error: P <= 0: " + probability);
		this.probability = probability;
	}

	/**
	 * Returns the rest of the probability
	 * 
	 * @return 1 - p
	 */
	public Probability rest() {
		return new Probability(1 - probability);
	}

}
