uk.ed.inf.graph.compound.base
Class BaseCompoundGraph

java.lang.Object
  extended by uk.ed.inf.graph.compound.base.BaseCompoundGraph
All Implemented Interfaces:
IBasicGraph<BaseCompoundNode,BaseCompoundEdge>, ICompoundGraph<BaseCompoundNode,BaseCompoundEdge>, IModifiableCompoundGraph<BaseCompoundNode,BaseCompoundEdge>, IDirectedGraph<BaseCompoundNode,BaseCompoundEdge>, IRestorableGraph<BaseCompoundNode,BaseCompoundEdge>
Direct Known Subclasses:
ArchetypalCompoundGraph

public abstract class BaseCompoundGraph
extends java.lang.Object
implements ICompoundGraph<BaseCompoundNode,BaseCompoundEdge>, IRestorableGraph<BaseCompoundNode,BaseCompoundEdge>, IModifiableCompoundGraph<BaseCompoundNode,BaseCompoundEdge>


Constructor Summary
protected BaseCompoundGraph(BaseGraphCopyBuilder copyBuilder)
           
protected BaseCompoundGraph(BaseGraphCopyBuilder copyBuilder, BaseCompoundGraph otherGraph)
           
 
Method Summary
 boolean canCopyHere(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subGraph)
          Removes the nodes and edges defined in the subgraph from this graph.
 boolean canRemoveSubgraph(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subgraph)
          Tests if subgraph removal will succeed.
 boolean containsConnection(BaseCompoundNode thisNode, BaseCompoundNode thatNode)
          Tests if the graph contains an edge connecting these nodes.
 boolean containsConnection(IBasicPair<? extends BaseCompoundNode,? extends BaseCompoundEdge> ends)
          Tests if the ends define any edge in this graph.
 boolean containsDirectedEdge(BaseCompoundNode outNode, BaseCompoundNode inNode)
          Tests if there is one or more directed edges from the outNode to the inNode.
 boolean containsDirectedEdge(IDirectedPair<? extends BaseCompoundNode,? extends BaseCompoundEdge> ends)
          Tests if the ends define one or more directed edges.
 boolean containsEdge(BaseCompoundEdge 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(BaseCompoundNode node)
          Tests if this node exists in the graph.
 boolean containsNode(int nodeIdx)
          Tests if the graph contains the node with the given index number.
 void copyHere(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subGraph)
          Copies a subgraph into this graph.
protected abstract  void createCopyOfRootNode(int newIndexValue, BaseCompoundNode otherRootNode)
           
abstract  BaseCompoundEdgeFactory edgeFactory()
          Gets an edge factory that works out the LCA of two nodes making up the edge and assigns it to the appropriate compound graph.
 java.util.Iterator<BaseCompoundEdge> edgeIterator()
          Returns all edges in tree level-node iteration order.
 ISubCompoundGraph<BaseCompoundNode,BaseCompoundEdge> getCopiedComponents()
          Retrieves the nodes and edges created in this graph by the last copy operation.
 IGraphState<BaseCompoundNode,BaseCompoundEdge> getCurrentState()
          Get the current state of the graph as a momento.
 BaseCompoundEdge getEdge(int edgeIdx)
          Get the edge with this index.
protected abstract  IndexCounter getEdgeCounter()
           
(package private)  BaseCompoundNode getLcaNode(BaseCompoundNode inNode, BaseCompoundNode outNode)
           
 BaseCompoundNode getNode(int nodeIdx)
          Get the node matching the nodeIdx.
protected abstract  IndexCounter getNodeCounter()
           
protected abstract  ITree<BaseCompoundNode> getNodeTree()
           
 int getNumEdges()
          Get the number of edges in the graph.
 int getNumNodes()
          Get the number of nodes in the graph.
abstract  BaseCompoundNode getRootNode()
          Get the root node of this graph.
protected abstract  boolean hasPassedAdditionalValidation()
          A hook method that should be used to provide addition validation for the class inheriting from this one.
 boolean isValid()
           
abstract  BaseCompoundNodeFactory nodeFactory()
          Gets the node factory to add new nodes to the root child graph of this compound graph.
 java.util.Iterator<BaseCompoundNode> nodeIterator()
          Get an iterator that traverses all the nodes in this graph.
protected  void performCopy(BaseCompoundGraph otherGraph)
          To be used by copy constructor.
 void removeSubgraph(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subgraph)
           
 void restoreState(IGraphState<BaseCompoundNode,BaseCompoundEdge> previousState)
          Restores the graph state to the state stored by the previousState object.
abstract  BaseSubCompoundGraphFactory subgraphFactory()
          Gets a subgraph factory used to create a subgraph of this graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseCompoundGraph

protected BaseCompoundGraph(BaseGraphCopyBuilder copyBuilder)

BaseCompoundGraph

protected BaseCompoundGraph(BaseGraphCopyBuilder copyBuilder,
                            BaseCompoundGraph otherGraph)
Method Detail

getNodeCounter

protected abstract IndexCounter getNodeCounter()

getEdgeCounter

protected abstract IndexCounter getEdgeCounter()

createCopyOfRootNode

protected abstract void createCopyOfRootNode(int newIndexValue,
                                             BaseCompoundNode otherRootNode)

getNodeTree

protected abstract ITree<BaseCompoundNode> getNodeTree()

performCopy

protected void performCopy(BaseCompoundGraph otherGraph)
To be used by copy constructor. After this constructor has been called extending classes should ensure that the root node is copied, and a new Tree is created. The calling constructor can then call perfromCopy() to actually copy the graph;

Parameters:
copyBuilder -
otherGraph -

getRootNode

public abstract BaseCompoundNode getRootNode()
Description copied from interface: ICompoundGraph
Get the root node of this graph.

Specified by:
getRootNode in interface ICompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Returns:
The root node, which cannot be null.

containsDirectedEdge

public final boolean containsDirectedEdge(BaseCompoundNode outNode,
                                          BaseCompoundNode inNode)
Description copied from interface: IDirectedGraph
Tests if there is one or more directed edges from the outNode to the inNode.

Specified by:
containsDirectedEdge in interface IDirectedGraph<BaseCompoundNode,BaseCompoundEdge>
Parameters:
outNode - the node the edge comes out from, can be null.
inNode - the node the edge goes into, can be null.
Returns:
true if there is such and edge, false otherwise.

containsConnection

public final boolean containsConnection(BaseCompoundNode thisNode,
                                        BaseCompoundNode 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<BaseCompoundNode,BaseCompoundEdge>
Parameters:
thisNode - a node to test.
thatNode - the other node to test.
Returns:
true if the edge exists, false otherwise.

containsEdge

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

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

containsEdge

public final 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<BaseCompoundNode,BaseCompoundEdge>
Parameters:
edgeIdx - the index to test.
Returns:
true if matching edge can be found, false otherwise.

containsNode

public final 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<BaseCompoundNode,BaseCompoundEdge>
Parameters:
nodeIdx - The index number of the node.
Returns:
True if the graph contains the node, false otherwise.

containsNode

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

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

getEdge

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

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

edgeIterator

public java.util.Iterator<BaseCompoundEdge> edgeIterator()
Returns all edges in tree level-node iteration order. For each node the edges are returned in the same order as the CiNode edge iterator. Returns both undirected and directed nodes.

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

getNode

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

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

nodeIterator

public java.util.Iterator<BaseCompoundNode> 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<BaseCompoundNode,BaseCompoundEdge>
Returns:
The node iterator, guaranteed to be non-null.

getNumEdges

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

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

getNumNodes

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

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

canRemoveSubgraph

public boolean canRemoveSubgraph(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subgraph)
Description copied from interface: IModifiableCompoundGraph
Tests if subgraph removal will succeed. To succeed the subgraph must belong to this graph, it must be a consistent snapshot and cannot be null.

Specified by:
canRemoveSubgraph in interface IModifiableCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Parameters:
subgraph - the subgraph to be removed, which can be null.
Returns:
true if the subgraph will succeed, false otherwise.

removeSubgraph

public final void removeSubgraph(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subgraph)

getLcaNode

final BaseCompoundNode getLcaNode(BaseCompoundNode inNode,
                                  BaseCompoundNode outNode)

containsDirectedEdge

public final boolean containsDirectedEdge(IDirectedPair<? extends BaseCompoundNode,? extends BaseCompoundEdge> ends)
Tests if the ends define one or more directed edges.

Specified by:
containsDirectedEdge in interface IDirectedGraph<BaseCompoundNode,BaseCompoundEdge>
Parameters:
ends - the pair of nodes to be tested, can be null.
Returns:
true if there is at least one edge between then, false otherwise.

containsConnection

public final boolean containsConnection(IBasicPair<? extends BaseCompoundNode,? extends BaseCompoundEdge> ends)
Tests if the ends define any edge in this graph. Note that the node pair must be created by this graph as the method expects ends to be of type IDirectedPair and will return false if it is not.

Specified by:
containsConnection in interface IBasicGraph<BaseCompoundNode,BaseCompoundEdge>
Parameters:
ends - the pair of nodes that may define the edges of an edge.
Returns:
true if it does, false otherwise.

getCurrentState

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

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

restoreState

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

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

canCopyHere

public final boolean canCopyHere(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subGraph)
Description copied from interface: IModifiableCompoundGraph
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:
canCopyHere in interface IModifiableCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Parameters:
subGraph - The subgraph to remove, cannot be null.
Returns:
true if the subgraph is valid to copy from, false otherwise.

copyHere

public final void copyHere(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subGraph)
Description copied from interface: IModifiableCompoundGraph
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 IModifiableCompoundGraph<BaseCompoundNode,BaseCompoundEdge>

getCopiedComponents

public final ISubCompoundGraph<BaseCompoundNode,BaseCompoundEdge> getCopiedComponents()
Description copied from interface: IModifiableCompoundGraph
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 IModifiableCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Returns:
the subgraph of copied components, or an empty subset of not copy operation has been perfromed.

nodeFactory

public abstract BaseCompoundNodeFactory nodeFactory()
Description copied from interface: IModifiableCompoundGraph
Gets the node factory to add new nodes to the root child graph of this compound graph.

Specified by:
nodeFactory in interface IModifiableCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Returns:
the edge factory, which cannot be null.

edgeFactory

public abstract BaseCompoundEdgeFactory edgeFactory()
Description copied from interface: IModifiableCompoundGraph
Gets an edge factory that works out the LCA of two nodes making up the edge and assigns it to the appropriate compound graph. This is more permissive than the edge factory from a ChildCompoundGraph, which requires to to know that the edge belongs in that child graph (i.e. its root node is the LCA of the out and in nodes of the edge).

Specified by:
edgeFactory in interface IModifiableCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Returns:
The edge factory, which cannot be null.

subgraphFactory

public abstract BaseSubCompoundGraphFactory subgraphFactory()
Description copied from interface: IModifiableCompoundGraph
Gets a subgraph factory used to create a subgraph of this graph.

Specified by:
subgraphFactory in interface IModifiableCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Returns:
a new instance of the subgraph factory.

hasPassedAdditionalValidation

protected abstract boolean hasPassedAdditionalValidation()
A hook method that should be used to provide addition validation for the class inheriting from this one.

Returns:

isValid

public boolean isValid()