lu.cs.co.graph
Class Edge

java.lang.Object
  |
  +--lu.cs.co.graph.Edge
Direct Known Subclasses:
DirectedEdge, UndirectedEdge

public class Edge
extends Object
implements Comparable, Cloneable

This abstract class defines and provides fields and methods for an edge in a graph. The class is cannot be instantiated but is extended by DirectedEdge and UndirectedEdge, which can.


Field Summary
 int len
          The edge's length.
 Vertex u
          The first vertex incident to the edge.
 Vertex v
          The second vertex incident to the edge.
 
Method Summary
 Object clone()
          Returns a clone of this edge.
 int compareTo(Edge e)
          Compares the length of two edges.
 int compareTo(Object o)
          Compares this edge to another object.
 Vertex neighbour(Vertex v)
          The neighbour of a given vertex on this edge.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

u

public Vertex u
The first vertex incident to the edge.

v

public Vertex v
The second vertex incident to the edge.

len

public int len
The edge's length.
Method Detail

clone

public Object clone()
Returns a clone of this edge. The incident vertices are cloned too, so the cloned edge has no vertices in common with the original.
Returns:
a clone of this edge

neighbour

public Vertex neighbour(Vertex v)
The neighbour of a given vertex on this edge. No matter how the edge is oriented, this returns the "other" vertex incident to the edge.

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(Object o)
Compares this edge to another object. If the object is an edge this function behaves like compareTo(Edge). Otherwise, it throws a ClassCastException (as Edges are comparable only to other edges).
Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared
Returns:
-1, 0, or +1, if the argument is longer than, as long as, or shorter than this edge
Throws:
ClassCastException - if the argument is not an edge

compareTo

public int compareTo(Edge e)
Compares the length of two edges.
Parameters:
e - the edge to be compared
Returns:
-1, 0, or +1, if e is longer than, as long as, or shorter than this edge