Search this API

y.base
Class Node

java.lang.Object
  extended by y.base.Node

public class Node
extends java.lang.Object

Represents a so-called node in the directed graph data type 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 (edges(), inEdges(), outEdges()). Also supported is iteration over all nodes at opposite ends of either incoming edges or outgoing edges (predecessors(), successors()).

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.

 

Constructor Summary
protected Node(Graph g)
          Instantiates a new Node object that will be part of the given graph.
 
Method Summary
 Node createCopy(Graph g)
          Creates a copy of this node that will be inserted into the given graph.
 int degree()
          Returns the overall number of incoming and outgoing edges at this node.
 EdgeCursor edges()
          Returns an edge cursor for all incoming and outgoing edges at this node.
 Edge firstInEdge()
          Returns the first incoming edge at this node, or null if it does not exist.
 Edge firstOutEdge()
          Returns 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.
 Edge getEdgeFrom(Node source)
          Returns an incoming edge that connects the given node with this node, if such an edge exists.
 Edge getEdgeTo(Node target)
          Returns an outgoing edge that connects this node with the given node, if such an edge exists.
 Graph getGraph()
          Returns the graph this node belongs to.
 int inDegree()
          Returns the number of incoming edges at this node.
 int index()
          Returns the index of this node within its graph G.
 EdgeCursor inEdges()
          Returns an edge cursor for all incoming edges at this node.
 EdgeCursor inEdges(Edge startEdge)
          Returns an edge cursor for incoming edges at this node.
 Edge lastInEdge()
          Returns the last incoming edge at this node, or null if it does not exist.
 Edge lastOutEdge()
          Returns the last outgoing edge at this node, or null if it does not exist.
 NodeCursor neighbors()
          Returns a node cursor for all neighbor nodes of this node.
 int outDegree()
          Returns the number of outgoing edges at this node.
 EdgeCursor outEdges()
          Returns an edge cursor for all outgoing edges at this node.
 EdgeCursor outEdges(Edge startEdge)
          Returns an edge cursor for outgoing edges at this node.
 NodeCursor predecessors()
          Returns a node cursor for all predecessor nodes of this node.
 void sortInEdges(java.util.Comparator c)
          Sorts incoming edges at this node according to the given comparator.
 void sortOutEdges(java.util.Comparator c)
          Sorts outgoing edges at this node according to the given comparator.
 NodeCursor successors()
          Returns a node cursor for all successor nodes of this node.
 java.lang.String toString()
          Returns a String representation of this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

protected Node(Graph g)
Instantiates a new Node object that will be part of the given graph.

Parameters:
g - The graph that the created node will belong to.
Method Detail

createCopy

public Node createCopy(Graph g)
Creates a copy of this node that will be inserted into the given graph.

Parameters:
g - The graph that the created node will belong to.
Returns:
The newly created Node object.

degree

public int degree()
Returns the overall number of incoming and outgoing edges at this node.

Note that self-loops are counted twice.

See Also:
Edge, inDegree(), outDegree()

inDegree

public int inDegree()
Returns the number of incoming edges at this node.

See Also:
degree(), outDegree()

outDegree

public int outDegree()
Returns the number of outgoing edges at this node.

See Also:
degree(), inDegree()

index

public int index()
Returns the index of this node within its graph G. 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.

Precondition:
This node must belong to some graph.
See Also:
Graph.removeNode(Node), Graph.hide(Node), Graph.reInsertNode(Node), Graph.unhide(Node), Graph.moveToFirst(Node), Graph.moveToLast(Node)

getGraph

public Graph getGraph()
Returns the graph this node belongs to. If the node does not belong to a graph, because it was removed or hidden from it, this method returns null.


firstOutEdge

public Edge firstOutEdge()
Returns the first outgoing edge at this node, or null if it does not exist.

See Also:
firstInEdge(), lastOutEdge()

firstInEdge

public Edge firstInEdge()
Returns the first incoming edge at this node, or null if it does not exist.

See Also:
firstOutEdge(), lastInEdge()

lastOutEdge

public Edge lastOutEdge()
Returns the last outgoing edge at this node, or null if it does not exist.

See Also:
firstOutEdge(), lastInEdge()

lastInEdge

public Edge lastInEdge()
Returns the last incoming edge at this node, or null if it does not exist.

See Also:
firstInEdge(), lastOutEdge()

edges

public EdgeCursor edges()
Returns an edge cursor for all incoming and outgoing edges at this node.

See Also:
inEdges(), outEdges()

inEdges

public EdgeCursor inEdges()
Returns an edge cursor for all incoming edges at this node.

See Also:
edges(), outEdges()

inEdges

public EdgeCursor inEdges(Edge startEdge)
Returns an edge cursor for incoming edges at this node. The cursor starts at the given edge, and the cyclic sequence order is the same as returned by inEdges().

Precondition:
startEdge is an incoming edge at this node.
Parameters:
startEdge - The first edge being accessed by the returned cursor.
See Also:
outEdges(Edge)

outEdges

public EdgeCursor outEdges()
Returns an edge cursor for all outgoing edges at this node.

See Also:
edges(), inEdges()

outEdges

public EdgeCursor outEdges(Edge startEdge)
Returns an edge cursor for outgoing edges at this node. The cursor starts at the given edge, and the cyclic sequence order is the same as returned by outEdges().

Precondition:
startEdge is an outgoing edge at this node.
Parameters:
startEdge - The first edge being accessed by the returned cursor.
See Also:
inEdges(Edge)

neighbors

public NodeCursor neighbors()
Returns a node cursor for all neighbor nodes of this node. Neighbor nodes are those at the opposite ends of both incoming and outgoing edges.

See Also:
predecessors(), successors()

predecessors

public NodeCursor predecessors()
Returns a node cursor for all predecessor nodes of this node. Predecessor nodes are those at the opposite ends of incoming edges.

See Also:
successors()

successors

public NodeCursor successors()
Returns a node cursor for all successor nodes of this node. Successor nodes are those at the opposite ends of outgoing edges.

See Also:
predecessors()

getEdgeTo

public Edge getEdgeTo(Node target)
Returns an outgoing edge that connects this node with the given node, if such an edge exists. Otherwise null is returned.

See Also:
getEdge(Node), getEdgeFrom(Node)

getEdgeFrom

public Edge getEdgeFrom(Node source)
Returns an incoming edge that connects the given node with this node, if such an edge exists. Otherwise null is returned.

See Also:
getEdge(Node), getEdgeTo(Node)

getEdge

public Edge getEdge(Node opposite)
Returns an edge that connects this node with the given node, if such an edge exists. Otherwise null is returned.

Note that the first matching edge is returned, and that outgoing edges are tested prior to incoming edges.

See Also:
getEdgeFrom(Node), getEdgeTo(Node)

sortInEdges

public void sortInEdges(java.util.Comparator c)
Sorts incoming edges at this node according to the given comparator.

See Also:
sortOutEdges(Comparator)

sortOutEdges

public void sortOutEdges(java.util.Comparator c)
Sorts outgoing edges at this node according to the given comparator.

See Also:
sortInEdges(Comparator)

toString

public java.lang.String toString()
Returns a String representation of this node.

Overrides:
toString in class java.lang.Object

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.