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 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.Collection<GraphElement>
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)
Returnstrue
, 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)
Returnstrue
, if the graph contains the specified edge,false
otherwise.boolean
containsNode(Node n)
Returnstrue
, if the graph contains the specified node,false
otherwise.void
deleteEdge(Edge e)
Deletes the given edge from the current graph.void
deleteNode(Node n)
Deletes the given node.long
generateNextUniqueGraphElementId()
returns a unique id for a new graphelement added to this graphAttributeTypesManager
getAttTypesManager()
Returns theAttributeTypesManager
of the graph.long
getCurrentMaxGraphElementId()
returns current max id of the last added graph element without incrementing itCollection<Edge>
getEdges()
Returns ajava.util.Collection
containing 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.ListenerManager
getListenerManager()
Returns the ListenerManager of the current 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()
Returnstrue
if the graph is empty.boolean
isUndirected()
Indicates whether the graph is undirected.boolean
removeAttributeConsumer(AttributeConsumer attConsumer)
Returnstrue
, if the given attribute consumer was in the list of attribute consumers and could be removed.void
setDirected(boolean directed)
Sets all edges to bedirected
.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, 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.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, setString
Methods 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 theListenerManager
of the new instance to the defaultListenerManager
. -
AbstractGraph
Constructs a new instance of anAbstractGraph
. Sets theListenerManager
of the new instance to the defaultListenerManager
.- Parameters:
coll
- theCollectionAttribute
of the currently createdAbstractGraph
instance.
-
AbstractGraph
Constructs a new instance of anAdjListGraph
. Sets theListenerManager
of the new instance to the specified one.- Parameters:
listenerManager
- listener manager for the graph.
-
AbstractGraph
Constructs a new instance of anAdjListGraph
. Sets theListenerManager
of the new instance to the specified one.- Parameters:
listenerManager
- listener manager for the graph.coll
- theCollectionAttribute
of the currently createdAbstractGraph
instance.
-
-
Method Details
-
getAttTypesManager
Returns theAttributeTypesManager
of the graph.- Specified by:
getAttTypesManager
in interfaceGraph
- Returns:
- the
AttributeTypesManager
of the graph.
-
isDirected
public boolean isDirected()Indicates whether the graph is directed. A graph is directed if the graph setting states this.- Specified by:
isDirected
in interfaceGraph
- Returns:
- a boolean indicating whether the graph is directed.
-
setDirected
public void setDirected(boolean directed)Sets all edges to bedirected
.If
directed
istrue
, standard arrows are set, if it isfalse
, all arrows of all edges are removed.- Specified by:
setDirected
in 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:
setDirected
in interfaceGraph
- Parameters:
directed
-adjustArrows
-
-
generateNextUniqueGraphElementId
public long generateNextUniqueGraphElementId()Description copied from interface:Graph
returns a unique id for a new graphelement added to this graph- Specified by:
generateNextUniqueGraphElementId
in interfaceGraph
- Returns:
-
getCurrentMaxGraphElementId
public long getCurrentMaxGraphElementId()Description copied from interface:Graph
returns current max id of the last added graph element without incrementing it- Specified by:
getCurrentMaxGraphElementId
in interfaceGraph
- Returns:
-
getEdges
Returns ajava.util.Collection
containing 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:
getEdges
in interfaceGraph
- 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
Returns an iterator over the edges of the graph.- Specified by:
getEdgesIterator
in interfaceGraph
- Returns:
- an iterator over the edges of the graph.
-
isEmpty
public boolean isEmpty()Returnstrue
if 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:
getGraphElements
in interfaceGraph
- Returns:
- Collection
-
getListenerManager
Returns the ListenerManager of the current graph.- Specified by:
getListenerManager
in interfaceAttributable
- Returns:
- the ListenerManager of the current graph.
-
getNumberOfDirectedEdges
public int getNumberOfDirectedEdges()Returns the number of directed edges of the graph.- Specified by:
getNumberOfDirectedEdges
in interfaceGraph
- 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 interfaceGraph
- Returns:
- the number of edges of the graph.
-
getNumberOfNodes
public int getNumberOfNodes()Returns the number of nodes in the graph.- Specified by:
getNumberOfNodes
in interfaceGraph
- 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 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:
isUndirected
in interfaceGraph
- Returns:
- A boolean indicating whether the graph is undirected.
-
addAttributeConsumer
Adds the given attribute consumer to the list of attribute consumers.- Specified by:
addAttributeConsumer
in 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 thedefaultEdgeAttributes
after thepreEdgeAdded
and before thepostEdgeAdded
event.- Specified by:
addEdge
in interfaceGraph
- 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 GraphElementNotFoundExceptionAdds a new edge to the current graph. Informs the ListenerManager about the new node. This method does not add anydefaultEdgeAttributes
.- Specified by:
addEdge
in interfaceGraph
- 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
- theCollectionAttribute
with 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:
addEdgeCopy
in interfaceGraph
- Parameters:
edge
- theEgde
which to copy and add.source
- the sourceNode
of the copied and added edge.target
- the targetNode
of 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 thedefaultNodeAttribute
to the newly created node (after thepreNodeAdded
event and before thepostNodeAdded
event). -
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:
addNodeCopy
in interfaceGraph
- Parameters:
node
- theNode
which to copy and to add.- Returns:
- the newly created node.
-
areConnected
Returnstrue
, 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 n2false
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. -
containsEdge
Returnstrue
, if the graph contains the specified edge,false
otherwise.- Specified by:
containsEdge
in interfaceGraph
- Parameters:
e
- the edge to search for.- Returns:
true
, if the graph contains the edge e,false
otherwise.
-
containsNode
Returnstrue
, if the graph contains the specified node,false
otherwise.- Specified by:
containsNode
in interfaceGraph
- Parameters:
n
- the node to search for.- Returns:
true
, if the graph contains the node n,false
otherwise.
-
deleteEdge
Deletes the given edge from the current graph. Informs the ListenerManager about the deletion.- Specified by:
deleteEdge
in 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:
deleteNode
in 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:
removeAttributeConsumer
in interfaceGraph
- Parameters:
attConsumer
- DOCUMENT ME!- Returns:
true
, if the given attribute consumer was in the list of attribute consumers and could be removed.
-