Class OptAdjListGraph

All Implemented Interfaces:
Attributable, DeepCopy, Graph

public class OptAdjListGraph
extends AdjListGraph
implements Graph
Implements the Graph-interface using an adjacency list representation of the graph. Requires AdjListNode and AdjListEdge as implementations for nodes and edges. Every method modifying the graph will inform the ListenerManager about the modification according to the description in Graph.
Version:
$Revision: 1.7 $
See Also:
Graph, AbstractGraph, AdjListNode, AdjListEdge, AbstractNode, AbstractEdge
  • Constructor Details

    • OptAdjListGraph

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

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

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

      public OptAdjListGraph​(ListenerManager listenerManager, CollectionAttribute coll)
      Constructs a new instance of an OptAdjListGraph. 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 OptAdjListGraph instance.
    • OptAdjListGraph

      public OptAdjListGraph​(Graph g, ListenerManager listenerManager)
      Constructs a new instance of an OptAdjListGraph from an instance of any Graph implementation. Copies all nodes and edges from g into the new graph.
      Parameters:
      g - any Graph implementation out of which an OptAdjListGraph shall be generated.
      listenerManager - listener manager for the graph.
    • OptAdjListGraph

      public OptAdjListGraph​(Graph g, ListenerManager listenerManager, CollectionAttribute coll)
      Constructs a new instance of an OptAdjListGraph from an instance of any Graph implementation. Copies all nodes and edges from g into the new graph.
      Parameters:
      g - any Graph implementation out of which an OptAdjListGraph shall be generated.
      listenerManager - listener manager for the graph.
      coll - the CollectionAttribute of the currently created OptAdjListGraph instance.
  • Method Details

    • isDirected

      public boolean isDirected()
      Indicates whether the graph is directed. A graph is directed if graph setting states this.
      Specified by:
      isDirected in interface Graph
      Overrides:
      isDirected in class AbstractGraph
      Returns:
      a boolean indicating whether the graph is directed.
    • getEdges

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

      public Iterator<Edge> getEdgesIterator()
      Returns an iterator over the edges of the graph. Note that the remove operation is not supported by this iterator.
      Specified by:
      getEdgesIterator in interface Graph
      Overrides:
      getEdgesIterator in class AbstractGraph
      Returns:
      an iterator containing 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
      Overrides:
      isEmpty in class AbstractGraph
      Returns:
      true if the graph is empty, false otherwise.
    • getNodes

      public List<Node> getNodes()
      Returns a list containing a copy of the node list of the graph. Removing elements from this collection will have no effect on the graph whereas nodes can be modified.
      Specified by:
      getNodes in interface Graph
      Overrides:
      getNodes in class AdjListGraph
      Returns:
      a new java.util.List containing all the nodes of the graph.
    • getNodesIterator

      public Iterator<Node> getNodesIterator()
      Returns an iterator over the nodes of the graph. Note that the remove operation is not supported by this iterator.
      Specified by:
      getNodesIterator in interface Graph
      Overrides:
      getNodesIterator in class AdjListGraph
      Returns:
      an iterator containing the nodes of the graph.
    • getNumberOfDirectedEdges

      public int getNumberOfDirectedEdges()
      Returns the number of directed edges of the graph.
      Specified by:
      getNumberOfDirectedEdges in interface Graph
      Overrides:
      getNumberOfDirectedEdges in class AbstractGraph
      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
      Overrides:
      getNumberOfEdges in class AdjListGraph
      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
      Overrides:
      getNumberOfNodes in class AdjListGraph
      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
      Overrides:
      getNumberOfUndirectedEdges in class AbstractGraph
      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
      Overrides:
      isUndirected in class AbstractGraph
      Returns:
      A boolean indicating whether the graph is undirected.
    • containsEdge

      public boolean containsEdge​(Edge e)
      Returns true, if the graph contains the specified edge, false otherwise.
      Specified by:
      containsEdge in interface Graph
      Overrides:
      containsEdge in class AbstractGraph
      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
      Overrides:
      containsNode in class AbstractGraph
      Parameters:
      n - the node to search for.
      Returns:
      true, if the graph contains the node n, false otherwise.
    • copy

      public Object copy()
      Creates and returns a copy of the graph. The attributes are copied as well as all nodes and edges.
      Specified by:
      copy in interface DeepCopy
      Overrides:
      copy in class AdjListGraph
      Returns:
      a copy of the graph.