org.graffiti.graph
Class AbstractGraph

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

public abstract class AbstractGraph
extends AbstractAttributable
implements Graph

Provides further functionality for graphs.

Version:
$Revision: 5779 $
See Also:
Graph, AdjListGraph

Constructor Summary
AbstractGraph()
          Constructs a new instance of an AbstractGraph.
AbstractGraph(CollectionAttribute coll)
          Constructs a new instance of an AbstractGraph.
AbstractGraph(ListenerManager listenerManager)
          Constructs a new instance of an AdjListGraph.
AbstractGraph(ListenerManager listenerManager, CollectionAttribute coll)
          Constructs a new instance of an AdjListGraph.
 
Method Summary
 void addAttributeConsumer(AttributeConsumer attConsumer)
          Adds the given attribute consumer to the list of attribute consumers.
 Edge addEdge(Node source, Node target, boolean directed)
          Adds a new edge to the current graph.
 Edge addEdge(Node source, Node target, boolean directed, CollectionAttribute col)
          Adds a new edge to the current graph.
 Edge addEdgeCopy(Edge edge, Node source, Node target)
          Adds a copy of the specified edge to the graph as a new edge between the specified source and target node.
 void addGraph(Graph g)
          Adds a Graph g to the current graph.
 Node addNode()
          Adds a new node to the graph.
 Node addNode(CollectionAttribute col)
          Adds a new node to the graph.
 Node addNodeCopy(Node node)
          Adds a copy of the specified node to the graph and returns the copy.
 boolean areConnected(Node n1, Node n2)
          Returns true, if the graph contains an edge between the nodes n1 and n2, false otherwise.
 void clear()
          Deletes the current graph by resetting all its attributes.
 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.
abstract  Node createNode(CollectionAttribute col)
          Creates a new Node that is initialize with the given CollectionAttribute.
 void deleteEdge(Edge e)
          Deletes the given edge from the current graph.
 void deleteNode(Node n)
          Deletes the given node.
 AttributeTypesManager getAttTypesManager()
          Returns the AttributeTypesManager of the graph.
 Collection<Edge> getEdges()
          Returns all edges of the graph.
 Collection<Edge> getEdges(Node n1, Node n2)
          Returns a collection containing all the edges between n1 and n2.
 Iterator<Edge> getEdgesIterator()
          Returns an iterator over the edges of the graph.
 Collection<GraphElement> getGraphElements()
          Returns all nodes and all edges contained in this graph.
 ListenerManager getListenerManager()
          Returns the ListenerManager of the current graph.
 List<Node> getNodes()
          Returns a list containing a copy of the node list 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.
 boolean removeAttributeConsumer(AttributeConsumer attConsumer)
          Returns true, if the given attribute consumer was in the list of attribute consumers and could be removed.
 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.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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.graffiti.graph.Graph
createEdge, getNodesIterator, isModified, 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, getLong, getShort, getString, removeAttribute, setBoolean, setByte, setDouble, setFloat, setInteger, setLong, setShort, setString
 
Methods inherited from interface org.graffiti.core.DeepCopy
copy
 

Constructor Detail

AbstractGraph

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


AbstractGraph

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

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

AbstractGraph

public AbstractGraph(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.

AbstractGraph

public AbstractGraph(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 AbstractGraph instance.
Method Detail

getAttTypesManager

public AttributeTypesManager getAttTypesManager()
Returns the AttributeTypesManager of the graph.

Specified by:
getAttTypesManager in interface Graph
Returns:
the AttributeTypesManager of the graph.

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
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
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
Parameters:
directed -
adjustArrows -

getEdges

public Collection<Edge> getEdges()
Description copied from interface: Graph
Returns all edges of the graph. The returned collection may be unmodifiable and is only valid as long as the graph is not modified.

Specified by:
getEdges in interface Graph
Returns:
a list of all edges of the graph.

getEdges

public Collection<Edge> getEdges(Node n1,
                                 Node n2)
                          throws GraphElementNotFoundException
Returns a collection containing all the edges between n1 and n2. There can be more than one edge between two nodes. The edges returned by this method can go from n1 to n2 or vice versa, be directed or not.

Specified by:
getEdges in interface Graph
Parameters:
n1 - the first node.
n2 - the second node.
Returns:
a Collection containing all edges between n1 and n2, an empty collection if there is no edge between the two nodes.
Throws:
GraphElementNotFoundException - if one of the nodes is not contained in the graph.

getEdgesIterator

public Iterator<Edge> getEdgesIterator()
Returns an iterator over the edges of the graph.

Specified by:
getEdgesIterator in interface Graph
Returns:
an iterator over 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
Returns:
true if the graph is empty, false otherwise.

getGraphElements

public Collection<GraphElement> getGraphElements()
Returns all nodes and all edges contained in this graph.

Specified by:
getGraphElements in interface Graph
Returns:
Collection

getListenerManager

public ListenerManager getListenerManager()
Returns the ListenerManager of the current graph.

Specified by:
getListenerManager in interface Attributable
Returns:
the ListenerManager of the current graph.

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
Returns:
a new java.util.List containing all the nodes of the graph.

getNumberOfDirectedEdges

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

Specified by:
getNumberOfDirectedEdges in interface Graph
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
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
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
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
Returns:
A boolean indicating whether the graph is undirected.

addAttributeConsumer

public void addAttributeConsumer(AttributeConsumer attConsumer)
                          throws UnificationException
Adds the given attribute consumer to the list of attribute consumers.

Specified by:
addAttributeConsumer in interface Graph
Parameters:
attConsumer - the attribute consumer to add.
Throws:
UnificationException - in the context of unification failures.

addEdge

public Edge addEdge(Node source,
                    Node target,
                    boolean directed)
             throws GraphElementNotFoundException
Adds a new edge to the current graph. Informs the ListenerManager about the new node. This method adds a copy of the defaultEdgeAttributes after the preEdgeAdded and before the postEdgeAdded event.

Specified by:
addEdge 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.
Returns:
the new edge.
Throws:
GraphElementNotFoundException - if any of the nodes cannot be found in the graph.

addEdge

public Edge addEdge(Node source,
                    Node target,
                    boolean directed,
                    CollectionAttribute col)
             throws GraphElementNotFoundException
Adds a new edge to the current graph. Informs the ListenerManager about the new node. This method does not add any defaultEdgeAttributes.

Specified by:
addEdge 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 - the CollectionAttribute with which the edge is initialized.
Returns:
the new edge.
Throws:
GraphElementNotFoundException - if any of the nodes cannot be found in the graph.

addEdgeCopy

public Edge addEdgeCopy(Edge edge,
                        Node source,
                        Node target)
Adds a copy of the specified edge to the graph as a new edge between the specified source and target node. Informs the ListenerManager about the newly added edge through the call to addEdge(). Also informs the ListenerManager about the copy of the attributes added to the edge by adding them separatly throug CollectionAttribute.add(Attribute).

Specified by:
addEdgeCopy in interface Graph
Parameters:
edge - the Egde which to copy and add.
source - the source Node of the copied and added edge.
target - the target Node of the copied and added edge.
Returns:
DOCUMENT ME!

addGraph

public void addGraph(Graph g)
Adds a Graph g to the current graph. Graph g will be copied and then all its nodes and edges will be added to the current graph. Like this g will not be destroyed.

Specified by:
addGraph in interface Graph
Parameters:
g - the Graph to be added.

addNode

public Node addNode()
Adds a new node to the graph. Informs the ListenerManager about the new node. This method adds a copy of the defaultNodeAttribute to the newly created node (after the preNodeAdded event and before the postNodeAdded event).

Specified by:
addNode in interface Graph
Returns:
the new node.

addNode

public Node addNode(CollectionAttribute col)
Adds a new node to the graph. Informs the ListenerManager about the new node. Default node attributes (defaultNodeAttribute) are not added by this method.

Specified by:
addNode in interface Graph
Parameters:
col - the CollectionAttribute the node is initialized with.
Returns:
the new node.

addNodeCopy

public Node addNodeCopy(Node node)
Adds a copy of the specified node to the graph and returns the copy. Informs the ListenerManager about the newly added node in the same way as if a completely new node was added. Also informs the ListenerManager about the addition of attributes by using the add(Attribute) method of CollectionAttribute.

Specified by:
addNodeCopy in interface Graph
Parameters:
node - the Node which to copy and to add.
Returns:
the newly created node.

areConnected

public boolean areConnected(Node n1,
                            Node n2)
                     throws GraphElementNotFoundException
Returns true, if the graph contains an edge between the nodes n1 and n2, false otherwise.

Parameters:
n1 - first node of the edge to search for.
n2 - second node of the edge to search for.
Returns:
true, if the graph contains an edge between the nodes n1 and n2 false otherwise.
Throws:
GraphElementNotFoundException - if any of the nodes cannot be found in the graph.

clear

public void clear()
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:
clear in interface Graph

containsEdge

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

Specified by:
containsEdge in interface Graph
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
Parameters:
n - the node to search for.
Returns:
true, if the graph contains the node n, false otherwise.

deleteEdge

public void deleteEdge(Edge e)
                throws GraphElementNotFoundException
Deletes the given edge from the current graph. Informs the ListenerManager about the deletion.

Specified by:
deleteEdge in interface Graph
Parameters:
e - the edge to delete.
Throws:
GraphElementNotFoundException - if the edge to delete cannot be found in the graph.

deleteNode

public void deleteNode(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. Then deletes the node and informs the ListenerManager about the deletion.

Specified by:
deleteNode in interface Graph
Parameters:
n - the node to delete.
Throws:
GraphElementNotFoundException - if the node to delete cannot be found in the graph.

removeAttributeConsumer

public boolean removeAttributeConsumer(AttributeConsumer attConsumer)
Returns true, if the given attribute consumer was in the list of attribute consumers and could be removed.

Specified by:
removeAttributeConsumer in interface Graph
Parameters:
attConsumer - DOCUMENT ME!
Returns:
true, if the given attribute consumer was in the list of attribute consumers and could be removed.

createNode

public abstract Node createNode(CollectionAttribute col)
Creates a new Node that is initialize with the given CollectionAttribute.

Specified by:
createNode in interface Graph
Parameters:
col - attributes for the new node
Returns:
the newly created node.


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