Class Graph.Edge<V,E>
java.lang.Object
Graph.Edge<V,E>
- Direct Known Subclasses:
Graph.WeightedEdge
A holder class for Edges that allows each Edge to track the Vertex endpoints
as well as the associated data of the edge.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEdge(Graph.Vertex<V, E> u, Graph.Vertex<V, E> v) Constructs an edge with the specified endpoints.Edge(Graph.Vertex<V, E> u, Graph.Vertex<V, E> v, boolean directed) Constructs an edge with the specified endpoints.Edge(Graph.Vertex<V, E> u, Graph.Vertex<V, E> v, boolean directed, E data) Constructs an edge with the specified endpoints holding the specified data.Edge(Graph.Vertex<V, E> u, Graph.Vertex<V, E> v, E data) Constructs an edge with the specified endpoints holding the specified data. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif the specified object is an edge with the same endpoints and in the same direction (if applicable) as this edge.inthashCode()booleanReturns whether this edge is directed.other(Graph.Vertex<V, E> vertex) Returns the other endpoint of this edge contrasting the specified vertex, ornullif the specified vertex is not an endpoint of this edge.Graph.Edge<V,E> reverse()Returns an edge that is the reverse of this edge.source()Returns the source of this directed edge.target()Returns the target of this directed edge.toString()List<Graph.Vertex<V,E>> vertices()Returns a list containing the vertices in this edge.
-
Field Details
-
data
The data associated with this Edge.
-
-
Constructor Details
-
Edge
Constructs an edge with the specified endpoints.- Parameters:
u- an endpoint of this edgev- an endpoint of this edge
-
Edge
Constructs an edge with the specified endpoints holding the specified data.- Parameters:
u- an endpoint of this edgev- an endpoint of this edgedata- the associated data of this edge
-
Edge
Constructs an edge with the specified endpoints.If directed is
true, the constructed edge becomes a directed edge, whereuis the source of the edge andvis the target of the edge.- Parameters:
u- an endpoint of this edgev- an endpoint of this edgedirected- specified whether this edge is to be directed or undirected
-
Edge
Constructs an edge with the specified endpoints holding the specified data.If directed is true, the constructed edge becomes a directed edge, where
uis the source of the edge andvis the target of the edge.- Parameters:
u- an endpoint of this edgev- an endpoint of this edgedirected- specified whether this edge is to be directed or undirecteddata- the associated data of this edge
-
-
Method Details
-
vertices
Returns a list containing the vertices in this edge.For undirected edges the order is meaningless, but for directed edges the source will be before the target.
- Returns:
- a list containing the vertices in this edge.
-
isDirected
public boolean isDirected()Returns whether this edge is directed.- Returns:
- whether this edge is directed.
-
source
Returns the source of this directed edge.- Returns:
- the source of this directed edge.
- Throws:
UnsupportedOperationException- if this edge is not directed.
-
target
Returns the target of this directed edge.- Returns:
- the target of this directed edge.
- Throws:
UnsupportedOperationException- if this edge is not directed.
-
reverse
Returns an edge that is the reverse of this edge.If this edge is directed, the edge returned by this method will be directed in the opposite direction.
- Returns:
- an edge that is the reverse of this edge.
-
equals
Returnstrueif the specified object is an edge with the same endpoints and in the same direction (if applicable) as this edge.Notably, the data of the edges are not considered.
-
hashCode
public int hashCode() -
other
Returns the other endpoint of this edge contrasting the specified vertex, ornullif the specified vertex is not an endpoint of this edge.- Parameters:
vertex- an endpoint of this edge- Returns:
- the other endpoint of this edge contrasting the specified vertex, or
nullif the specified vertex is not an endpoint of this edge.
-
toString
-