com.ch.odi.common.graphs
Interface Graph

All Known Implementing Classes:
HashGraph

public interface Graph

Description: A graph consists of interconnected nodes. A node must be connected to at least one other node (neighbour). All nodes in a graph are connected so that there are no islands. A single node without any connections is a valid graph. A graph without nodes is a valid graph. Copyright: Copyright (c) 2002 Ortwin Glück


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.
 void removeConnection(Object node1, Object node2)
          Removes a connection between two nodes.
 void removeNode(Object node)
          Removes a node an all its connections from the graph.
 int size()
          Gets the number of nodes in the graph.
 

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.
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 an all its connections from the graph.

contains

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

addConnection

public void addConnection(Object node1,
                          Object node2)
Creates a connection between two nodes in a graph.

removeConnection

public void removeConnection(Object node1,
                             Object node2)
                      throws LastConnectionException
Removes a connection between two nodes.

getNeighbours

public List getNeighbours(Object node)
Gets all nodes connected to the specified node.
Throws:
NoSuchNodeException - if the node was not found.

getNodes

public Set getNodes()
Gets all the nodes in the graph.

isConnected

public boolean isConnected(Object node1,
                           Object node2)
Checks if two nodes are connected.

size

public int size()
Gets the number of nodes in the graph.