org.graffiti.graph
Class OptAdjListGraph

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

public class OptAdjListGraph
extends AdjListGraph
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
OptAdjListGraph()
          Constructs a new instance of an OptAdjListGraph.
OptAdjListGraph(CollectionAttribute coll)
          Constructs a new instance of an OptAdjListGraph.
OptAdjListGraph(Graph g, ListenerManager listenerManager)
          Constructs a new instance of an OptAdjListGraph from an instance of any Graph implementation.
OptAdjListGraph(Graph g, ListenerManager listenerManager, CollectionAttribute coll)
          Constructs a new instance of an OptAdjListGraph from an instance of any Graph implementation.
OptAdjListGraph(ListenerManager listenerManager)
          Constructs a new instance of an OptAdjListGraph.
OptAdjListGraph(ListenerManager listenerManager, CollectionAttribute coll)
          Constructs a new instance of an OptAdjListGraph.
 
Method Summary
 boolean containsEdge(Edge e)
          Returns true, if the graph contains the specified edge, false otherwise.
 boolean containsNode(Node n)
          Returns true, if the graph contains the specified node, false otherwise.
 Object copy()
          Creates and returns a copy of the 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.
 Collection<Edge> getEdges()
          Returns a java.util.Collection containing all the edges of the current graph.
 Iterator<Edge> getEdgesIterator()
          Returns an iterator over the edges of the graph.
 List<Node> getNodes()
          Returns a list containing a copy of the node list of the graph.
 Iterator<Node> getNodesIterator()
          Returns an iterator over the nodes of the graph.
 int getNumberOfDirectedEdges()
          Returns the number of directed edges of the graph.
 int getNumberOfEdges()
          Returns the number of edges of the graph.
 int getNumberOfNodes()
          Returns the number of nodes in the graph.
 int getNumberOfUndirectedEdges()
          Returns the number of undirected edges in the graph.
 boolean isDirected()
          Indicates whether the graph is directed.
 boolean isEmpty()
          Returns true if the graph is empty.
 boolean isUndirected()
          Indicates whether the graph is undirected.
 void setDirected(boolean directed)
          Sets all edges to be directed.
 void setDirected(boolean directed, boolean adjustArrows)
          When passing a true value, all undirected edges in the graph will be set to be directed.
 
Methods inherited from class org.graffiti.graph.AdjListGraph
createEdge, createEdge, createNode, createNode, isModified, setModified, setNodeFirst, setNodeLast
 
Methods inherited from class org.graffiti.graph.AbstractGraph
addAttributeConsumer, addEdge, addEdge, addEdgeCopy, addGraph, addNode, addNode, addNodeCopy, areConnected, clear, deleteEdge, deleteNode, getAttTypesManager, getEdges, getGraphElements, getListenerManager, removeAttributeConsumer
 
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, createEdge, createNode, deleteEdge, deleteNode, getAttTypesManager, getEdges, getGraphElements, isModified, removeAttributeConsumer, setModified
 
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

OptAdjListGraph

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


OptAdjListGraph

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

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

OptAdjListGraph

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

Parameters:
listenerManager - listener manager for the graph.

OptAdjListGraph

public OptAdjListGraph(ListenerManager listenerManager,
                       CollectionAttribute coll)
Constructs a new instance of an OptAdjListGraph. 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 OptAdjListGraph instance.

OptAdjListGraph

public OptAdjListGraph(Graph g,
                       ListenerManager listenerManager)
Constructs a new instance of an OptAdjListGraph 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 OptAdjListGraph shall be generated.
listenerManager - listener manager for the graph.

OptAdjListGraph

public OptAdjListGraph(Graph g,
                       ListenerManager listenerManager,
                       CollectionAttribute coll)
Constructs a new instance of an OptAdjListGraph 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 OptAdjListGraph shall be generated.
listenerManager - listener manager for the graph.
coll - the CollectionAttribute of the currently created OptAdjListGraph instance.
Method Detail

isDirected

public boolean isDirected()
Indicates whether the graph is directed. A graph is directed if all the edges are directed.

Specified by:
isDirected in interface Graph
Overrides:
isDirected in class AbstractGraph
Returns:
a boolean indicating whether the graph is directed.

setDirected

public void setDirected(boolean directed)
Sets all edges to be directed.

If directed is true, standard arrows are set, if it is false, all arrows of all edges are removed.

Specified by:
setDirected in interface Graph
Overrides:
setDirected in class AbstractGraph
See Also:
Graph.setDirected(boolean)

setDirected

public void setDirected(boolean directed,
                        boolean adjustArrows)
When passing a true value, all undirected edges in the graph will be set to be directed. V.v. for a false value. A true second parameter indicates that all edges shall get one arrow at their tips (i.e. close to the target node).

Specified by:
setDirected in interface Graph
Overrides:
setDirected in class AbstractGraph
Parameters:
directed -
adjustArrows -

getEdges

public Collection<Edge> getEdges()
Returns a java.util.Collection containing all the edges of the current graph.

Specified by:
getEdges in interface Graph
Overrides:
getEdges in class AbstractGraph
Returns:
a java.util.Collection containing all the edges of the current graph.

getEdgesIterator

public Iterator<Edge> getEdgesIterator()
Returns an iterator over the edges of the graph. Note that the remove operation is not supported by this iterator.

Specified by:
getEdgesIterator in interface Graph
Overrides:
getEdgesIterator in class AbstractGraph
Returns:
an iterator containing the edges of the graph.

isEmpty

public boolean isEmpty()
Returns true if the graph is empty. The graph is equal to a graph which has been cleared.

Specified by:
isEmpty in interface Graph
Overrides:
isEmpty in class AbstractGraph
Returns:
true if the graph is empty, false otherwise.

getNodes

public List<Node> getNodes()
Returns a list containing a copy of the node list of the graph. Removing elements from this collection will have no effect on the graph whereas nodes can be modified.

Specified by:
getNodes in interface Graph
Overrides:
getNodes in class AbstractGraph
Returns:
a new java.util.List containing all the nodes of the graph.

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
Overrides:
getNodesIterator in class AdjListGraph
Returns:
an iterator containing the nodes of the graph.

getNumberOfDirectedEdges

public int getNumberOfDirectedEdges()
Returns the number of directed edges of the graph.

Specified by:
getNumberOfDirectedEdges in interface Graph
Overrides:
getNumberOfDirectedEdges in class AbstractGraph
Returns:
the number of directed edges of the graph.

getNumberOfEdges

public int getNumberOfEdges()
Returns the number of edges of the graph.

Specified by:
getNumberOfEdges in interface Graph
Overrides:
getNumberOfEdges in class AbstractGraph
Returns:
the number of edges of the graph.

getNumberOfNodes

public int getNumberOfNodes()
Returns the number of nodes in the graph.

Specified by:
getNumberOfNodes in interface Graph
Overrides:
getNumberOfNodes in class AbstractGraph
Returns:
the number of nodes of the graph.

getNumberOfUndirectedEdges

public int getNumberOfUndirectedEdges()
Returns the number of undirected edges in the graph.

Specified by:
getNumberOfUndirectedEdges in interface Graph
Overrides:
getNumberOfUndirectedEdges in class AbstractGraph
Returns:
the number of undirected edges in the graph.

isUndirected

public boolean isUndirected()
Indicates whether the graph is undirected. A graph is undirected if all the edges are undirected.

Specified by:
isUndirected in interface Graph
Overrides:
isUndirected in class AbstractGraph
Returns:
A boolean indicating whether the graph is undirected.

containsEdge

public boolean containsEdge(Edge e)
Returns true, if the graph contains the specified edge, false otherwise.

Specified by:
containsEdge in interface Graph
Overrides:
containsEdge in class AbstractGraph
Parameters:
e - the edge to search for.
Returns:
true, if the graph contains the edge e, false otherwise.

containsNode

public boolean containsNode(Node n)
Returns true, if the graph contains the specified node, false otherwise.

Specified by:
containsNode in interface Graph
Overrides:
containsNode in class AbstractGraph
Parameters:
n - the node to search for.
Returns:
true, if the graph contains the node n, false otherwise.

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
Overrides:
copy in class AdjListGraph
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 AdjListGraph
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.

Overrides:
doAddEdge in class AdjListGraph
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 - DOCUMENT ME!
Returns:
the new edge.

doAddNode

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

Overrides:
doAddNode in class AdjListGraph
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.

Overrides:
doClear in class AdjListGraph

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.

Overrides:
doDeleteEdge in class AdjListGraph
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.

Overrides:
doDeleteNode in class AdjListGraph
Parameters:
n - the node to delete.
Throws:
GraphElementNotFoundException - DOCUMENT ME!


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