package net.woodyfolsom.msproj.ann2;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;

public class Connection {
	private int src;
	private int dest;
	private double weight;
	private transient double lastDelta = 0.0;
	
	public Connection() {
		//no-arg constructor for JAXB
	}
	
	public Connection(int src, int dest, double weight) {
		this.src = src;
		this.dest = dest;
		this.weight = weight;
	}
	
	public void addDelta(double delta) {
		this.weight += delta;
		this.lastDelta = delta;
	}
	
	@XmlAttribute
	public int getDest() {
		return dest;
	}
	
	@XmlTransient
	public double getLastDelta() {
		return lastDelta;
	}
	
	@XmlAttribute
	public int getSrc() {
		return src;
	}

	@XmlAttribute
	public double getWeight() {
		return weight;
	}
	
	public void setDest(int dest) {
		this.dest = dest;
	}
	
	public void setSrc(int src) {
		this.src = src;
	}
	
	public void setWeight(double weight) {
		this.weight = weight;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + dest;
		result = prime * result + src;
		long temp;
		temp = Double.doubleToLongBits(weight);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Connection other = (Connection) obj;
		if (dest != other.dest)
			return false;
		if (src != other.src)
			return false;
		if (Double.doubleToLongBits(weight) != Double
				.doubleToLongBits(other.weight))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "Connection(" + src + ", " + dest +"), weight: " + weight;
	}
}