Class Graph


  • public class Graph
    extends java.lang.Object

    Graph representation using the adjacency list form. See the book 'Introduction to Algorithms' by Cormen, Leiserson, and Rivest.

    Since:
    1.0.0
    Author:
    Abe White
    • Constructor Summary

      Constructors 
      Constructor Description
      Graph()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEdge​(Edge edge)
      Add an edge to the graph.
      void addNode​(java.lang.Object node)
      Add a node to the graph.
      void clear()
      Clear the graph.
      void clearTraversal()
      Clear all nodes and edges of the bookkeeping information from their last traversal.
      boolean containsNode​(java.lang.Object node)
      Return true if the graph contains the given node.
      java.util.Collection<Edge> getEdges()
      Return all edges in the graph.
      java.util.Collection<Edge> getEdges​(java.lang.Object from, java.lang.Object to)
      Return all the edges from one node to another.
      java.util.Collection<Edge> getEdgesFrom​(java.lang.Object node)
      Return all the edges from a particular node.
      java.util.Collection<Edge> getEdgesTo​(java.lang.Object node)
      Return all the edges to a particular node.
      java.util.Collection<java.lang.Object> getNodes()
      Return a view of all nodes in the graph.
      boolean removeEdge​(Edge edge)
      Remove an edge from the graph.
      boolean removeNode​(java.lang.Object node)
      Remove a node from the graph.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Graph

        public Graph()
    • Method Detail

      • clear

        public void clear()
        Clear the graph.
      • containsNode

        public boolean containsNode​(java.lang.Object node)
        Return true if the graph contains the given node.
      • getNodes

        public java.util.Collection<java.lang.Object> getNodes()
        Return a view of all nodes in the graph.
      • addNode

        public void addNode​(java.lang.Object node)
        Add a node to the graph. Adding a node a second time has no effect.
      • removeNode

        public boolean removeNode​(java.lang.Object node)
        Remove a node from the graph. All edges to and from the node will be cleared.
        Returns:
        true if the node was removed, false otherwise
      • getEdges

        public java.util.Collection<Edge> getEdges()
        Return all edges in the graph.
      • getEdgesFrom

        public java.util.Collection<Edge> getEdgesFrom​(java.lang.Object node)
        Return all the edges from a particular node.
      • getEdgesTo

        public java.util.Collection<Edge> getEdgesTo​(java.lang.Object node)
        Return all the edges to a particular node.
      • getEdges

        public java.util.Collection<Edge> getEdges​(java.lang.Object from,
                                                   java.lang.Object to)
        Return all the edges from one node to another.
      • addEdge

        public void addEdge​(Edge edge)
        Add an edge to the graph.
      • removeEdge

        public boolean removeEdge​(Edge edge)
        Remove an edge from the graph.
        Returns:
        true if the edge was removed, false if not in the graph
      • clearTraversal

        public void clearTraversal()
        Clear all nodes and edges of the bookkeeping information from their last traversal.