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

java.lang.Object
  extended by uk.ed.inf.graph.compound.base.BaseChildCompoundGraph
All Implemented Interfaces:
IBasicGraph<BaseCompoundNode,BaseCompoundEdge>, IChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>, ICompoundGraph<BaseCompoundNode,BaseCompoundEdge>, IModifiableChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>, IDirectedGraph<BaseCompoundNode,BaseCompoundEdge>
Direct Known Subclasses:
ArchetypalChildCompoundGraph

public abstract class BaseChildCompoundGraph
extends java.lang.Object
implements IChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>, IModifiableChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>


Constructor Summary
protected BaseChildCompoundGraph(BaseGraphCopyBuilder copyBuilder, BaseGraphMoveBuilder moveBuilder)
           
 
Method Summary
protected  void addNewEdge(BaseCompoundEdge newEdge)
           
protected  void addNewNode(BaseCompoundNode newNode)
           
 boolean canCopyHere(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subGraph)
          Tests whether the subGraph can be copied to this graph.
 boolean canMoveHere(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> iSubGraph)
          Tests whether the subGraph can be moved to this graph.
 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 graph has an edge between the defined ends.
 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)
          Test if there is one or more directed edge defined by the end pair ends.
 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  void createEdgeSet(IDirectedEdgeSet<BaseCompoundNode,BaseCompoundEdge> edgeSet)
           
protected  void createNodeSet(INodeSet<BaseCompoundNode,BaseCompoundEdge> nodeSet)
           
abstract  BaseChildCompoundEdgeFactory edgeFactory()
          Gets the edgeFactory for this class.
 java.util.Iterator<BaseCompoundEdge> edgeIterator()
          Get an iterator that traverses all the edges in this graph.
 BaseSubCompoundGraph getCopiedComponents()
          Retrieves the nodes and edges created in this graph by the last copy operation.
 BaseCompoundEdge getEdge(int edgeIdx)
          Get the edge with this index.
protected  IEdgeSet<BaseCompoundNode,BaseCompoundEdge> getEdgeSet()
           
 BaseSubCompoundGraph getMovedComponents()
          Retrieves the nodes and edges created in this graph by the last copy operation.
 BaseCompoundNode getNode(int nodeIdx)
          Get the node matching the nodeIdx.
protected  INodeSet<BaseCompoundNode,BaseCompoundEdge> getNodeSet()
           
 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.
 BaseCompoundGraph getSuperGraph()
          Gets the compound graph that owns this child graph.
protected abstract  boolean hasPassedAdditionalValidation()
          A hook method that should be used to provide addition validation for the class inheriting from this one.
 boolean isInducedSubgraph()
           
 boolean isValid()
           
 void moveHere(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subGraph)
          Moves a subgraph into this graph.
abstract  BaseCompoundNodeFactory nodeFactory()
           
 java.util.Iterator<BaseCompoundNode> nodeIterator()
          Get an iterator that traverses all the nodes in this graph.
protected  java.util.Iterator<BaseCompoundEdge> unfilteredEdgeIterator()
           
protected  java.util.Iterator<BaseCompoundNode> unfilteredNodeIterator()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseChildCompoundGraph

protected BaseChildCompoundGraph(BaseGraphCopyBuilder copyBuilder,
                                 BaseGraphMoveBuilder moveBuilder)
Method Detail

createNodeSet

protected final void createNodeSet(INodeSet<BaseCompoundNode,BaseCompoundEdge> nodeSet)

createEdgeSet

protected final void createEdgeSet(IDirectedEdgeSet<BaseCompoundNode,BaseCompoundEdge> edgeSet)

getEdgeSet

protected final IEdgeSet<BaseCompoundNode,BaseCompoundEdge> getEdgeSet()

getNodeSet

protected final INodeSet<BaseCompoundNode,BaseCompoundEdge> getNodeSet()

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

unfilteredEdgeIterator

protected final java.util.Iterator<BaseCompoundEdge> unfilteredEdgeIterator()

unfilteredNodeIterator

protected final java.util.Iterator<BaseCompoundNode> unfilteredNodeIterator()

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 final 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.

canCopyHere

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

getSuperGraph

public BaseCompoundGraph getSuperGraph()
Description copied from interface: IChildCompoundGraph
Gets the compound graph that owns this child graph.

Specified by:
getSuperGraph in interface IChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Returns:
the owning compound graph, which cannot be null.

isInducedSubgraph

public final boolean isInducedSubgraph()

addNewNode

protected void addNewNode(BaseCompoundNode newNode)

addNewEdge

protected void addNewEdge(BaseCompoundEdge newEdge)

containsDirectedEdge

public final boolean containsDirectedEdge(IDirectedPair<? extends BaseCompoundNode,? extends BaseCompoundEdge> ends)
Description copied from interface: IDirectedGraph
Test if there is one or more directed edge defined by the end pair ends.

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)
Description copied from interface: IBasicGraph
Tests if the graph has an edge between the defined ends.

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

nodeFactory

public abstract BaseCompoundNodeFactory nodeFactory()
Specified by:
nodeFactory in interface IModifiableChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>

edgeFactory

public abstract BaseChildCompoundEdgeFactory edgeFactory()
Description copied from interface: IModifiableChildCompoundGraph
Gets the edgeFactory 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 edges can be added to this graph.

Specified by:
edgeFactory in interface IModifiableChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Returns:
The edge factory.

canMoveHere

public boolean canMoveHere(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> iSubGraph)
Tests whether the subGraph can be moved 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 and belong to the same graph as this one. The subgraph must also be valid. Also no nodes in the induced sub-graph of subGraph can be children. In addition at least one node must be moving to a new child graph. of this child compound graph.

Specified by:
canMoveHere in interface IModifiableChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Parameters:
subGraph - the subgraph to test, can be null.
Returns:
true if the subgraph is valid to copy from, false otherwise.

moveHere

public void moveHere(ISubCompoundGraph<? extends BaseCompoundNode,? extends BaseCompoundEdge> subGraph)
Moves a subgraph into this graph. It does this by creating a new set of nodes in this subgraph and removing the nodes defined in subGraph. The new nodes from the move can be found in getMovedComponents() and the removed nodes will be found in subGraph. At least one node must be moving to a new child graph. Only those nodes and edges that have a new owning child graph will be moved, other nodes will remain where they are.

Specified by:
moveHere in interface IModifiableChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Parameters:
subGraph - the subgraph to move.
Throws:
java.lang.IllegalArgumentException - if canMoveHere(subGraph) == false.

getMovedComponents

public BaseSubCompoundGraph getMovedComponents()
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:
getMovedComponents in interface IModifiableChildCompoundGraph<BaseCompoundNode,BaseCompoundEdge>
Returns:
the subgraph of copied components, or an empty subset of not copy operation has been perfromed.

getCopiedComponents

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

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()