Class Graph<V>


  • public class Graph<V>
    extends Object
    Graph with nodes and edges
    • Field Detail

      • nodes

        private final List<Node<V>> nodes
        The list of nodes
      • edges

        private final List<Edge<V>> edges
        The list of edges
    • Constructor Detail

      • Graph

        public Graph()
        Constructor initializing the lists of nodes and edges with empty lists.
    • Method Detail

      • addNode

        public Node<V> addNode​(V value)
        Adds a node with a given value to the graph.
        Parameters:
        value - the value in the node
        Returns:
        the node added
      • connect

        public Edge<V> connect​(Node<V> from,
                               Node<V> to,
                               int weight)
        Connects two nodes with a given weight.
        Parameters:
        from - the source node
        to - the destination node
        weight - the weight
        Returns:
        the edge
      • biConnect

        public void biConnect​(Node<V> from,
                              Node<V> to,
                              int weight)
        Makes a bidirectional connection of two nodes with a given weight.
        Parameters:
        from - the first node
        to - the second node
        weight - the weight
      • getNodes

        public List<Node<V>> getNodes()
        Returns the list of nodes of this graph.
        Returns:
        the list of nodes
      • getEdges

        public List<Edge<V>> getEdges()
        Returns the list of edges of this graph.
        Returns:
        the list of edges