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 Details

    • getAttTypesManager

      AttributeTypesManager getAttTypesManager()
      Returns the AttributeTypesManager of the Graph.
      Returns:
      the AttributeTypesManager of the Graph.
    • isDirected

      boolean isDirected()
      Indicates whether the Graph is directed. A Graph is directed if all the edges are directed.
      Returns:
      true if the Graph is directed false otherwise.
    • isModified

      boolean isModified()
      Indicates whether the Graph has been modified. A call to setModified 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 to true.
      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 a java.util.Collection containing all the edges of the current Graph.
      Returns:
      a java.util.Collection containing all the edges of the current Graph.
    • getEdges

      Collection<Edge> getEdges​(Node n1, Node n2)
      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.
      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

      Iterator<Edge> getEdgesIterator()
      Returns an iterator over the edges of the Graph.
      Returns:
      an iterator over the edges of the Graph.
    • isEmpty

      boolean isEmpty()
      Returns true if the Graph is empty. E.g. the Graph is equal to a Graph which has been cleared.
      Returns:
      true if the Graph is empty, false otherwise.
    • getGraphElements

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

      List<Node> getNodes()
      Returns a java.util.List containing all the nodes of the Graph.
      Returns:
      a java.util.List containing all the nodes of the Graph.
    • getNodesIterator

      Iterator<Node> getNodesIterator()
      Returns an iterator over the nodes of the Graph. If the Graph 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 the Graph.
      Returns:
      the number of directed edges of the Graph.
    • getNumberOfEdges

      int getNumberOfEdges()
      Returns the number of edges of the Graph.
      Returns:
      the number of edges of the Graph.
    • getNumberOfNodes

      int getNumberOfNodes()
      Returns the number of nodes in the Graph.
      Returns:
      the number of nodes in the Graph.
    • getNumberOfUndirectedEdges

      int getNumberOfUndirectedEdges()
      Returns the number of undirected edges in the Graph.
      Returns:
      the number of undirected edges in the Graph.
    • isUndirected

      boolean isUndirected()
      Indicates whether the Graph is undirected. A Graph is undirected if all the edges are undirected.
      Returns:
      true if the Graph is undirected, false otherwise.
    • addAttributeConsumer

      void addAttributeConsumer​(AttributeConsumer attConsumer) throws UnificationException
      Adds the given attribute consumer to the list of attribute consumers.
      Parameters:
      attConsumer - the attribute consumer to add.
      Throws:
      UnificationException
    • addEdge

      Edge addEdge​(Node source, Node target, boolean directed) throws GraphElementNotFoundException
      Adds a new Edge to the current Graph. Informs the ListenerManager about the new Edge.
      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 newly generated Edge.
      Throws:
      GraphElementNotFoundException - if any of the nodes cannot be found in the Graph.
    • addEdge

      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 Edge.
      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 this edge is initialized with.
      Returns:
      the newly generated Edge.
      Throws:
      GraphElementNotFoundException - if any of the nodes cannot be found in the Graph.
    • addEdgeCopy

      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. Also informs the ListenerManager about the copy of the attributes added to the Edge.
      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

      Collection<GraphElement> 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.
      Parameters:
      g - the Graph to be added.
    • addNode

      Node addNode()
      Adds a new Node to the Graph. Informs the ListenerManager about the new Node.
      Returns:
      the new Node.
    • addNode

      Node addNode​(CollectionAttribute col)
      Adds a new node to the graph. Informs the ListenerManager about the new node.
      Parameters:
      col - the CollectionAttribute the node is initialized with.
      Returns:
      the new node.
    • addNodeCopy

      Node addNodeCopy​(Node node)
      Adds a copy of the specified Node to the Graph. 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.
      Parameters:
      node - the Node which to copy and to add.
      Returns:
      DOCUMENT ME!
    • clear

      void clear()
      Deletes the current Graph by resetting all its attributes. The Graph is then equal to a newly generated Graph.
    • containsEdge

      boolean containsEdge​(Edge e)
      Returns true, if the Graph contains the specified Edge, false otherwise.
      Parameters:
      e - the Edge to seach for
      Returns:
      true, if the Graph contains the specified Edge, false otherwise.
    • containsNode

      boolean containsNode​(Node n)
      Returns true, if the Graph contains the specified Node, false otherwise.
      Parameters:
      n - the Node to search for.
      Returns:
      true, if the Graph contains the Node n, false otherwise.
    • deleteEdge

      void deleteEdge​(Edge e) throws GraphElementNotFoundException
      Deletes Edge e from the current Graph. Informs the ListenerManager about the deletion.
      Parameters:
      e - the Edge to delete.
      Throws:
      GraphElementNotFoundException - if the Edge to delete cannot be found in the Graph.
    • deleteNode

      void deleteNode​(Node n) throws GraphElementNotFoundException
      Deletes the Node n. All in- and out-going edges will be deleted. Informs the ListenerManager about the deletion of the Node and the concerned edges.
      Parameters:
      n - the Node to delete.
      Throws:
      GraphElementNotFoundException - if the Node to delete cannot be found in the Graph.
    • removeAttributeConsumer

      boolean removeAttributeConsumer​(AttributeConsumer attConsumer)
      Returns true, 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

      void deleteAll​(Collection<? extends GraphElement> graphelements)
    • setName

      void setName​(String name)
      The name can be retrieved with the method getName.
      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. Calls getName(false) to return a short name. E.g. just the filename and not the full name with file path.
    • getName

      String getName​(boolean fullName)
      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

      void setListenerManager​(ListenerManager object)
    • setFileTypeDescription

      void setFileTypeDescription​(String fileTypeDescription)
      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