Class 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 Details

    • AbstractGraph

      public AbstractGraph()
      Constructs a new instance of an AbstractGraph. Sets the ListenerManager of the new instance to the default ListenerManager.
    • AbstractGraph

      public AbstractGraph​(CollectionAttribute coll)
      Constructs a new instance of an AbstractGraph. Sets the ListenerManager of the new instance to the default ListenerManager.
      Parameters:
      coll - the CollectionAttribute of the currently created AbstractGraph instance.
    • AbstractGraph

      public AbstractGraph​(ListenerManager listenerManager)
      Constructs a new instance of an AdjListGraph. Sets the ListenerManager of the new instance to the specified one.
      Parameters:
      listenerManager - listener manager for the graph.
    • AbstractGraph

      public AbstractGraph​(ListenerManager listenerManager, CollectionAttribute coll)
      Constructs a new instance of an AdjListGraph. Sets the ListenerManager of the new instance to the specified one.
      Parameters:
      listenerManager - listener manager for the graph.
      coll - the CollectionAttribute of the currently created AbstractGraph instance.
  • Method Details

    • getAttTypesManager

      public AttributeTypesManager getAttTypesManager()
      Returns the AttributeTypesManager of the graph.
      Specified by:
      getAttTypesManager in interface Graph
      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 interface Graph
      Returns:
      a boolean indicating whether the graph is directed.
    • setDirected

      public void setDirected​(boolean directed)
      Sets all edges to be directed.

      If directed is true, standard arrows are set, if it is false, all arrows of all edges are removed.

      Specified by:
      setDirected in interface Graph
      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 interface Graph
      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 interface Graph
      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 interface Graph
      Returns:
    • getEdges

      public Collection<Edge> getEdges()
      Returns a java.util.Collection containing all the edges of the current graph.
      Specified by:
      getEdges in interface Graph
      Returns:
      a java.util.Collection containing all the edges of the current graph.
    • getEdges

      public Collection<Edge> getEdges​(Node n1, Node n2) throws GraphElementNotFoundException
      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 interface Graph
      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

      public Iterator<Edge> getEdgesIterator()
      Returns an iterator over the edges of the graph.
      Specified by:
      getEdgesIterator in interface Graph
      Returns:
      an iterator over the edges of the graph.
    • isEmpty

      public boolean isEmpty()
      Returns true if the graph is empty. The graph is equal to a graph which has been cleared.
      Specified by:
      isEmpty in interface Graph
      Returns:
      true if the graph is empty, false otherwise.
    • getGraphElements

      public Collection<GraphElement> getGraphElements()
      Returns all nodes and all edges contained in this graph.
      Specified by:
      getGraphElements in interface Graph
      Returns:
      Collection
    • getListenerManager

      public ListenerManager getListenerManager()
      Returns the ListenerManager of the current graph.
      Specified by:
      getListenerManager in interface Attributable
      Returns:
      the ListenerManager of the current graph.
    • getNumberOfDirectedEdges

      public int getNumberOfDirectedEdges()
      Returns the number of directed edges of the graph.
      Specified by:
      getNumberOfDirectedEdges in interface Graph
      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 interface Graph
      Returns:
      the number of edges of the graph.
    • getNumberOfNodes

      public int getNumberOfNodes()
      Returns the number of nodes in the graph.
      Specified by:
      getNumberOfNodes in interface Graph
      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 interface Graph
      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 interface Graph
      Returns:
      A boolean indicating whether the graph is undirected.
    • addAttributeConsumer

      public void addAttributeConsumer​(AttributeConsumer attConsumer) throws UnificationException
      Adds the given attribute consumer to the list of attribute consumers.
      Specified by:
      addAttributeConsumer in interface Graph
      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 GraphElementNotFoundException
      Adds a new edge to the current graph. Informs the ListenerManager about the new node. This method adds a copy of the defaultEdgeAttributes after the preEdgeAdded and before the postEdgeAdded event.
      Specified by:
      addEdge in interface Graph
      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 GraphElementNotFoundException
      Adds a new edge to the current graph. Informs the ListenerManager about the new node. This method does not add any defaultEdgeAttributes.
      Specified by:
      addEdge in interface Graph
      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 with which the edge is initialized.
      Returns:
      the new edge.
      Throws:
      GraphElementNotFoundException - if any of the nodes cannot be found in the graph.
    • addEdgeCopy

      public 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 through the call to addEdge(). Also informs the ListenerManager about the copy of the attributes added to the edge by adding them separatly throug CollectionAttribute.add(Attribute).
      Specified by:
      addEdgeCopy in interface Graph
      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

      public 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.
      Specified by:
      addGraph in interface Graph
      Parameters:
      g - the Graph to be added.
    • addNode

      public Node addNode()
      Adds a new node to the graph. Informs the ListenerManager about the new node. This method adds a copy of the defaultNodeAttribute to the newly created node (after the preNodeAdded event and before the postNodeAdded event).
      Specified by:
      addNode in interface Graph
      Returns:
      the new node.
    • addNode

      public Node addNode​(CollectionAttribute col)
      Adds a new node to the graph. Informs the ListenerManager about the new node. Default node attributes (defaultNodeAttribute) are not added by this method.
      Specified by:
      addNode in interface Graph
      Parameters:
      col - the CollectionAttribute the node is initialized with.
      Returns:
      the new node.
    • addNodeCopy

      public Node addNodeCopy​(Node node)
      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 the add(Attribute) method of CollectionAttribute.
      Specified by:
      addNodeCopy in interface Graph
      Parameters:
      node - the Node which to copy and to add.
      Returns:
      the newly created node.
    • areConnected

      public boolean areConnected​(Node n1, Node n2) throws GraphElementNotFoundException
      Returns true, 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 n2 false 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.
      Specified by:
      clear in interface Graph
    • containsEdge

      public boolean containsEdge​(Edge e)
      Returns true, if the graph contains the specified edge, false otherwise.
      Specified by:
      containsEdge in interface Graph
      Parameters:
      e - the edge to search for.
      Returns:
      true, if the graph contains the edge e, false otherwise.
    • containsNode

      public boolean containsNode​(Node n)
      Returns true, if the graph contains the specified node, false otherwise.
      Specified by:
      containsNode in interface Graph
      Parameters:
      n - the node to search for.
      Returns:
      true, if the graph contains the node n, false otherwise.
    • deleteEdge

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

      public void deleteNode​(Node n) throws GraphElementNotFoundException
      Deletes the given node. First all in- and out-going edges will be deleted using deleteEdge() and thereby informs the ListenerManager implicitly. Then deletes the node and informs the ListenerManager about the deletion.
      Specified by:
      deleteNode in interface Graph
      Parameters:
      n - the node to delete.
      Throws:
      GraphElementNotFoundException - if the node to delete cannot be found in the graph.
    • removeAttributeConsumer

      public boolean removeAttributeConsumer​(AttributeConsumer attConsumer)
      Returns true, if the given attribute consumer was in the list of attribute consumers and could be removed.
      Specified by:
      removeAttributeConsumer in interface Graph
      Parameters:
      attConsumer - DOCUMENT ME!
      Returns:
      true, if the given attribute consumer was in the list of attribute consumers and could be removed.