Class BasicGraph

    • Constructor Detail

      • 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 Detail

      • setNodes

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

        public void setEdges​(Collection<Edge> edges)
        Sets the edge collection for the graph.
        Parameters:
        edges - Collection of Edge objects.
      • 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:
        Graph.queryNodes(GraphVisitor)
      • 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:
        Graph.queryEdges(GraphVisitor)
      • 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:
        Graph.getNodesOfDegree(int), Node.getDegree()
      • 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:
        Graph.getVisitedNodes(boolean)
      • 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:
        Graph.getVisitedEdges(boolean)
      • 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.