public class Node extends GraphObject
Graph
.
Most notably, a node provides access to its adjacent edges (represented by instances of class
Edge
). These can be distinguished into the sets of incoming and outgoing edges.
Iteration over all three sets of edges is provided by means of bidirectional cursors that present a read-only view of
the respective set (getEdgeCursor()
, getInEdgeCursor(Edge)
,
getOutEdgeCursor(Edge)
). Also supported is iteration over all nodes at opposite ends of either incoming
edges or outgoing edges (getPredecessorCursor()
, getSuccessorCursor()
).
The number of overall edges at a node is called its degree
(Degree
), which is the sum of incoming and outgoing edges (InDegree
,
OutDegree
).
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 |
Node(Graph g)
Instantiates a new Node object that will be part of the given graph.
|
Modifier and Type | Method and Description |
---|---|
Node |
createCopy(Graph g)
Creates a copy of this node that will be inserted into the given graph.
|
int |
degree()
Gets the overall number of incoming and outgoing edges at this node.
|
Edge |
firstInEdge()
Gets the first incoming edge at this node, or
null if it does not exist. |
Edge |
firstOutEdge()
Gets the first outgoing edge at this node, or
null if it does not exist. |
Edge |
getEdge(Node opposite)
Returns an edge that connects this node with the given node, if such an edge exists.
|
IEdgeCursor |
getEdgeCursor()
Returns an edge cursor for all incoming and outgoing edges at this node.
|
Edge |
getEdgeFrom(Node source)
Returns an incoming edge that connects the given node with this node, if such an edge exists.
|
IEnumerable<Edge> |
getEdges()
|
Edge |
getEdgeTo(Node target)
Returns an outgoing edge that connects this node with the given node, if such an edge exists.
|
Graph |
getGraph()
Gets the graph this node belongs to.
|
IEdgeCursor |
getInEdgeCursor()
Returns an edge cursor for incoming edges at this node.
|
IEdgeCursor |
getInEdgeCursor(Edge startEdge)
Returns an edge cursor for incoming edges at this node.
|
IEnumerable<Edge> |
getInEdges()
|
INodeCursor |
getNeighborCursor()
Returns a node cursor for all neighbor nodes of this node.
|
IEnumerable<Node> |
getNeighbors()
|
IEdgeCursor |
getOutEdgeCursor()
Returns an edge cursor for outgoing edges at this node.
|
IEdgeCursor |
getOutEdgeCursor(Edge startEdge)
Returns an edge cursor for outgoing edges at this node.
|
IEnumerable<Edge> |
getOutEdges()
|
INodeCursor |
getPredecessorCursor()
Returns a node cursor for all predecessor nodes of this node.
|
IEnumerable<Node> |
getPredecessors()
|
INodeCursor |
getSuccessorCursor()
Returns a node cursor for all successor nodes of this node.
|
IEnumerable<Node> |
getSuccessors()
|
int |
inDegree()
Gets the number of incoming edges at this node.
|
int |
index()
Gets the index of this node within its graph G.
|
Edge |
lastInEdge()
Gets the last incoming edge at this node, or
null if it does not exist. |
Edge |
lastOutEdge()
Gets the last outgoing edge at this node, or
null if it does not exist. |
int |
outDegree()
Gets the number of outgoing edges at this node.
|
void |
sortInEdges(Comparator<Object> c)
Sorts incoming edges at this node according to the given comparator.
|
void |
sortOutEdges(Comparator<Object> c)
Sorts outgoing edges at this node according to the given comparator.
|
String |
toString()
Returns a String representation of this node.
|
protected Node(Graph g)
g
- The graph that the created node will belong to.public Node createCopy(Graph g)
g
- The graph that the created node will belong to.public final int degree()
Note that self-loops are counted twice.
Edge
,
inDegree()
,
outDegree()
public final Edge firstInEdge()
null
if it does not exist.firstOutEdge()
,
lastInEdge()
public final Edge firstOutEdge()
null
if it does not exist.firstInEdge()
,
lastOutEdge()
public final Edge getEdge(Node opposite)
Otherwise null
is returned.
Note that the first matching edge is returned, and that outgoing edges are tested prior to incoming edges.
getEdgeFrom(Node)
,
getEdgeTo(Node)
public final IEdgeCursor getEdgeCursor()
getInEdgeCursor(Edge)
,
getOutEdgeCursor(Edge)
public final Edge getEdgeFrom(Node source)
Otherwise null
is returned.
getEdge(Node)
,
getEdgeTo(Node)
public IEnumerable<Edge> getEdges()
Iterable
for
Edge
s that can be used to iterate over the adjacent edges at this instance.
This is a live enumerable and will thus reflect the current state of the node's adjacency. Note that changes to the graph structure during the traversal should be carried out with great care. Note that self-loop edges are reported twice (as in edge and as out edge).
public final Edge getEdgeTo(Node target)
Otherwise null
is returned.
getEdge(Node)
,
getEdgeFrom(Node)
public final Graph getGraph()
If the node does not belong to a graph, because it was removed or hidden from it, this method returns null
.
public final IEdgeCursor getInEdgeCursor()
If an edge is specified, the cursor starts at the given edge, and the cyclic sequence order is the same as returned by
getInEdgeCursor(Edge)
.
startEdge
is an incoming edge at this node.getOutEdgeCursor(Edge)
public final IEdgeCursor getInEdgeCursor(Edge startEdge)
If an edge is specified, the cursor starts at the given edge, and the cyclic sequence order is the same as returned by
getInEdgeCursor(Edge)
.
startEdge
is an incoming edge at this node.startEdge
- The first edge being accessed by the returned cursor.getOutEdgeCursor(Edge)
public IEnumerable<Edge> getInEdges()
Iterable
for Edge
s that can be used to iterate over ingoing edges at this instance.
This is a live enumerable and will thus reflect the current state of the node's adjacency. Note that changes to the graph structure during the traversal should be carried out with great care. Note that self-loop edges are reported, too.
public final INodeCursor getNeighborCursor()
Neighbor nodes are those at the opposite ends of both incoming and outgoing edges.
getPredecessorCursor()
,
getSuccessorCursor()
public IEnumerable<Node> getNeighbors()
Iterable
for
Node
s that can be used to iterate over the opposite sides of adjacent adjacent edges at this instance.
This is a live enumerable and will thus reflect the current state of the node's adjacency. Note that changes to the graph structure during the traversal should be carried out with great care. Note that for self-loop edges this node itself will be reported as a neighbor, twice.
public final IEdgeCursor getOutEdgeCursor()
If an edge is specified, the cursor starts at the given edge, and the cyclic sequence order is the same as returned by
getOutEdgeCursor(Edge)
.
startEdge
is an outgoing edge at this node.getInEdgeCursor(Edge)
public final IEdgeCursor getOutEdgeCursor(Edge startEdge)
If an edge is specified, the cursor starts at the given edge, and the cyclic sequence order is the same as returned by
getOutEdgeCursor(Edge)
.
startEdge
is an outgoing edge at this node.startEdge
- The first edge being accessed by the returned cursor.getInEdgeCursor(Edge)
public IEnumerable<Edge> getOutEdges()
Iterable
for Edge
s that can be used to iterate over outgoing edges at this instance.
This is a live enumerable and will thus reflect the current state of the node's adjacency. Note that changes to the graph structure during the traversal should be carried out with great care. Note that self-loop edges are reported, too.
public final INodeCursor getPredecessorCursor()
Predecessor nodes are those at the opposite ends of incoming edges.
getSuccessorCursor()
public IEnumerable<Node> getPredecessors()
Iterable
for
Node
s that can be used to iterate over the opposite sides of adjacent incoming edges at this instance.
This is a live enumerable and will thus reflect the current state of the node's adjacency. Note that changes to the graph structure during the traversal should be carried out with great care. Note that for self-loop edges this node itself will be reported as a predecessor.
public final INodeCursor getSuccessorCursor()
Successor nodes are those at the opposite ends of outgoing edges.
getPredecessorCursor()
public IEnumerable<Node> getSuccessors()
Iterable
for
Node
s that can be used to iterate over the opposite sides of adjacent outgoing edges at this instance.
This is a live enumerable and will thus reflect the current state of the node's adjacency. Note that changes to the graph structure during the traversal should be carried out with great care. Note that for self-loop edges this node itself will be reported as a successor.
public final int inDegree()
degree()
,
outDegree()
public final int index()
Node indices represent the ordering of standard node iteration on G. The value of an index is >= 0
and
< G.nodeCount()
.
Note that indices are subject to change whenever the sequence of nodes in a graph is modified by either removing, hiding, reinserting, or unhiding a node, or by explicitly changing its position in the sequence.
Graph.removeNode(Node)
,
Graph.hide(Node)
,
Graph.reInsertNode(Node)
,
Graph.unhide(Node)
,
Graph.moveToFirst(Node)
,
Graph.moveToLast(Node)
public final Edge lastInEdge()
null
if it does not exist.firstInEdge()
,
lastOutEdge()
public final Edge lastOutEdge()
null
if it does not exist.firstOutEdge()
,
lastInEdge()
public final int outDegree()
degree()
,
inDegree()
public final void sortInEdges(Comparator<Object> c)
sortOutEdges(Comparator)
public final void sortOutEdges(Comparator<Object> c)
sortInEdges(Comparator)