uk.ed.inf.graph.impl
Class EdgeFactory

java.lang.Object
  extended by uk.ed.inf.graph.impl.EdgeFactory
All Implemented Interfaces:
IBasicEdgeFactory<Node,Edge>, IUndirectedEdgeFactory<Node,Edge>

public class EdgeFactory
extends java.lang.Object
implements IUndirectedEdgeFactory<Node,Edge>


Constructor Summary
EdgeFactory(Graph graph)
           
 
Method Summary
 boolean canCreateEdge()
          Tests is all the conditions have been met in the factory so that edge creation will succeed.
 Edge createEdge()
          Create a new edge and add it to the graph.
 IBasicPair<Node,Edge> getCurrentNodePair()
          Returns the current node pair, or false if no nodes have been set.
 IBasicGraph<Node,Edge> getGraph()
          Get the graph to which this factory acts upon.
 boolean isValidNodePair(Node thisNode, Node thatNode)
          Test if the node pair is valid.
 void setPair(Node oneNode, Node twoNode)
          Sets a pair of nodes with which to create a new edge.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EdgeFactory

EdgeFactory(Graph graph)
Method Detail

setPair

public void setPair(Node oneNode,
                    Node twoNode)
Description copied from interface: IBasicEdgeFactory
Sets a pair of nodes with which to create a new edge.

Specified by:
setPair in interface IBasicEdgeFactory<Node,Edge>
Specified by:
setPair in interface IUndirectedEdgeFactory<Node,Edge>
Parameters:
oneNode - a node in the edge pair, cannot be null.
twoNode - another node in the edge pair, cannot be null.

createEdge

public Edge createEdge()
Description copied from interface: IBasicEdgeFactory
Create a new edge and add it to the graph.

Specified by:
createEdge in interface IBasicEdgeFactory<Node,Edge>
Returns:
the newly created edge that is added to the graph

getGraph

public IBasicGraph<Node,Edge> getGraph()
Description copied from interface: IBasicEdgeFactory
Get the graph to which this factory acts upon.

Specified by:
getGraph in interface IBasicEdgeFactory<Node,Edge>
Returns:
The owning graph, cannot be null.

getCurrentNodePair

public IBasicPair<Node,Edge> getCurrentNodePair()
Description copied from interface: IBasicEdgeFactory
Returns the current node pair, or false if no nodes have been set.

Specified by:
getCurrentNodePair in interface IBasicEdgeFactory<Node,Edge>
Returns:
the current node pair or false if setPair(thisNode, thatNode) has not been called.

canCreateEdge

public boolean canCreateEdge()
Description copied from interface: IBasicEdgeFactory
Tests is all the conditions have been met in the factory so that edge creation will succeed. AT the very least isValidNodePair(thisNode, thatNode) should be true.

Specified by:
canCreateEdge in interface IBasicEdgeFactory<Node,Edge>
Returns:
true if this is the case, false otherwise.

isValidNodePair

public boolean isValidNodePair(Node thisNode,
                               Node thatNode)
Description copied from interface: IBasicEdgeFactory
Test if the node pair is valid. Tests include, does the node pair belong to the same graph as that return by getGraph(), do both nodes belong to the same graph and are both nodes not null.

Specified by:
isValidNodePair in interface IBasicEdgeFactory<Node,Edge>
Parameters:
thisNode - a node that may be the end of an edge.
thatNode - another node that may be the end of an edge.
Returns:
true if the above conditions are met, false otherwise.