public final class Edge extends Element
On creation of an edge, an arbitrary object can be associated with the edge as the weight of the edge. We say that an edge is unweighted if it does not have an assigned weight. It is an error to attempt to access the weight of an unweighted edge.
Self-loop edges (edges whose source and sink nodes are identical) are allowed.
Once an edge is created, its source node and sink node cannot be changed.
Node
Red (cxh) |
Red (cxh) |
Constructor and Description |
---|
Edge(Node source,
Node sink)
Construct an unweighted edge with a specified source node and sink node.
|
Edge(Node source,
Node sink,
java.lang.Object weight)
Construct a weighted edge with a specified source node, sink node, and
edge weight.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
descriptor()
A one-word description of the type of this graph element.
|
boolean |
isSelfLoop()
Return true if this is a self-loop edge.
|
Node |
sink()
Return the sink node of the edge.
|
Node |
source()
Return the source node of the edge.
|
java.lang.String |
toString()
Return a string representation of the edge, including information
about the edge weight.
|
java.lang.String |
toString(boolean showWeight)
Return a string representation of the edge, optionally including
information about the edge weight.
|
getWeight, hasWeight, removeWeight, setWeight
public Edge(Node source, Node sink)
source
- The source node.sink
- The sink node.public Edge(Node source, Node sink, java.lang.Object weight)
source
- The source node.sink
- The sink node.weight
- The edge weight.java.lang.IllegalArgumentException
- If the specified weight is
null
.public java.lang.String descriptor()
descriptor
in class Element
public boolean isSelfLoop()
public Node sink()
public Node source()
public java.lang.String toString(boolean showWeight)
(source, sink, weight)
,
where source
, sink
, and
weight
are string representations
of the source node, sink node, and edge weight, respectively.
If the edge is unweighted or the showWeight
argument is
false, then the string representation is simply
(source, sink)
.
showWeight
- True to include a string representation of the edge
weight in the string representation of the edge.public java.lang.String toString()
toString
in class java.lang.Object
toString(boolean)