public class Edge extends GraphObject
Node
) in
the directed graph data type Graph
.
The directed stems from the fact that an edge has a distinct source node and a distinct target node. Using
pair notation, an edge would be written as (<source node>, <target node>).
Most notably, an edge provides access to its source node
(Source
) and its target node (Target
). Note that an edge can have the same node as
its source and target. Such an edge is then called "self-loop" and method SelfLoop
yields
true
.
Important: Class Graph is the single authority for any structural changes to the graph data type. Specifically, this means that there is no way to create or delete a node or an edge without using an actual Graph instance.
Modifier | Constructor and Description |
---|---|
protected |
Edge(Graph g,
Node v,
Edge e1,
Node w,
Edge e2,
GraphElementInsertion d1,
GraphElementInsertion d2)
Creates a new edge that belongs to the given graph.
|
Modifier and Type | Method and Description |
---|---|
Edge |
createCopy(Graph g,
Node v,
Node w)
Creates a copy of this edge that will be inserted into the given graph connecting the given source and target nodes.
|
Graph |
getGraph()
Gets the graph this edge belongs to.
|
int |
index()
Gets the index of this edge within its graph G.
|
boolean |
isSelfLoop()
Gets
true if and only if this edge is a self-loop. |
Edge |
nextInEdge()
Gets the successor of this edge in the list of incoming edges at its target node.
|
Edge |
nextOutEdge()
Gets the successor of this edge in the list of outgoing edges at its source node.
|
protected void |
onReinsert()
Callback method that is invoked from a graph just before this edge will be reinserted into that graph.
|
Node |
opposite(Node v)
Returns the node at the opposite edge end with respect to the given node.
|
Edge |
prevInEdge()
Gets the predecessor of this edge in the list of incoming edges at its target node.
|
Edge |
prevOutEdge()
Gets the predecessor of this edge in the list of outgoing edges at its source node.
|
Node |
source()
Gets the source node connected to this edge.
|
Node |
target()
Gets the target node connected to this edge.
|
String |
toString()
Returns a String representation of this edge.
|
protected Edge(Graph g, Node v, Edge e1, Node w, Edge e2, GraphElementInsertion d1, GraphElementInsertion d2)
The new edge e
has source node v
and target node w
.
Edge e
is inserted in such a way that an iteration over the edges at node v
returns e
e1
, if d1 == AFTER
e1
, if d1 == BEFORE
,
and an iteration over the edges at w
returns e
e2
, if d2 == AFTER
e2
, if d2 == BEFORE
.e1
must have source node v
and edge e2
must have target node w
.v
- The source node of the edge.e1
- An edge with source node v
.w
- The target node of the edge.e2
- An edge with target node w
.d1
- One of the object insertion specifiers GraphElementInsertion.BEFORE
or GraphElementInsertion.AFTER
.d2
- One of the object insertion specifiers GraphElementInsertion.BEFORE
or GraphElementInsertion.AFTER
.public Edge createCopy(Graph g, Node v, Node w)
g
- The graph the created edge will belong to.v
- The source node of the created edge.w
- The target node of the created edge.public final Graph getGraph()
If the edge does not belong to a graph, because it was removed or hidden from it, this method returns null
.
public final int index()
Edge indices represent the ordering of standard edge iteration on G. The value of an index is >= 0
and
< G.edgeCount()
.
Note that indices are subject to change whenever the sequence of edges in a graph is modified by either removing, hiding, reinserting, or unhiding an edge, or by explicitly changing its position in the sequence.
Graph.removeEdge(Edge)
,
Graph.hide(Edge)
,
Graph.reInsertEdge(Edge)
,
Graph.unhide(Edge)
,
Graph.moveToFirst(Edge)
,
Graph.moveToLast(Edge)
public final boolean isSelfLoop()
true
if and only if this edge is a self-loop.
An edge is called a self-loop, if it is adjacent to only one node, i.e., source node and target node are the same.
public final Edge nextInEdge()
If this edge is the last incoming edge at its target node, then null
is returned.
prevInEdge()
,
nextOutEdge()
public final Edge nextOutEdge()
If this edge is the last outgoing edge at its source node, then null
is returned.
prevOutEdge()
,
nextInEdge()
protected void onReinsert()
public final Node opposite(Node v)
Note that self-loops have the same node at both edge ends.
public final Edge prevInEdge()
If this edge is the first incoming edge at its target node, then null
is returned.
nextInEdge()
,
prevOutEdge()
public final Edge prevOutEdge()
If this edge is the first outgoing edge at its source node, then null
is returned.
nextOutEdge()
,
prevInEdge()
public final Node source()
target()
public final Node target()
source()