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 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 newEdge
to the currentGraph
.Edge
addEdge(Node source, Node target, boolean directed, CollectionAttribute col)
Adds a newEdge
to the currentGraph
.Edge
addEdgeCopy(Edge edge, Node source, Node target)
Adds a copy of the specifiedEdge
to theGraph
as a newEdge
between the specified source and targetNode
.Collection<GraphElement>
addGraph(Graph g)
Adds aGraph
g to the currentGraph
.Node
addNode()
Adds a newNode
to theGraph
.Node
addNode(CollectionAttribute col)
Adds a new node to the graph.Node
addNodeCopy(Node node)
Adds a copy of the specifiedNode
to theGraph
.void
checkMaxGraphElementId(long id)
void
clear()
Deletes the currentGraph
by resetting all its attributes.boolean
containsEdge(Edge e)
Returnstrue
, if theGraph
contains the specifiedEdge
,false
otherwise.boolean
containsNode(Node n)
Returnstrue
, if theGraph
contains the specifiedNode
,false
otherwise.void
deleteAll(Collection<? extends GraphElement> graphelements)
void
deleteEdge(Edge e)
DeletesEdge
e from the currentGraph
.void
deleteNode(Node n)
Deletes theNode
n.long
generateNextUniqueGraphElementId()
returns a unique id for a new graphelement added to this graphAttributeTypesManager
getAttTypesManager()
Returns theAttributeTypesManager
of theGraph
.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 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
.String
getFileTypeDescription()
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.String
getName()
String
getName(boolean fullName)
List<Node>
getNodes()
Returns ajava.util.List
containing all the nodes of theGraph
.Iterator<Node>
getNodesIterator()
Returns an iterator over the nodes of theGraph
.int
getNumberOfDirectedEdges()
Returns the number of directed edges of theGraph
.int
getNumberOfEdges()
Returns the number of edges of theGraph
.int
getNumberOfNodes()
Returns the number of nodes in theGraph
.int
getNumberOfUndirectedEdges()
Returns the number of undirected edges in theGraph
.boolean
isDirected()
Indicates whether theGraph
is directed.boolean
isEmpty()
Returnstrue
if theGraph
is empty.boolean
isModified()
Indicates whether theGraph
has been modified.boolean
isUndirected()
Indicates whether theGraph
is undirected.void
numberGraphElements()
This method should number (setId
all nodes globally unique.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)
When passing a true value, all undirected edges in the graph will be set 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.void
setFileTypeDescription(String fileTypeDescription)
Sets a file type description which can be used to choose an appropriate output serializer independent of the file extension.void
setListenerManager(ListenerManager object)
void
setModified(boolean modified)
Should be set to False after saving changes and to True after making changes to the Graph.void
setName(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 theAttributeTypesManager
of theGraph
.- Returns:
- the
AttributeTypesManager
of theGraph
.
-
isDirected
boolean isDirected()Indicates whether theGraph
is directed. AGraph
is directed if all the edges are directed.- Returns:
true
if theGraph
is directedfalse
otherwise.
-
isModified
boolean isModified()Indicates whether theGraph
has been modified. A call tosetModified
can 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.Collection
containing all the edges of the currentGraph
.- Returns:
- a
java.util.Collection
containing all the edges of the currentGraph
.
-
getEdges
Returns a collection containing all the edges between n1 and n2. There can be more than oneEdge
between two nodes. The edges returned by this method can go from n1 to n2 or vice versa, be directed or not.- Parameters:
n1
- the firstNode
n2
- the secondNode
- Returns:
- a
Collection
containing all edges between n1 and n2, an empty collection if there is noEdge
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 theGraph
.- Returns:
- an iterator over the edges of the
Graph
.
-
isEmpty
boolean isEmpty()Returnstrue
if theGraph
is empty. E.g. theGraph
is equal to aGraph
which has been cleared.- Returns:
true
if theGraph
is empty,false
otherwise.
-
getGraphElements
Collection<GraphElement> getGraphElements()Returns all nodes and all edges contained in this graph.- Returns:
- Collection
-
getNodes
Returns ajava.util.List
containing all the nodes of theGraph
.- Returns:
- a
java.util.List
containing all the nodes of theGraph
.
-
getNodesIterator
Returns an iterator over the nodes of theGraph
. If theGraph
is 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 theGraph
is undirected. AGraph
is undirected if all the edges are undirected.- Returns:
true
if theGraph
is undirected,false
otherwise.
-
addAttributeConsumer
Adds the given attribute consumer to the list of attribute consumers.- Parameters:
attConsumer
- the attribute consumer to add.- Throws:
UnificationException
-
addEdge
Adds a newEdge
to the currentGraph
. Informs the ListenerManager about the newEdge
.- Parameters:
source
- the source of theEdge
to add.target
- the target of theEdge
to add.directed
-true
if theEdge
shall be directed,false
otherwise.- 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 newEdge
to the currentGraph
. Informs the ListenerManager about the newEdge
.- Parameters:
source
- the source of theEdge
to add.target
- the target of theEdge
to add.directed
-true
if theEdge
shall be directed,false
otherwise.col
- theCollectionAttribute
this 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 specifiedEdge
to theGraph
as a newEdge
between 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
- theEgde
which to copy and add.source
- the sourceNode
of the copied and addedEdge
.target
- the targetNode
of the copied and addedEdge
.- Returns:
- DOCUMENT ME!
-
addGraph
Adds aGraph
g to the currentGraph
.Graph
g 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
- theGraph
to be added.
-
addNode
Node addNode()Adds a newNode
to 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
- theCollectionAttribute
the node is initialized with.- Returns:
- the new node.
-
addNodeCopy
Adds a copy of the specifiedNode
to theGraph
. Informs the ListenerManager about the newly addedNode
in the same way as if a completely newNode
was added. Also informs the ListenerManager about the addition of attributes.- Parameters:
node
- theNode
which to copy and to add.- Returns:
- DOCUMENT ME!
-
clear
void clear()Deletes the currentGraph
by resetting all its attributes. TheGraph
is then equal to a newly generatedGraph
. -
containsEdge
Returnstrue
, if theGraph
contains the specifiedEdge
,false
otherwise.- Parameters:
e
- theEdge
to seach for- Returns:
true
, if theGraph
contains the specifiedEdge
,false
otherwise.
-
containsNode
Returnstrue
, if theGraph
contains the specifiedNode
,false
otherwise.- Parameters:
n
- theNode
to search for.- Returns:
true
, if theGraph
contains theNode
n,false
otherwise.
-
deleteEdge
DeletesEdge
e from the currentGraph
. Informs the ListenerManager about the deletion.- Parameters:
e
- theEdge
to delete.- Throws:
GraphElementNotFoundException
- if theEdge
to delete cannot be found in theGraph
.
-
deleteNode
Deletes theNode
n. All in- and out-going edges will be deleted. Informs the ListenerManager about the deletion of theNode
and the concerned edges.- Parameters:
n
- theNode
to delete.- Throws:
GraphElementNotFoundException
- if theNode
to 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 (setId
all 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
-