Package org.graffiti.graph
Interface Graph
- All Superinterfaces:
Attributable,DeepCopy
- All Known Subinterfaces:
CoarsenedGraph
- All Known Implementing Classes:
AbstractGraph,AdjListGraph,OptAdjListGraph
public interface Graph extends Attributable, DeepCopy
A
Graph consists of a set of nodes and a set of edges. These two
sets are not ordered. A Graph is considered directed iff all its
edges are directed, undirected iff all its edges are undirected. A
Graph may contain directed and undirected edges. It can only be
directed and undirected at the same time iff it is empty. Graphs can be
copied. The methode copy() of the interface
org.graffiti.core.DeepCopy returns a copy of the
Graph which contains no references to the original
Graph any more. Every Graph implementation
implements this interface. Graph implementations are to be
observable. This is required e.g. for visualisation. For this reason every
Graph instance contains a ListenerManager which
provides the required functionality. To use this functionality all methods
modifying the Graph should inform the
ListenerManager.
Implementation notes: For example, the method xy() of any
Graph implementation will have to look as follows:
public whatever xy() {
GraphEvent ge = new GraphEvent(...);
listenerManager.preXy(g);
// ...
// here comes the functionality of method xy
// ...
ge = new GraphEvent(...);
listenerManager.postXy(g);
return ... ;
}
- Version:
- $Revision: 1.7.4.1.2.1 $
- See Also:
Node,Edge,Attributable
-
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 newEdgeto the currentGraph.EdgeaddEdge(Node source, Node target, boolean directed, CollectionAttribute col)Adds a newEdgeto the currentGraph.EdgeaddEdgeCopy(Edge edge, Node source, Node target)Adds a copy of the specifiedEdgeto theGraphas a newEdgebetween the specified source and targetNode.Collection<GraphElement>addGraph(Graph g)Adds aGraphg to the currentGraph.NodeaddNode()Adds a newNodeto theGraph.NodeaddNode(CollectionAttribute col)Adds a new node to the graph.NodeaddNodeCopy(Node node)Adds a copy of the specifiedNodeto theGraph.voidcheckMaxGraphElementId(long id)voidclear()Deletes the currentGraphby resetting all its attributes.booleancontainsEdge(Edge e)Returnstrue, if theGraphcontains the specifiedEdge,falseotherwise.booleancontainsNode(Node n)Returnstrue, if theGraphcontains the specifiedNode,falseotherwise.voiddeleteAll(Collection<? extends GraphElement> graphelements)voiddeleteEdge(Edge e)DeletesEdgee from the currentGraph.voiddeleteNode(Node n)Deletes theNoden.longgenerateNextUniqueGraphElementId()returns a unique id for a new graphelement added to this graphAttributeTypesManagergetAttTypesManager()Returns theAttributeTypesManagerof theGraph.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 currentGraph.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 theGraph.StringgetFileTypeDescription()Returns a file type description which can be used to choose an appropriate output serializer independent of the file extension.Collection<GraphElement>getGraphElements()Returns all nodes and all edges contained in this graph.StringgetName()StringgetName(boolean fullName)List<Node>getNodes()Returns ajava.util.Listcontaining all the nodes of theGraph.Iterator<Node>getNodesIterator()Returns an iterator over the nodes of theGraph.intgetNumberOfDirectedEdges()Returns the number of directed edges of theGraph.intgetNumberOfEdges()Returns the number of edges of theGraph.intgetNumberOfNodes()Returns the number of nodes in theGraph.intgetNumberOfUndirectedEdges()Returns the number of undirected edges in theGraph.booleanisDirected()Indicates whether theGraphis directed.booleanisEmpty()Returnstrueif theGraphis empty.booleanisModified()Indicates whether theGraphhas been modified.booleanisUndirected()Indicates whether theGraphis undirected.voidnumberGraphElements()This method should number (setIdall nodes globally unique.booleanremoveAttributeConsumer(AttributeConsumer attConsumer)Returnstrue, if the given attribute consumer was in the list of attribute consumers and could be removed.voidsetDirected(boolean directed)When passing a true value, all undirected edges in the graph will be set to be directed.voidsetDirected(boolean directed, boolean adjustArrows)When passing a true value, all undirected edges in the graph will be set to be directed.voidsetFileTypeDescription(String fileTypeDescription)Sets a file type description which can be used to choose an appropriate output serializer independent of the file extension.voidsetListenerManager(ListenerManager object)voidsetModified(boolean modified)Should be set to False after saving changes and to True after making changes to the Graph.voidsetName(String name)The name can be retrieved with the methodgetName.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, getListenerManager, getLong, getShort, getString, removeAttribute, setBoolean, setByte, setDouble, setFloat, setInteger, setLong, setShort, setString
-
Method Details
-
getAttTypesManager
AttributeTypesManager getAttTypesManager()Returns theAttributeTypesManagerof theGraph.- Returns:
- the
AttributeTypesManagerof theGraph.
-
isDirected
boolean isDirected()Indicates whether theGraphis directed. AGraphis directed if all the edges are directed.- Returns:
trueif theGraphis directedfalseotherwise.
-
isModified
boolean isModified()Indicates whether theGraphhas been modified. A call tosetModifiedcan 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 totrue.- Returns:
- True, if the graph has been modifed, False if not.
-
setModified
void setModified(boolean modified)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.- Parameters:
modified- Indicates the new status of this field.
-
setDirected
void setDirected(boolean directed)When passing a true value, all undirected edges in the graph will be set to be directed. V.v. for a false value.- Parameters:
directed-
-
setDirected
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).- Parameters:
directed-adjustArrows-
-
generateNextUniqueGraphElementId
long generateNextUniqueGraphElementId()returns a unique id for a new graphelement added to this graph- Returns:
-
getCurrentMaxGraphElementId
long getCurrentMaxGraphElementId()returns current max id of the last added graph element without incrementing it- Returns:
-
getEdges
Collection<Edge> getEdges()Returns ajava.util.Collectioncontaining all the edges of the currentGraph.- Returns:
- a
java.util.Collectioncontaining all the edges of the currentGraph.
-
getEdges
Returns a collection containing all the edges between n1 and n2. There can be more than oneEdgebetween two nodes. The edges returned by this method can go from n1 to n2 or vice versa, be directed or not.- Parameters:
n1- the firstNoden2- the secondNode- Returns:
- a
Collectioncontaining all edges between n1 and n2, an empty collection if there is noEdgebetween the two nodes. - Throws:
GraphElementNotFoundException- if one of the nodes is not contained in the graph.
-
getEdgesIterator
Returns an iterator over the edges of theGraph.- Returns:
- an iterator over the edges of the
Graph.
-
isEmpty
boolean isEmpty()Returnstrueif theGraphis empty. E.g. theGraphis equal to aGraphwhich has been cleared.- Returns:
trueif theGraphis empty,falseotherwise.
-
getGraphElements
Collection<GraphElement> getGraphElements()Returns all nodes and all edges contained in this graph.- Returns:
- Collection
-
getNodes
Returns ajava.util.Listcontaining all the nodes of theGraph.- Returns:
- a
java.util.Listcontaining all the nodes of theGraph.
-
getNodesIterator
Returns an iterator over the nodes of theGraph. If theGraphis empty an empty iterator will be returned.- Returns:
- an interator containing the nodes of the
Graph.
-
getNumberOfDirectedEdges
int getNumberOfDirectedEdges()Returns the number of directed edges of theGraph.- Returns:
- the number of directed edges of the
Graph.
-
getNumberOfEdges
int getNumberOfEdges()Returns the number of edges of theGraph.- Returns:
- the number of edges of the
Graph.
-
getNumberOfNodes
int getNumberOfNodes()Returns the number of nodes in theGraph.- Returns:
- the number of nodes in the
Graph.
-
getNumberOfUndirectedEdges
int getNumberOfUndirectedEdges()Returns the number of undirected edges in theGraph.- Returns:
- the number of undirected edges in the
Graph.
-
isUndirected
boolean isUndirected()Indicates whether theGraphis undirected. AGraphis undirected if all the edges are undirected.- Returns:
trueif theGraphis undirected,falseotherwise.
-
addAttributeConsumer
Adds the given attribute consumer to the list of attribute consumers.- Parameters:
attConsumer- the attribute consumer to add.- Throws:
UnificationException
-
addEdge
Adds a newEdgeto the currentGraph. Informs the ListenerManager about the newEdge.- Parameters:
source- the source of theEdgeto add.target- the target of theEdgeto add.directed-trueif theEdgeshall be directed,falseotherwise.- Returns:
- the newly generated
Edge. - Throws:
GraphElementNotFoundException- if any of the nodes cannot be found in theGraph.
-
addEdge
Edge addEdge(Node source, Node target, boolean directed, CollectionAttribute col) throws GraphElementNotFoundExceptionAdds a newEdgeto the currentGraph. Informs the ListenerManager about the newEdge.- Parameters:
source- the source of theEdgeto add.target- the target of theEdgeto add.directed-trueif theEdgeshall be directed,falseotherwise.col- theCollectionAttributethis edge is initialized with.- Returns:
- the newly generated
Edge. - Throws:
GraphElementNotFoundException- if any of the nodes cannot be found in theGraph.
-
addEdgeCopy
Adds a copy of the specifiedEdgeto theGraphas a newEdgebetween the specified source and targetNode. Informs the ListenerManager about the newly addedEdge. Also informs the ListenerManager about the copy of the attributes added to theEdge.- Parameters:
edge- theEgdewhich to copy and add.source- the sourceNodeof the copied and addedEdge.target- the targetNodeof the copied and addedEdge.- Returns:
- DOCUMENT ME!
-
addGraph
Adds aGraphg to the currentGraph.Graphg will be copied and then all its nodes and edges will be added to the currentGraph. Like this g will not be destroyed.- Parameters:
g- theGraphto be added.
-
addNode
Node addNode()Adds a newNodeto theGraph. Informs the ListenerManager about the newNode.- Returns:
- the new
Node.
-
addNode
Adds a new node to the graph. Informs the ListenerManager about the new node.- Parameters:
col- theCollectionAttributethe node is initialized with.- Returns:
- the new node.
-
addNodeCopy
Adds a copy of the specifiedNodeto theGraph. Informs the ListenerManager about the newly addedNodein the same way as if a completely newNodewas added. Also informs the ListenerManager about the addition of attributes.- Parameters:
node- theNodewhich to copy and to add.- Returns:
- DOCUMENT ME!
-
clear
void clear()Deletes the currentGraphby resetting all its attributes. TheGraphis then equal to a newly generatedGraph. -
containsEdge
Returnstrue, if theGraphcontains the specifiedEdge,falseotherwise.- Parameters:
e- theEdgeto seach for- Returns:
true, if theGraphcontains the specifiedEdge,falseotherwise.
-
containsNode
Returnstrue, if theGraphcontains the specifiedNode,falseotherwise.- Parameters:
n- theNodeto search for.- Returns:
true, if theGraphcontains theNoden,falseotherwise.
-
deleteEdge
DeletesEdgee from the currentGraph. Informs the ListenerManager about the deletion.- Parameters:
e- theEdgeto delete.- Throws:
GraphElementNotFoundException- if theEdgeto delete cannot be found in theGraph.
-
deleteNode
Deletes theNoden. All in- and out-going edges will be deleted. Informs the ListenerManager about the deletion of theNodeand the concerned edges.- Parameters:
n- theNodeto delete.- Throws:
GraphElementNotFoundException- if theNodeto delete cannot be found in theGraph.
-
removeAttributeConsumer
Returnstrue, if the given attribute consumer was in the list of attribute consumers and could be removed.- Returns:
true, if the given attribute consumer was in the list of attribute consumers and could be removed.
-
deleteAll
-
setName
The name can be retrieved with the methodgetName.- Parameters:
name- A ID that can be used for identifying the graph - for the user or for the developer.
-
getName
String getName()- Returns:
- A ID that can be used for identifying the graph - for the user or for
the developer. The name can be set with the method
setName. CallsgetName(false)to return a short name. E.g. just the filename and not the full name with file path.
-
getName
- Returns:
- A ID that can be used for identifying the graph - for the user or for
the developer. The name can be set with the method
setName.
-
numberGraphElements
void numberGraphElements()This method should number (setIdall nodes globally unique. -
checkMaxGraphElementId
void checkMaxGraphElementId(long id) -
setListenerManager
-
setFileTypeDescription
Sets a file type description which can be used to choose an appropriate output serializer independent of the file extension.- Parameters:
fileTypeDescription-
-
getFileTypeDescription
String getFileTypeDescription()Returns a file type description which can be used to choose an appropriate output serializer independent of the file extension.- Returns:
- a file type description
-