// Adapted from Carrano&Savitch, Data Structures and Abstractions With Java

public class Edge implements Comparable {

    private Vertex source; // s (s->d)
    private Vertex dest;   // d
    private int weight; // also called cost

    // Make weighted Edge:
    public Edge(Vertex source, Vertex dest, int weight) {
	this.source=source;
	this.dest=dest;
	this.weight=weight;
    }
    // Make unweighted (0) Edge:
    public Edge(Vertex source, Vertex dest) {
	this(source,dest,0);
    }

    // Getters:
    public Vertex getSource() { return source; }
    public Vertex getDest()   { return dest;   }
    public int getWeight()    { return weight; }

    // Setters:
    public void setSource(Vertex v) { source = v; }
    public void setDest  (Vertex v) { dest = v;   }
    public void setWeight(int w)    { weight = w; }

    // Equals: helps with comparing weights during searches:
    public boolean equals(Object other) {
	Edge e = (Edge) other;
	return weight == e.weight;
    }
    
    // Comparison: helps with comparing weights during searches:
    public int compareTo(Object other) {
	Edge e = (Edge) other;
	return (int) (weight-e.weight);
    }

    // Stringify as (d,--w->,s):
    public String toString() {
	return "("+source+"-"+weight+"->"+dest+")";
    }

}
