public class Edge extends java.lang.Object implements java.lang.Comparable<Edge>
Edge
class.
This class models an undirected edge for a graph. The edge has two
vertices and a length. The length is the Euclidean distance between the
two vertices of the Edge. Edges are sorted by length using the comparable
interface.
To associate a different cost to the edge (other than length) you can use
the setCost() method, which will overwrite the length field with the
new cost.Constructor and Description |
---|
Edge(Vertex a,
Vertex b)
This is the constructor for edge objects.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Edge otherEdge)
This is the method inhereted from the Comparable interface.
|
float |
getLength()
Returns the length of the edge.
|
Vertex |
getVertexA()
Getter for Vertex A.
|
Vertex |
getVertexB()
Getter for Vertex B.
|
boolean |
isIncidentTo(Vertex v)
Tests whether this
Edge is incident to
the given Vertex . |
void |
setCost(float cost)
This allows you to associate a cost with the edge.
|
void |
setVertexA(Vertex vertex)
Setter for Vertex A.
|
void |
setVertexB(Vertex vertex)
Setter for Vertex B.
|
public Vertex getVertexA()
public Vertex getVertexB()
public void setVertexA(Vertex vertex)
vertex
- the new Vertex
.public void setVertexB(Vertex vertex)
vertex
- the new Vertex
.public float getLength()
public boolean isIncidentTo(Vertex v)
Edge
is incident to
the given Vertex
.v
- the Vertex
to be tested.Vertex
is incident to this
Edge
.public void setCost(float cost)
cost
- the new cost for the edge.public int compareTo(Edge otherEdge)
Edge
to the length of the other Edge
.compareTo
in interface java.lang.Comparable<Edge>
otherEdge
- the other Edge
to compare with this one.Edge
is shorter than the other
Edge
, 1 if this Edge
is longer, and 0 if
the two Edges are the same length.