com.ch.odi.common.graphs
Class HashGraph

java.lang.Object
  |
  +--com.ch.odi.common.graphs.HashGraph

public class HashGraph
extends Object
implements Graph

Title: Thread safe implementation of a graph with hashtables. Description: Copyright: Copyright (c) 2002 Ortwin Glück Company:


Constructor Summary
HashGraph()
           
 
Method Summary
 void addConnection(Object node1, Object node2)
          Creates a connection between two nodes in a graph.
 void addNode(Object node, Object neighbour)
          Adds a node to the graph.
 boolean contains(Object node)
          Checks if a node is in the graph.
 List getNeighbours(Object node)
          Gets all nodes connected to the specified node.
 Set getNodes()
          Gets all the nodes in the graph.
 boolean isConnected(Object node1, Object node2)
          Checks if two nodes are connected.
 boolean isEmpty()
          Checks if the graph contains any nodes.
 void removeConnection(Object node1, Object node2)
          Removes a connection between two nodes.
 void removeNode(Object node)
          Removes a node and all its connections from the graph.
 int size()
          Gets the number of nodes in the graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashGraph

public HashGraph()
Method Detail

addNode

public void addNode(Object node,
                    Object neighbour)
             throws GraphException
Adds a node to the graph. If node is already a member of the graph a connection is created and no exception is thrown.
Specified by:
addNode in interface Graph
Parameters:
node - The node to add
neighbour - A neighbour of the new node that is already a member of the graph. If you add a node to an empty graph this parameter is ignored.
Throws:
GraphException - if neighbour was not found in the graph.

removeNode

public void removeNode(Object node)
Removes a node and all its connections from the graph.
Specified by:
removeNode in interface Graph

contains

public boolean contains(Object node)
Checks if a node is in the graph.
Specified by:
contains in interface Graph
Returns:
true if the node was found, false otherwise

isEmpty

public boolean isEmpty()
Checks if the graph contains any nodes.

addConnection

public void addConnection(Object node1,
                          Object node2)
Creates a connection between two nodes in a graph.
Specified by:
addConnection in interface Graph

removeConnection

public void removeConnection(Object node1,
                             Object node2)
                      throws LastConnectionException
Removes a connection between two nodes. If the connection does not exist nothing happens.
Specified by:
removeConnection in interface Graph

getNeighbours

public List getNeighbours(Object node)
Gets all nodes connected to the specified node.
Specified by:
getNeighbours in interface Graph
Tags copied from interface: Graph
Throws:
NoSuchNodeException - if the node was not found.

getNodes

public Set getNodes()
Gets all the nodes in the graph.
Specified by:
getNodes in interface Graph

isConnected

public boolean isConnected(Object node1,
                           Object node2)
Checks if two nodes are connected.
Specified by:
isConnected in interface Graph

size

public int size()
Description copied from interface: Graph
Gets the number of nodes in the graph.
Specified by:
size in interface Graph