sofya.graphs
Class Node

java.lang.Object
  extended by sofya.graphs.Node
All Implemented Interfaces:
SConstants
Direct Known Subclasses:
Block

public class Node
extends java.lang.Object
implements SConstants

Class to represent a node in a graph. Every node has an ID, a list of predecessors, and a list of of successors.

A node P is a predecessor to this node if there is an edge from P to this node. A node S is a successor to this node if there is an edge from this node to S.

Version:
09/22/2004
Author:
Alex Kinneer
See Also:
Graph

Nested Class Summary
 
Nested classes/interfaces inherited from interface sofya.base.SConstants
SConstants.BlockLabel, SConstants.BlockObjectType, SConstants.BlockSubType, SConstants.BlockType, SConstants.BranchObjectType, SConstants.BranchType, SConstants.EDObjectType, SConstants.TraceObjectType
 
Field Summary
protected  int nodeID
          The node's unique ID.
protected  java.util.List predecessors
          Collection of the node's predecessors.
protected  java.util.List successors
          Collection of the node's successors.
static Node[] ZL_ARRAY
          Zero-length node array useful for specifying array cast types to methods such getSuccessors(Node[]).
 
Fields inherited from interface sofya.base.SConstants
DEFAULT_PORT, INST_COMPATIBLE, INST_OLD_UNSUPPORTED, INST_OPT_NORMAL, INST_OPT_SEQUENCE, SIG_CHKALIVE, SIG_ECHO
 
Constructor Summary
Node()
          Creates a new node with ID zero.
Node(int id)
          Creates a new node with a given ID.
 
Method Summary
 void addPredecessor(Node n)
          Adds a node to this node's predecessor list.
 void addSuccessor(Node n)
          Adds a node to this node's successor list.
 int getID()
          Gets this node's ID.
 int getPredecessorCount()
          Gets the number of predecessors to this node.
 Node[] getPredecessors()
          Gets this node's predecessor list.
 Node[] getPredecessors(Node[] a)
          Gets this node's predecessors in a type-specific array.
 java.util.List getPredecessorsList()
          Gets this node's predecessors as a java.util.List (unmodifiable).
 int getSuccessorCount()
          Gets the number of successors of this node.
 Node[] getSuccessors()
          Gets this node's successor list.
 Node[] getSuccessors(Node[] a)
          Gets this node's successors in a type-specific array.
 java.util.List getSuccessorsList()
          Gets this node's successors as a java.util.List (unmodifiable).
static void main(java.lang.String[] args)
          Test driver for the Node class.
 void removePredecessor(Node n)
          Removes a node from this node's predecessor list.
 void removeSuccessor(Node n)
          Removes a node from this node's successor list.
 void setID(int n)
          Sets this node's ID.
 java.lang.String toString()
          Returns a string representation of this node, which consists of the node's ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nodeID

protected int nodeID
The node's unique ID.


successors

protected java.util.List successors
Collection of the node's successors.


predecessors

protected java.util.List predecessors
Collection of the node's predecessors.


ZL_ARRAY

public static final Node[] ZL_ARRAY
Zero-length node array useful for specifying array cast types to methods such getSuccessors(Node[]).

Constructor Detail

Node

public Node()
Creates a new node with ID zero.


Node

public Node(int id)
Creates a new node with a given ID.

Method Detail

setID

public void setID(int n)
Sets this node's ID.

Parameters:
n - ID to be assigned to this node.

getID

public int getID()
Gets this node's ID.

Returns:
The ID assigned to this node.

addSuccessor

public void addSuccessor(Node n)
Adds a node to this node's successor list.

Parameters:
n - Node to be added to the successor list.

removeSuccessor

public void removeSuccessor(Node n)
Removes a node from this node's successor list.

Parameters:
n - Node to be removed from the successor list.

getSuccessors

public Node[] getSuccessors()
Gets this node's successor list.

Returns:
An array of this node's sucessors.

getSuccessors

public Node[] getSuccessors(Node[] a)
Gets this node's successors in a type-specific array.

Parameters:
a - Array which will be used to determine the runtime type of the array returned by this method.
Returns:
An array of this node's sucessors.

getSuccessorsList

public java.util.List getSuccessorsList()
Gets this node's successors as a java.util.List (unmodifiable).

Returns:
A list of this node's successors.

addPredecessor

public void addPredecessor(Node n)
Adds a node to this node's predecessor list.

Parameters:
n - Node to be added to the predecessor list.

removePredecessor

public void removePredecessor(Node n)
Removes a node from this node's predecessor list.

Parameters:
n - Node to be removed from the predecessor list.

getPredecessors

public Node[] getPredecessors()
Gets this node's predecessor list.

Returns:
An array of this node's predecessors.

getPredecessors

public Node[] getPredecessors(Node[] a)
Gets this node's predecessors in a type-specific array.

Parameters:
a - Array which will be used to determine the runtime type of the array returned by this method.
Returns:
An array of this node's sucessors.

getPredecessorsList

public java.util.List getPredecessorsList()
Gets this node's predecessors as a java.util.List (unmodifiable).

Returns:
A list of this node's predecessors.

getPredecessorCount

public int getPredecessorCount()
Gets the number of predecessors to this node.

Returns:
The number of nodes which are the source of a directed edge to this node (only immediate predecessors are counted).

getSuccessorCount

public int getSuccessorCount()
Gets the number of successors of this node.

Returns:
The number of nodes which are the target of a directed edge from this node (only immediate successors are counted).

toString

public java.lang.String toString()
Returns a string representation of this node, which consists of the node's ID.

Overrides:
toString in class java.lang.Object
Returns:
The node's ID as a string.

main

public static void main(java.lang.String[] args)
Test driver for the Node class.