org.graffiti.graph
Class AdjListGraph

java.lang.Object
  extended by org.graffiti.attributes.AbstractAttributable
      extended by org.graffiti.graph.AbstractGraph
          extended by org.graffiti.graph.AdjListGraph
All Implemented Interfaces:
Attributable, DeepCopy, Graph
Direct Known Subclasses:
OptAdjListGraph

public class AdjListGraph
extends AbstractGraph
implements Graph

Implements the Graph-interface using an adjacency list representation of the graph. Requires AdjListNode and AdjListEdge as implementations for nodes and edges. Every method modifying the graph will inform the ListenerManager about the modification according to the description in Graph.

Version:
$Revision: 5779 $
See Also:
Graph, AbstractGraph, AdjListNode, AdjListEdge, AbstractNode, AbstractEdge

Field Summary
 
Fields inherited from class org.graffiti.graph.AbstractGraph
attTypesManager, defaultDirectedEdgeAttribute, defaultGraphAttribute, defaultNodeAttribute, defaultUndirectedEdgeAttribute, listenerManager
 
Fields inherited from class org.graffiti.attributes.AbstractAttributable
attributes
 
Constructor Summary
AdjListGraph()
          Constructs a new instance of an AdjListGraph.
AdjListGraph(CollectionAttribute coll)
          Constructs a new instance of an AdjListGraph.
AdjListGraph(Graph g, ListenerManager listenerManager)
          Constructs a new instance of an AdjListGraph from an instance of any Graph implementation.
AdjListGraph(Graph g, ListenerManager listenerManager, CollectionAttribute coll)
          Constructs a new instance of an AdjListGraph from an instance of any Graph implementation.
AdjListGraph(ListenerManager listenerManager)
          Constructs a new instance of an AdjListGraph.
AdjListGraph(ListenerManager listenerManager, CollectionAttribute coll)
          Constructs a new instance of an AdjListGraph.
 
Method Summary
 Object copy()
          Creates and returns a copy of the graph.
protected  Edge createEdge(Node source, Node target, boolean directed)
          Creates a new AdjListEdge that is in the current graph.
 Edge createEdge(Node source, Node target, boolean directed, CollectionAttribute col)
          Creates a new AdjListEdge that is in the current graph.
protected  Node createNode()
          Creates a new AdjListNode that is in the current graph.
 Node createNode(CollectionAttribute col)
          Creates a new AdjListNode that is in the current graph.
protected  Edge doAddEdge(Node source, Node target, boolean directed)
          Adds a new edge to the current graph.
protected  Edge doAddEdge(Node source, Node target, boolean directed, CollectionAttribute col)
          Adds a new edge to the current graph.
protected  void doAddNode(Node node)
          Adds a new node to the graph.
protected  void doClear()
          Deletes the current graph by resetting all its attributes.
protected  void doDeleteEdge(Edge e)
          Deletes the given edge from the current graph.
protected  void doDeleteNode(Node n)
          Deletes the given node.
 Iterator<Node> getNodesIterator()
          Returns an iterator over the nodes of the graph.
 boolean isModified()
          Indicates whether the Graph has been modified.
 void setModified(boolean modified)
          Should be set to False after saving changes and to True after making changes to the Graph.
 void setNodeFirst(Node node)
          The given node is moved to the front of the node list.
 void setNodeLast(Node node)
          The given node is moved to the end of the node list.
 
Methods inherited from class org.graffiti.graph.AbstractGraph
addAttributeConsumer, addEdge, addEdge, addEdgeCopy, addGraph, addNode, addNode, addNodeCopy, areConnected, clear, containsEdge, containsNode, deleteEdge, deleteNode, getAttTypesManager, getEdges, getEdges, getEdgesIterator, getGraphElements, getListenerManager, getNodes, getNumberOfDirectedEdges, getNumberOfEdges, getNumberOfNodes, getNumberOfUndirectedEdges, isDirected, isEmpty, isUndirected, removeAttributeConsumer, setDirected, setDirected
 
Methods inherited from class org.graffiti.attributes.AbstractAttributable
addAttribute, addBoolean, addByte, addDouble, addFloat, addInteger, addLong, addShort, addString, changeBoolean, changeByte, changeDouble, changeFloat, changeInteger, changeLong, changeShort, changeString, containsAttribute, getAttribute, getAttributes, getBoolean, getByte, getDouble, getFloat, getInteger, getLong, getShort, getString, removeAttribute, setBoolean, setByte, setDouble, setFloat, setInteger, setLong, setShort, setString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.graffiti.graph.Graph
addAttributeConsumer, addEdge, addEdge, addEdgeCopy, addGraph, addNode, addNode, addNodeCopy, clear, containsEdge, containsNode, deleteEdge, deleteNode, getAttTypesManager, getEdges, getEdges, getEdgesIterator, getGraphElements, getNodes, getNumberOfDirectedEdges, getNumberOfEdges, getNumberOfNodes, getNumberOfUndirectedEdges, isDirected, isEmpty, isUndirected, removeAttributeConsumer, setDirected, setDirected
 
Methods inherited from interface org.graffiti.attributes.Attributable
addAttribute, addBoolean, addByte, addDouble, addFloat, addInteger, addLong, addShort, addString, changeBoolean, changeByte, changeDouble, changeFloat, changeInteger, changeLong, changeShort, changeString, containsAttribute, getAttribute, getAttributes, getBoolean, getByte, getDouble, getFloat, getInteger, getListenerManager, getLong, getShort, getString, removeAttribute, setBoolean, setByte, setDouble, setFloat, setInteger, setLong, setShort, setString
 

Constructor Detail

AdjListGraph

public AdjListGraph()
Constructs a new instance of an AdjListGraph. Sets the ListenerManager of the new instance to the default ListenerManager.


AdjListGraph

public AdjListGraph(CollectionAttribute coll)
Constructs a new instance of an AdjListGraph. Sets the ListenerManager of the new instance to the default ListenerManager.

Parameters:
coll - the CollectionAttribute of the currently created AdjListGraph instance.

AdjListGraph

public AdjListGraph(ListenerManager listenerManager)
Constructs a new instance of an AdjListGraph. Sets the ListenerManager of the new instance to the specified one.

Parameters:
listenerManager - listener manager for the graph.

AdjListGraph

public AdjListGraph(ListenerManager listenerManager,
                    CollectionAttribute coll)
Constructs a new instance of an AdjListGraph. Sets the ListenerManager of the new instance to the specified one.

Parameters:
listenerManager - listener manager for the graph.
coll - the CollectionAttribute of the currently created AdjListGraph instance.

AdjListGraph

public AdjListGraph(Graph g,
                    ListenerManager listenerManager)
Constructs a new instance of an AdjListGraph from an instance of any Graph implementation. Copies all nodes and edges from g into the new graph.

Parameters:
g - any Graph implementation out of which an AdjListGraph shall be generated.
listenerManager - listener manager for the graph.

AdjListGraph

public AdjListGraph(Graph g,
                    ListenerManager listenerManager,
                    CollectionAttribute coll)
Constructs a new instance of an AdjListGraph from an instance of any Graph implementation. Copies all nodes and edges from g into the new graph.

Parameters:
g - any Graph implementation out of which an AdjListGraph shall be generated.
listenerManager - listener manager for the graph.
coll - the CollectionAttribute of the currently created AdjListGraph instance.
Method Detail

setNodeFirst

public void setNodeFirst(Node node)
The given node is moved to the front of the node list.

Parameters:
node -

setNodeLast

public void setNodeLast(Node node)
The given node is moved to the end of the node list.

Parameters:
node -

getNodesIterator

public Iterator<Node> getNodesIterator()
Returns an iterator over the nodes of the graph. Note that the remove operation is not supported by this iterator.

Specified by:
getNodesIterator in interface Graph
Returns:
an iterator containing the nodes of the graph.

copy

public Object copy()
Creates and returns a copy of the graph. The attributes are copied as well as all nodes and edges.

Specified by:
copy in interface DeepCopy
Returns:
a copy of the graph.

doAddEdge

protected Edge doAddEdge(Node source,
                         Node target,
                         boolean directed)
Adds a new edge to the current graph. Informs the ListenerManager about the new node.

Overrides:
doAddEdge in class AbstractGraph
Parameters:
source - the source of the edge to add.
target - the target of the edge to add.
directed - true if the edge shall be directed, false otherwise.
Returns:
the new edge.

doAddEdge

protected Edge doAddEdge(Node source,
                         Node target,
                         boolean directed,
                         CollectionAttribute col)
Adds a new edge to the current graph. Informs the ListenerManager about the new node.

Specified by:
doAddEdge in class AbstractGraph
Parameters:
source - the source of the edge to add.
target - the target of the edge to add.
directed - true if the edge shall be directed, false otherwise.
col - CollectionAttribute that will be added to the new Edge
Returns:
the new edge.

doAddNode

protected void doAddNode(Node node)
Adds a new node to the graph. Informs the ListenerManager about the new node.

Specified by:
doAddNode in class AbstractGraph
Parameters:
node - DOCUMENT ME!

doClear

protected void doClear()
Deletes the current graph by resetting all its attributes. The graph is then equal to a new generated graph i.e. the list of nodes and edges will be empty. A special event for clearing the graph will be passed to the listener manager.

Specified by:
doClear in class AbstractGraph

doDeleteEdge

protected void doDeleteEdge(Edge e)
Deletes the given edge from the current graph. Implicitly calls the ListenerManager by calling AdjListNode.removeEdge() in the source and target node of the edge.

Specified by:
doDeleteEdge in class AbstractGraph
Parameters:
e - the edge to delete.

doDeleteNode

protected void doDeleteNode(Node n)
                     throws GraphElementNotFoundException
Deletes the given node. First all in- and out-going edges will be deleted using deleteEdge() and thereby informs the ListenerManager implicitly.

Specified by:
doDeleteNode in class AbstractGraph
Parameters:
n - the node to delete.
Throws:
GraphElementNotFoundException - DOCUMENT ME!

createNode

protected Node createNode()
Creates a new AdjListNode that is in the current graph.

Specified by:
createNode in class AbstractGraph
Returns:
the newly created node.

createNode

public Node createNode(CollectionAttribute col)
Creates a new AdjListNode that is in the current graph. And initializes it with the given CollectionAttribute.

Specified by:
createNode in interface Graph
Specified by:
createNode in class AbstractGraph
Parameters:
col - DOCUMENT ME!
Returns:
the newly created node.

createEdge

protected Edge createEdge(Node source,
                          Node target,
                          boolean directed)
Creates a new AdjListEdge that is in the current graph.

Parameters:
source - the source of the edge to add.
target - the target of the edge to add.
directed - true if the edge shall be directed, false otherwise.
Returns:
the newly created edge.

createEdge

public Edge createEdge(Node source,
                       Node target,
                       boolean directed,
                       CollectionAttribute col)
Creates a new AdjListEdge that is in the current graph. And initializes it with the given CollectionAttribute.

Specified by:
createEdge in interface Graph
Parameters:
source - the source of the edge to add.
target - the target of the edge to add.
directed - true if the edge shall be directed, false otherwise.
col - CollectionAttribute that will be added to the new Edge
Returns:
the new edge.

isModified

public boolean isModified()
Description copied from interface: Graph
Indicates whether the Graph has been modified. A call to setModified can change this property to false e.g. after the graph has been saved to disc. Changes to attributes and delete/add commands of nodes and edges should change this property to true.

Specified by:
isModified in interface Graph
Returns:
True, if the graph has been modifed, False if not.

setModified

public void setModified(boolean modified)
Description copied from interface: Graph
Should be set to False after saving changes and to True after making changes to the Graph. The add/delete nodes and edges commands as well as the property change methods should set this value to True.

Specified by:
setModified in interface Graph
Parameters:
modified - Indicates the new status of this field.


Generated at 2012-05-30 11:00:36 PM CEST