uk.ed.inf.graph.impl
Class Node

java.lang.Object
  extended by uk.ed.inf.graph.impl.Node
All Implemented Interfaces:
java.lang.Comparable<Node>, IBasicNode<Node,Edge>, IRestorableGraphElement, IUndirectedNode<Node,Edge>

public final class Node
extends java.lang.Object
implements IUndirectedNode<Node,Edge>, IRestorableGraphElement


Constructor Summary
Node(Graph owningGraph, int index)
          Creates a new node belonging to a graph.
 
Method Summary
(package private)  void addEdge(Edge edge)
           
 int compareTo(Node o)
          Compare this node to another node.
 java.util.Iterator<Node> connectedNodeIterator()
          Provides an iterator that lists all nodes connected to this node via another edge.
 java.util.Iterator<Edge> edgeIterator()
          Provides an iterator that lists all edges associated with this node.
 boolean equals(java.lang.Object obj)
          Is the other node equal to this one.
 int getDegree()
          Get the degree of the this node.
 java.util.SortedSet<Edge> getEdgesWith(Node other)
          Gets the edges shared with the other node.
 Graph getGraph()
          Get the graph that owns this node.
 int getIndex()
          Get the index of this node.
 boolean hasEdgeWith(Node other)
          Tests whether this node shares one or more edges with another node, irrespective of the direction of that edge.
 int hashCode()
          Get the hash code for this node.
 boolean isRemoved()
          Has the node been removed from the graph? Nodes are not removed from the graph's data structures, but flagged as deleted.
 void markRemoved(boolean removeFlag)
          Used to reset the removal status of a graph edge or node.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

Node(Graph owningGraph,
     int index)
Creates a new node belonging to a graph. Note the node is not added to the graph in this constructor, this must be done elsewhere. Typically usign a node factory.

Parameters:
owningGraph - The graph to which this node belongs.
index - The identifying index for the node, that can be used to lookup this node from the graph.
Throws:
java.lang.IllegalArgumentException - if owningGraph is null.
java.lang.IllegalArgumentException - if index is negative.
Method Detail

connectedNodeIterator

public java.util.Iterator<Node> connectedNodeIterator()
Description copied from interface: IBasicNode
Provides an iterator that lists all nodes connected to this node via another edge. When self-edges are encountered a reference to this node will be returned. The iterator may return the same node more than once if this node has multiple edges to it.

Specified by:
connectedNodeIterator in interface IBasicNode<Node,Edge>
Returns:
the node iterator.

getDegree

public int getDegree()
Description copied from interface: IBasicNode
Get the degree of the this node. That is the number of edges associated with it. Note that in graph theory self edges (edges that start and finish on the same node) add 2 to the degree of a node.

Specified by:
getDegree in interface IBasicNode<Node,Edge>
Returns:
The degree of the node.

edgeIterator

public java.util.Iterator<Edge> edgeIterator()
Description copied from interface: IBasicNode
Provides an iterator that lists all edges associated with this node. In a directed graph this iterator ignores the direction of the edge.

Specified by:
edgeIterator in interface IBasicNode<Node,Edge>
Returns:
the edge iterator.

getEdgesWith

public java.util.SortedSet<Edge> getEdgesWith(Node other)
Description copied from interface: IBasicNode
Gets the edges shared with the other node.

Specified by:
getEdgesWith in interface IBasicNode<Node,Edge>
Parameters:
other - The other node to test. Cannot be null.
Returns:
A set of edges sorted by edge index, which

getGraph

public Graph getGraph()
Description copied from interface: IBasicNode
Get the graph that owns this node.

Specified by:
getGraph in interface IBasicNode<Node,Edge>
Returns:
The graph instance which cannot be null.

getIndex

public int getIndex()
Description copied from interface: IBasicNode
Get the index of this node.

Specified by:
getIndex in interface IBasicNode<Node,Edge>
Returns:
Returns a whole number (>=0).

hasEdgeWith

public boolean hasEdgeWith(Node other)
Description copied from interface: IBasicNode
Tests whether this node shares one or more edges with another node, irrespective of the direction of that edge.

Specified by:
hasEdgeWith in interface IBasicNode<Node,Edge>
Parameters:
other - The other node to test. Can be null.
Returns:
True if and edge is shared, false otherwise.

addEdge

void addEdge(Edge edge)

compareTo

public int compareTo(Node o)
Description copied from interface: IBasicNode
Compare this node to another node. Comparison should be based on the comparison order of the node's index only. The owning graph should be ignored. It is the job of the graph library to ensure that only nodes belonging to the same graph are compared.

Specified by:
compareTo in interface java.lang.Comparable<Node>
Specified by:
compareTo in interface IBasicNode<Node,Edge>
Parameters:
o - the other node to compare to.

hashCode

public int hashCode()
Description copied from interface: IBasicNode
Get the hash code for this node. Should be consistent with equals.

Specified by:
hashCode in interface IBasicNode<Node,Edge>
Overrides:
hashCode in class java.lang.Object
Returns:
The hash code for this node.

equals

public boolean equals(java.lang.Object obj)
Description copied from interface: IBasicNode
Is the other node equal to this one. Should obey the standard contract for equals, and in addition a node should be regarded as equal if its owning graph and index are identical.

Specified by:
equals in interface IBasicNode<Node,Edge>
Overrides:
equals in class java.lang.Object
Parameters:
obj - the other object to be tested.
Returns:
true if equals by the standard contract and if the owning graph and index are identical. false otherwise.

isRemoved

public boolean isRemoved()
Description copied from interface: IBasicNode
Has the node been removed from the graph? Nodes are not removed from the graph's data structures, but flagged as deleted.

Specified by:
isRemoved in interface IBasicNode<Node,Edge>
Returns:
true if removed, false otherwise.

markRemoved

public void markRemoved(boolean removeFlag)
Description copied from interface: IRestorableGraphElement
Used to reset the removal status of a graph edge or node.

Specified by:
markRemoved in interface IRestorableGraphElement

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object