uk.ed.inf.graph.impl
Class Graph

java.lang.Object
  extended by uk.ed.inf.graph.impl.Graph
All Implemented Interfaces:
IBasicGraph<Node,Edge>, IModifiableGraph<Node,Edge>, IRestorableGraph<Node,Edge>, IUndirectedGraph<Node,Edge>

public final class Graph
extends java.lang.Object
implements IUndirectedGraph<Node,Edge>, IRestorableGraph<Node,Edge>, IModifiableGraph<Node,Edge>


Constructor Summary
Graph()
           
Graph(Graph other)
           
 
Method Summary
(package private)  void addNewNode(Node newNode)
           
 boolean canCopyHere(IBasicSubgraph<? extends Node,? extends Edge> subGraph)
          Tests whether the subGraph can be copied to this graph.
 boolean canCreateEdges()
           
 boolean canCreateNodes()
           
 boolean canCreateSubgraphs()
           
 boolean canRemoveSubgraphs()
           
 boolean containsConnection(IBasicPair<? extends Node,? extends Edge> ends)
          Tests if the graph has an edge between the defined ends.
 boolean containsConnection(Node thisNode, Node thatNode)
          Tests if the graph contains an edge connecting these nodes.
 boolean containsEdge(Edge edge)
          Tests if the graph contains the edge.
 boolean containsEdge(int edgeIdx)
          Tests if the graph contains the edge of the given index.
 boolean containsNode(int nodeIdx)
          Tests if the graph contains the node with the given index number.
 boolean containsNode(Node node)
          Tests if this node exists in the graph.
 void copyHere(IBasicSubgraph<? extends Node,? extends Edge> subGraph)
          Copies a subgraph into this graph.
 EdgeFactory edgeFactory()
          Gets the edgeFactory for this class.
 java.util.Iterator<Edge> edgeIterator()
          Get an iterator that traverses all the edges in this graph.
 Subgraph getCopiedComponents()
          Retrieves the nodes and edges created in this graph by the last copy operation.
 IGraphState<Node,Edge> getCurrentState()
          Get the current state of the graph as a momento.
 Edge getEdge(int edgeIdx)
          Get the edge with this index.
 Node getNode(int index)
          Get the node matching the nodeIdx.
 int getNumEdges()
          Get the number of edges in the graph.
 int getNumNodes()
          Get the number of nodes in the graph.
 NodeFactory nodeFactory()
          Gets the nodeFactory for this class.
 java.util.Iterator<Node> nodeIterator()
          Get an iterator that traverses all the nodes in this graph.
 void removeSubgraph(IBasicSubgraph<? extends Node,? extends Edge> subgraph)
          Removes the nodes and edges defined in the subgraph from this graph.
 void restoreState(IGraphState<Node,Edge> previousState)
          Restores the graph state to the state stored by the previousState object.
 SubgraphFactory subgraphFactory()
          Gets the subgraphFactory for this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph

public Graph()

Graph

public Graph(Graph other)
Method Detail

getNode

public Node getNode(int index)
Description copied from interface: IBasicGraph
Get the node matching the nodeIdx.

Specified by:
getNode in interface IBasicGraph<Node,Edge>
Parameters:
index - the node index to lookup.
Returns:
the node matching the index. Cannot be null.

canCreateEdges

public boolean canCreateEdges()

canCreateNodes

public boolean canCreateNodes()

canCreateSubgraphs

public boolean canCreateSubgraphs()

canRemoveSubgraphs

public boolean canRemoveSubgraphs()

containsNode

public boolean containsNode(Node node)
Description copied from interface: IBasicGraph
Tests if this node exists in the graph.

Specified by:
containsNode in interface IBasicGraph<Node,Edge>
Parameters:
node - to be tested.
Returns:
True if the graph contains the node, false otherwise.

containsConnection

public boolean containsConnection(Node thisNode,
                                  Node thatNode)
Description copied from interface: IBasicGraph
Tests if the graph contains an edge connecting these nodes. Ignores the direction of the edge.

Specified by:
containsConnection in interface IBasicGraph<Node,Edge>
Parameters:
thisNode - a node to test.
thatNode - the other node to test.
Returns:
true if the edge exists, false otherwise.

edgeFactory

public EdgeFactory edgeFactory()
Description copied from interface: IModifiableGraph
Gets the edgeFactory for this class. The factory is the only way that new edges can be added to this graph.

Specified by:
edgeFactory in interface IModifiableGraph<Node,Edge>
Specified by:
edgeFactory in interface IUndirectedGraph<Node,Edge>
Returns:
The edge factory.

nodeFactory

public NodeFactory nodeFactory()
Description copied from interface: IModifiableGraph
Gets the nodeFactory for this class. This factory is a singleton so this method must always return the same instance of the factory. The factory is the only way that new nodes can be added to this graph.

Specified by:
nodeFactory in interface IModifiableGraph<Node,Edge>
Returns:
The node factory.

subgraphFactory

public SubgraphFactory subgraphFactory()
Description copied from interface: IModifiableGraph
Gets the subgraphFactory for this class.

Specified by:
subgraphFactory in interface IModifiableGraph<Node,Edge>
Returns:
The subgraph factory.

edgeIterator

public java.util.Iterator<Edge> edgeIterator()
Description copied from interface: IBasicGraph
Get an iterator that traverses all the edges in this graph. No traversal order is guaranteed.

Specified by:
edgeIterator in interface IBasicGraph<Node,Edge>
Returns:
The edge iterator, guaranteed to be non-null.

nodeIterator

public java.util.Iterator<Node> nodeIterator()
Description copied from interface: IBasicGraph
Get an iterator that traverses all the nodes in this graph. The traversal order is not guaranteed, but all nodes will be traversed.

Specified by:
nodeIterator in interface IBasicGraph<Node,Edge>
Returns:
The node iterator, guaranteed to be non-null.

getNumEdges

public int getNumEdges()
Description copied from interface: IBasicGraph
Get the number of edges in the graph.

Specified by:
getNumEdges in interface IBasicGraph<Node,Edge>
Returns:
The number of edges.

getNumNodes

public int getNumNodes()
Description copied from interface: IBasicGraph
Get the number of nodes in the graph.

Specified by:
getNumNodes in interface IBasicGraph<Node,Edge>
Returns:
The number of nodes.

removeSubgraph

public void removeSubgraph(IBasicSubgraph<? extends Node,? extends Edge> subgraph)
Description copied from interface: IModifiableGraph
Removes the nodes and edges defined in the subgraph from this graph. The subgraph must be consistent with this graph and be a subgraph of this graph.

Specified by:
removeSubgraph in interface IModifiableGraph<Node,Edge>
Parameters:
subgraph - The subgraph to remove, cannot be null.

containsEdge

public boolean containsEdge(Edge edge)
Description copied from interface: IBasicGraph
Tests if the graph contains the edge.

Specified by:
containsEdge in interface IBasicGraph<Node,Edge>
Parameters:
edge - the edge to test.
Returns:
true if the edge exists in the graph, false otherwise.

containsEdge

public boolean containsEdge(int edgeIdx)
Description copied from interface: IBasicGraph
Tests if the graph contains the edge of the given index.

Specified by:
containsEdge in interface IBasicGraph<Node,Edge>
Parameters:
edgeIdx - the index to test.
Returns:
true if matching edge can be found, false otherwise.

containsNode

public boolean containsNode(int nodeIdx)
Description copied from interface: IBasicGraph
Tests if the graph contains the node with the given index number.

Specified by:
containsNode in interface IBasicGraph<Node,Edge>
Parameters:
nodeIdx - The index number of the node.
Returns:
True if the graph contains the node, false otherwise.

getEdge

public Edge getEdge(int edgeIdx)
Description copied from interface: IBasicGraph
Get the edge with this index.

Specified by:
getEdge in interface IBasicGraph<Node,Edge>
Parameters:
edgeIdx - The index of the edge.
Returns:
The edge matching the index.

addNewNode

void addNewNode(Node newNode)

containsConnection

public boolean containsConnection(IBasicPair<? extends Node,? extends Edge> ends)
Description copied from interface: IBasicGraph
Tests if the graph has an edge between the defined ends.

Specified by:
containsConnection in interface IBasicGraph<Node,Edge>
Parameters:
ends - the ends of the edge to test.
Returns:
true if the edge exists in the graph, false otherwise.

getCurrentState

public IGraphState<Node,Edge> getCurrentState()
Description copied from interface: IRestorableGraph
Get the current state of the graph as a momento.

Specified by:
getCurrentState in interface IRestorableGraph<Node,Edge>
Returns:
the current graph state, will not be null.

restoreState

public void restoreState(IGraphState<Node,Edge> previousState)
Description copied from interface: IRestorableGraph
Restores the graph state to the state stored by the previousState object.

Specified by:
restoreState in interface IRestorableGraph<Node,Edge>
Parameters:
previousState - The previous state to be restored.

canCopyHere

public boolean canCopyHere(IBasicSubgraph<? extends Node,? extends Edge> subGraph)
Description copied from interface: IModifiableGraph
Tests whether the subGraph can be copied to this graph. To be true the subgraph must be an induced subgraph that is a consistent of the super graph. It must also be not null.

Specified by:
canCopyHere in interface IModifiableGraph<Node,Edge>
Parameters:
subGraph - the subgraph to test, can be null.
Returns:
true if the subgraph is valid to copy from, false otherwise.

copyHere

public void copyHere(IBasicSubgraph<? extends Node,? extends Edge> subGraph)
Description copied from interface: IModifiableGraph
Copies a subgraph into this graph. Note that the subgraph can be from a different graph or subgraph of this graph, since the structure of the graph is copied not the nodes and edges instances themselves. Note that the subgraph must be valid to be copied.

Specified by:
copyHere in interface IModifiableGraph<Node,Edge>
Parameters:
subGraph - the subgraph to copy

getCopiedComponents

public Subgraph getCopiedComponents()
Description copied from interface: IModifiableGraph
Retrieves the nodes and edges created in this graph by the last copy operation. The subgraph is not guaranteed to be a consistent snapshot of this graph. If not copy operation has been performed then an empty subset will be returned.

Specified by:
getCopiedComponents in interface IModifiableGraph<Node,Edge>
Returns:
the subgraph of copied components, or an empty subset of not copy operation has been perfromed.