Package org.graffiti.graph
Class AbstractGraph
java.lang.Object
org.graffiti.attributes.AbstractAttributable
org.graffiti.graph.AbstractGraph
- All Implemented Interfaces:
Attributable,DeepCopy,Graph
- Direct Known Subclasses:
AdjListGraph
public abstract class AbstractGraph extends AbstractAttributable implements Graph
Provides further functionality for graphs.
- Version:
- $Revision: 1.10 $
- See Also:
Graph,AdjListGraph- Recent revisions:
- 2.7.0
-
Constructor Summary
Constructors Constructor Description AbstractGraph()Constructs a new instance of anAbstractGraph.AbstractGraph(CollectionAttribute coll)Constructs a new instance of anAbstractGraph.AbstractGraph(ListenerManager listenerManager)Constructs a new instance of anAdjListGraph.AbstractGraph(ListenerManager listenerManager, CollectionAttribute coll)Constructs a new instance of anAdjListGraph. -
Method Summary
Modifier and Type Method Description voidaddAttributeConsumer(AttributeConsumer attConsumer)Adds the given attribute consumer to the list of attribute consumers.EdgeaddEdge(Node source, Node target, boolean directed)Adds a new edge to the current graph.EdgeaddEdge(Node source, Node target, boolean directed, CollectionAttribute col)Adds a new edge to the current graph.EdgeaddEdgeCopy(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.Collection<GraphElement>addGraph(Graph g)Adds a Graph g to the current graph.NodeaddNode()Adds a new node to the graph.NodeaddNode(CollectionAttribute col)Adds a new node to the graph.NodeaddNodeCopy(Node node)Adds a copy of the specified node to the graph and returns the copy.booleanareConnected(Node n1, Node n2)Returnstrue, if the graph contains an edge between the nodes n1 and n2,falseotherwise.voidclear()Deletes the current graph by resetting all its attributes.booleancontainsEdge(Edge e)Returnstrue, if the graph contains the specified edge,falseotherwise.booleancontainsNode(Node n)Returnstrue, if the graph contains the specified node,falseotherwise.voiddeleteEdge(Edge e)Deletes the given edge from the current graph.voiddeleteNode(Node n)Deletes the given node.longgenerateNextUniqueGraphElementId()returns a unique id for a new graphelement added to this graphAttributeTypesManagergetAttTypesManager()Returns theAttributeTypesManagerof the graph.longgetCurrentMaxGraphElementId()returns current max id of the last added graph element without incrementing itCollection<Edge>getEdges()Returns ajava.util.Collectioncontaining all the edges of the current 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.ListenerManagergetListenerManager()Returns the ListenerManager of the current graph.intgetNumberOfDirectedEdges()Returns the number of directed edges of the graph.intgetNumberOfEdges()Returns the number of edges of the graph.intgetNumberOfNodes()Returns the number of nodes in the graph.intgetNumberOfUndirectedEdges()Returns the number of undirected edges in the graph.booleanisDirected()Indicates whether the graph is directed.booleanisEmpty()Returnstrueif the graph is empty.booleanisUndirected()Indicates whether the graph is undirected.booleanremoveAttributeConsumer(AttributeConsumer attConsumer)Returnstrue, if the given attribute consumer was in the list of attribute consumers and could be removed.voidsetDirected(boolean directed)Sets all edges to bedirected.voidsetDirected(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, getAttribute, getAttributes, getBoolean, getByte, getDouble, getFloat, getInteger, getLong, getShort, getString, removeAttribute, setBoolean, setByte, setDouble, setFloat, setInteger, setLong, setShort, setStringMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.graffiti.attributes.Attributable
addAttribute, addBoolean, addByte, addDouble, addFloat, addInteger, addLong, addShort, addString, changeBoolean, changeByte, changeDouble, changeFloat, changeInteger, changeLong, changeShort, changeString, getAttribute, getAttributes, getBoolean, getByte, getDouble, getFloat, getInteger, getLong, getShort, getString, removeAttribute, setBoolean, setByte, setDouble, setFloat, setInteger, setLong, setShort, setStringMethods inherited from interface org.graffiti.graph.Graph
checkMaxGraphElementId, deleteAll, getFileTypeDescription, getName, getName, getNodes, getNodesIterator, isModified, numberGraphElements, setFileTypeDescription, setListenerManager, setModified, setName
-
Constructor Details
-
AbstractGraph
public AbstractGraph()Constructs a new instance of anAbstractGraph. Sets theListenerManagerof the new instance to the defaultListenerManager. -
AbstractGraph
Constructs a new instance of anAbstractGraph. Sets theListenerManagerof the new instance to the defaultListenerManager.- Parameters:
coll- theCollectionAttributeof the currently createdAbstractGraphinstance.
-
AbstractGraph
Constructs a new instance of anAdjListGraph. Sets theListenerManagerof the new instance to the specified one.- Parameters:
listenerManager- listener manager for the graph.
-
AbstractGraph
Constructs a new instance of anAdjListGraph. Sets theListenerManagerof the new instance to the specified one.- Parameters:
listenerManager- listener manager for the graph.coll- theCollectionAttributeof the currently createdAbstractGraphinstance.
-
-
Method Details
-
getAttTypesManager
Returns theAttributeTypesManagerof the graph.- Specified by:
getAttTypesManagerin interfaceGraph- Returns:
- the
AttributeTypesManagerof the graph.
-
isDirected
public boolean isDirected()Indicates whether the graph is directed. A graph is directed if the graph setting states this.- Specified by:
isDirectedin interfaceGraph- Returns:
- a boolean indicating whether the graph is directed.
-
setDirected
public void setDirected(boolean directed)Sets all edges to bedirected.If
directedistrue, standard arrows are set, if it isfalse, all arrows of all edges are removed.- Specified by:
setDirectedin interfaceGraph- 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 second parameter indicates that if the edge arrows should be corrected.- Specified by:
setDirectedin interfaceGraph- Parameters:
directed-adjustArrows-
-
generateNextUniqueGraphElementId
public long generateNextUniqueGraphElementId()Description copied from interface:Graphreturns a unique id for a new graphelement added to this graph- Specified by:
generateNextUniqueGraphElementIdin interfaceGraph- Returns:
-
getCurrentMaxGraphElementId
public long getCurrentMaxGraphElementId()Description copied from interface:Graphreturns current max id of the last added graph element without incrementing it- Specified by:
getCurrentMaxGraphElementIdin interfaceGraph- Returns:
-
getEdges
Returns ajava.util.Collectioncontaining all the edges of the current graph. -
getEdges
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:
getEdgesin interfaceGraph- Parameters:
n1- the first node.n2- the second node.- Returns:
- a
Collectioncontaining 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
Returns an iterator over the edges of the graph.- Specified by:
getEdgesIteratorin interfaceGraph- Returns:
- an iterator over the edges of the graph.
-
isEmpty
public boolean isEmpty()Returnstrueif the graph is empty. The graph is equal to a graph which has been cleared. -
getGraphElements
Returns all nodes and all edges contained in this graph.- Specified by:
getGraphElementsin interfaceGraph- Returns:
- Collection
-
getListenerManager
Returns the ListenerManager of the current graph.- Specified by:
getListenerManagerin interfaceAttributable- Returns:
- the ListenerManager of the current graph.
-
getNumberOfDirectedEdges
public int getNumberOfDirectedEdges()Returns the number of directed edges of the graph.- Specified by:
getNumberOfDirectedEdgesin interfaceGraph- Returns:
- the number of directed edges of the graph.
-
getNumberOfEdges
public int getNumberOfEdges()Returns the number of edges of the graph.- Specified by:
getNumberOfEdgesin interfaceGraph- Returns:
- the number of edges of the graph.
-
getNumberOfNodes
public int getNumberOfNodes()Returns the number of nodes in the graph.- Specified by:
getNumberOfNodesin interfaceGraph- Returns:
- the number of nodes of the graph.
-
getNumberOfUndirectedEdges
public int getNumberOfUndirectedEdges()Returns the number of undirected edges in the graph.- Specified by:
getNumberOfUndirectedEdgesin interfaceGraph- 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:
isUndirectedin interfaceGraph- Returns:
- A boolean indicating whether the graph is undirected.
-
addAttributeConsumer
Adds the given attribute consumer to the list of attribute consumers.- Specified by:
addAttributeConsumerin interfaceGraph- 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 GraphElementNotFoundExceptionAdds a new edge to the current graph. Informs the ListenerManager about the new node. This method adds a copy of thedefaultEdgeAttributesafter thepreEdgeAddedand before thepostEdgeAddedevent.- Specified by:
addEdgein interfaceGraph- Parameters:
source- the source of the edge to add.target- the target of the edge to add.directed-trueif the edge shall be directed,falseotherwise.- 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 GraphElementNotFoundExceptionAdds a new edge to the current graph. Informs the ListenerManager about the new node. This method does not add anydefaultEdgeAttributes.- Specified by:
addEdgein interfaceGraph- Parameters:
source- the source of the edge to add.target- the target of the edge to add.directed-trueif the edge shall be directed,falseotherwise.col- theCollectionAttributewith which the edge is initialized.- Returns:
- the new edge.
- Throws:
GraphElementNotFoundException- if any of the nodes cannot be found in the graph.
-
addEdgeCopy
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 toaddEdge(). Also informs the ListenerManager about the copy of the attributes added to the edge by adding them separatly througCollectionAttribute.add(Attribute).- Specified by:
addEdgeCopyin interfaceGraph- Parameters:
edge- theEgdewhich to copy and add.source- the sourceNodeof the copied and added edge.target- the targetNodeof the copied and added edge.- Returns:
- DOCUMENT ME!
-
addGraph
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. -
addNode
Adds a new node to the graph. Informs the ListenerManager about the new node. This method adds a copy of thedefaultNodeAttributeto the newly created node (after thepreNodeAddedevent and before thepostNodeAddedevent). -
addNode
Adds a new node to the graph. Informs the ListenerManager about the new node. Default node attributes (defaultNodeAttribute) are not added by this method. -
addNodeCopy
Adds a copy of the specified node to the graph and returns the copy. The copy will NOT have the same id though!!! 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 theadd(Attribute)method ofCollectionAttribute.- Specified by:
addNodeCopyin interfaceGraph- Parameters:
node- theNodewhich to copy and to add.- Returns:
- the newly created node.
-
areConnected
Returnstrue, if the graph contains an edge between the nodes n1 and n2,falseotherwise.- 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 n2falseotherwise.- 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. -
containsEdge
Returnstrue, if the graph contains the specified edge,falseotherwise.- Specified by:
containsEdgein interfaceGraph- Parameters:
e- the edge to search for.- Returns:
true, if the graph contains the edge e,falseotherwise.
-
containsNode
Returnstrue, if the graph contains the specified node,falseotherwise.- Specified by:
containsNodein interfaceGraph- Parameters:
n- the node to search for.- Returns:
true, if the graph contains the node n,falseotherwise.
-
deleteEdge
Deletes the given edge from the current graph. Informs the ListenerManager about the deletion.- Specified by:
deleteEdgein interfaceGraph- Parameters:
e- the edge to delete.- Throws:
GraphElementNotFoundException- if the edge to delete cannot be found in the graph.
-
deleteNode
Deletes the given node. First all in- and out-going edges will be deleted usingdeleteEdge()and thereby informs the ListenerManager implicitly. Then deletes the node and informs the ListenerManager about the deletion.- Specified by:
deleteNodein interfaceGraph- Parameters:
n- the node to delete.- Throws:
GraphElementNotFoundException- if the node to delete cannot be found in the graph.
-
removeAttributeConsumer
Returnstrue, if the given attribute consumer was in the list of attribute consumers and could be removed.- Specified by:
removeAttributeConsumerin interfaceGraph- Parameters:
attConsumer- DOCUMENT ME!- Returns:
true, if the given attribute consumer was in the list of attribute consumers and could be removed.
-