spiglet.translate.graph
Class Node

java.lang.Object
  extended by spiglet.translate.graph.Node

public class Node
extends java.lang.Object

This class represents a node that belongs to a Graph. Each node stores a reference to the graph in which it is defined, as well as the list of successor and predecessor nodes (representing directed edges). Each graph only stores the minimal information about its node. To store extra information about what each node represents, external device is employed (hash mapping, for instance).

Author:
Santoso Wijaya

Field Summary
protected  Graph graph
          A reference to the graph this node belongs to.
protected  java.util.Set<Node> predecessors
          The set of all nodes that edges pointing to this node comes from.
protected  java.util.Set<Node> successors
          The set of nodes that edges coming out of this node points to.
 
Constructor Summary
protected Node(Graph g)
          Creates a new node, with the given graph in which it is to be defined.
 
Method Summary
 boolean adjacent(Node n)
          Returns true if this node and the given node are adjacent to each other.
 int degree()
          Returns the number of of successors plus predecessors this node has
 boolean from(Node n)
          Returns true if there is a directed edge from the given node to this node.
 java.util.Set<Node> getAdjacent()
          Returns the set of all nodes adjacent to this node (direction blind).
 java.util.Set<Node> getPredecessors()
          Returns the set (unmodifiable) of all predecessor nodes (nodes that edges pointing to this node comes from) to this node.
 java.util.Set<Node> getSuccessors()
          Returns the set (unmodifiable) of all successor nodes (nodes that edges coming out of this node points to) to this node.
 int inDegree()
          Returns the number of predecessors this node has
 int outDegree()
          Returns the number of successors this node has
protected static void resetCounter()
          Resets the static counter that numbers newly created nodes.
 boolean to(Node n)
          Returns true if there is a directed edge from this node to the given node.
 java.lang.String toString()
          String representation of this node is its unique key number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

graph

protected Graph graph
A reference to the graph this node belongs to.


successors

protected java.util.Set<Node> successors
The set of nodes that edges coming out of this node points to.


predecessors

protected java.util.Set<Node> predecessors
The set of all nodes that edges pointing to this node comes from.

Constructor Detail

Node

protected Node(Graph g)
Creates a new node, with the given graph in which it is to be defined.

Parameters:
g - the graph that this node would belong to
Method Detail

getSuccessors

public java.util.Set<Node> getSuccessors()
Returns the set (unmodifiable) of all successor nodes (nodes that edges coming out of this node points to) to this node.

Returns:
an unmodifiable set of all successor nodes to this node

getPredecessors

public java.util.Set<Node> getPredecessors()
Returns the set (unmodifiable) of all predecessor nodes (nodes that edges pointing to this node comes from) to this node.

Returns:
an unmodifiable set of all predecessor nodes to this node

getAdjacent

public java.util.Set<Node> getAdjacent()
Returns the set of all nodes adjacent to this node (direction blind).

Returns:
an unmodifiable set of all the nodes adjacent to this node

inDegree

public int inDegree()
Returns the number of predecessors this node has

Returns:
the number of predecessor nodes

outDegree

public int outDegree()
Returns the number of successors this node has

Returns:
the number of successor nodes

degree

public int degree()
Returns the number of of successors plus predecessors this node has

Returns:
the number of successor plus predecessor nodes

to

public boolean to(Node n)
Returns true if there is a directed edge from this node to the given node.

Parameters:
n - the destination node
Returns:
true if there exists a directed edge between this node and the given node

from

public boolean from(Node n)
Returns true if there is a directed edge from the given node to this node.

Parameters:
n - the source node
Returns:
true if there exists a directed edge between the given node and this node.

adjacent

public boolean adjacent(Node n)
Returns true if this node and the given node are adjacent to each other.

Parameters:
n - the potential neighbor node
Returns:
true if the given node and this node are neighbors

toString

public java.lang.String toString()
String representation of this node is its unique key number.

Overrides:
toString in class java.lang.Object
Returns:
the node's unique key number

resetCounter

protected static void resetCounter()
Resets the static counter that numbers newly created nodes.