Class BasicGraph

Object
BasicGraph
All Implemented Interfaces:
Serializable, Graph
Direct Known Subclasses:
BasicDirectedGraph

public class BasicGraph extends Object implements Graph, Serializable
Basic implemenation of Graph.
Author:
Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
See Also:
  • Constructor Details

    • BasicGraph

      public BasicGraph()
      Constructs an empty graph with edge and node collections uninitialized. Mainly for serializability purposes.
    • BasicGraph

      public BasicGraph(Collection<Node> nodes, Collection<Edge> edges)
      Constructs a graph from a collection of nodes and a collection of edges. The relationships between the nodes (edges) are already assumed to be formed. Only the references to the node and edge collections are copied, not the underlying collections themselves.
      Parameters:
      nodes - Collection of nodes to be contained by the graph.
      edges - Collection of edges to be contained by the graph.
  • Method Details

    • setNodes

      public void setNodes(Collection<Node> nodes)
      Sets the node collection of the graph.
      Parameters:
      nodes - Collection of Node objects.
    • getNodes

      public Collection<Node> getNodes()
      Description copied from interface: Graph
      Returns the nodes of the graph.
      Specified by:
      getNodes in interface Graph
      Returns:
      A collection of Node objects.
      See Also:
    • setEdges

      public void setEdges(Collection<Edge> edges)
      Sets the edge collection for the graph.
      Parameters:
      edges - Collection of Edge objects.
    • getEdges

      public Collection<Edge> getEdges()
      Description copied from interface: Graph
      Returns the edges of the graph.
      Specified by:
      getEdges in interface Graph
      Returns:
      A collection of Edge objects.
      See Also:
    • queryNodes

      public List<Node> queryNodes(GraphVisitor visitor)
      Description copied from interface: Graph
      Performs a query against the nodes of the graph. Each Node object contained in the graph is passed to a GraphVisitor to determine if it meets the query criteria.
      Specified by:
      queryNodes in interface Graph
      Parameters:
      visitor - Determines if node meets query criteria. Returns MEET_AND_CONTINUE to signal that the node meets the query criteria and the query should continue.
      Returns MEET_AND_STOP to signal that the node meest the query criteria and the query should stop.
      FAIL_QUERY to signal that the node does NOT meet the query criteria.
      Returns:
      A collection of nodes that meet the query criteria.
      See Also:
    • queryEdges

      public List<Edge> queryEdges(GraphVisitor visitor)
      Description copied from interface: Graph
      Performs a query against the edges of the graph. Each Edge object contained in the graph is passed to a GraphVisitor to determine if it meets the query criteria.
      Specified by:
      queryEdges in interface Graph
      Parameters:
      visitor - Determines if the meets the query criteria.
      Returns MEET_AND_CONTINUE to signal that the edge meets the query criteria and the query should continue.
      Returns MEET_AND_STOP to signal that the edge meest the query criteria and the query should stop.
      FAIL_QUERY to signal that the edge does NOT meet the query criteria.
      Returns:
      A collection of edges that meet the query criteria.
      See Also:
    • visitNodes

      public void visitNodes(GraphVisitor visitor)
      Description copied from interface: Graph
      Applies the visitor pattern to the nodes of the graph.
      Specified by:
      visitNodes in interface Graph
      See Also:
    • visitEdges

      public void visitEdges(GraphVisitor visitor)
      Description copied from interface: Graph
      Applies the visitor pattern to the edges of the graph.
      Specified by:
      visitEdges in interface Graph
      See Also:
    • getNodesOfDegree

      public List<Node> getNodesOfDegree(int n)
      Description copied from interface: Graph
      Returns all the nodes in the graph of a specified degree. The degree of a node is the number of edges that are adjacent to the node.
      Specified by:
      getNodesOfDegree in interface Graph
      Parameters:
      n - The desired degree of nodes to be returned.
      Returns:
      A collection of nodes of degree n.
      See Also:
    • getVisitedNodes

      public List<Node> getVisitedNodes(boolean visited)
      Description copied from interface: Graph
      Returns all the nodes in the graph that have been marked as visited or non-visited.
      Specified by:
      getVisitedNodes in interface Graph
      Parameters:
      visited - True if node is visited, false if node is unvisited.
      Returns:
      List of nodes marked as visited / non-visited.
      See Also:
    • getVisitedEdges

      public List<Edge> getVisitedEdges(boolean visited)
      Description copied from interface: Graph
      Returns all the edges in the graph that have been marked as visited or non-visited.
      Specified by:
      getVisitedEdges in interface Graph
      Parameters:
      visited - True if edge is visited, false if edge is unvisited.
      Returns:
      List of edges marked as visited / non-visited.
      See Also:
    • initNodes

      public void initNodes()
      Initializes the nodes in the graph by setting all visited flags to false and all visited counts to zero.
      See Also:
    • initEdges

      public void initEdges()
      Initializes the edges in the graph by setting all visited flags to false and all visited counts to zero.
      See Also:
    • toString

      public String toString()
      Returns the string representation of the graph which is just the string representation of the edge and node collections.
      Overrides:
      toString in class Object
      Returns:
      String represtentaton of graph.