package ps6;
/*
 * Created on Apr 3, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
/**
 * @author knorton
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public abstract class Gate {
	private Message			output;
	private Message				result;
	//private double				dampening = 1.0;
	private boolean				damp = false;
	
	public Gate() {
		this.output = new Message();
	}
	
	public void doDampening() {
		this.damp = true;
	}
	
	public void setValue(Message m) {
		this.output = m;
	}
	
	public Message getValue() {
		return this.output;
	}
	
	private static Message average(Message a, Message b) {
		return new Message(
			(a.getP(0)+b.getP(0))/2.0,
			(a.getP(1)+b.getP(1))/2.0);
	}
	
	public abstract void		update();
	
	public void setResult(Message result) {
		this.result = result;
	}
	
	public void		commit() {
		this.output
			= (this.damp)?average(this.output,this.result):this.result;
	}
}
