|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.scheinerman.graph.Edge<E>
public class Edge<E>
This class represents a connection between two vertices. This class keeps track of the two
vertices and the weight of this edge which is the distance between the two vertices. This
edge can be added to a graph in one of several ways. If two vertices exist already in a
Graph
a new edge can be made with both vertices passed to the constructor. After
this the add()
method must be called to add the Edge
to both of
the vertices. Another way to add an edge is two call the Vertex.addEdgeTo(Vertex)
on one vertex to another.
Warning: Calling the Vertex.addEdge(Edge)
only adds
the edge to the specified Vertex
The same method must be called on the other
Vertex
.
Graph}, {@link Vertex}
Constructor Summary | |
---|---|
Edge()
Creates a new edge with no vertices. |
|
Edge(Vertex<E> end1,
Vertex<E> end2)
Creates a new edge with two instantiated vertices. |
Method Summary | |
---|---|
void |
add()
Adds this edge to both of the ends that it encapsulates. |
int |
compareTo(Edge<E> e)
Comparison based on edge weight. |
Vertex<E> |
getEnd1()
Returns the first vertex from the edge. |
Vertex<E> |
getEnd2()
Returns the second vertex from the edge. |
double |
getWeight()
Returns the weight of this edge which is equal to the distance between the two vertices of this edge. |
void |
setEnd1(Vertex<E> end1)
Sets a new first vertex for the edge. |
void |
setEnd2(Vertex<E> end2)
Sets a new second vertex for the edge. |
java.lang.String |
toString()
Returns a string which consists of the numeric values of the two vertices and the weight of the edge. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Edge()
public Edge(Vertex<E> end1, Vertex<E> end2)
end1
- - the first vertexend2
- - the second vertexMethod Detail |
---|
public void add()
public Vertex<E> getEnd1()
public Vertex<E> getEnd2()
public void setEnd1(Vertex<E> end1)
end1
- - the new first vertexpublic void setEnd2(Vertex<E> end2)
end1
- - the new second vertexpublic double getWeight()
public java.lang.String toString()
(End1Val,End2Val):Weight
toString
in class java.lang.Object
Edge
.public int compareTo(Edge<E> e)
compareTo
in interface java.lang.Comparable<Edge<E>>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |