Class Graph.Vertex<V,E>

java.lang.Object
Graph.Vertex<V,E>
Enclosing class:
Graph<V,E>

public static class Graph.Vertex<V,E> extends Object
A holder class for Vertices that allows each Vertex to track all incident edges and adjacent vertices, as well as store a data entry associated with the vertex.
  • Field Details

    • data

      public V data
      The data associated with this vertex.
  • Constructor Details

    • Vertex

      public Vertex()
      Constructs a vertex without any data.
    • Vertex

      public Vertex(V data)
      Constructs a vertex with the specified data.
      Parameters:
      data - the data to be stored within this vertex
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getEdgeTo

      public Graph.Edge<V,E> getEdgeTo(Graph.Vertex<V,E> other)
      Returns the edge from this vertex to the vertex specified by other. If no such edge exists, returns null.
      Parameters:
      other - the other endpoint of the edge to be returned
      Returns:
      the edge from this vertex to the vertex specified by other. If no such edge exists, returns null.
    • getEdgeFrom

      public Graph.Edge<V,E> getEdgeFrom(Graph.Vertex<V,E> other)
      Returns the edge from the vertex specified by other to this vertex. If no such edge exists, returns null.
      Parameters:
      other - the other endpoint of the edge to be returned
      Returns:
      the edge from the vertex specified by other to this vertex. If no such edge exists, returns null.
    • neighborsOut

      public Collection<Graph.Vertex<V,E>> neighborsOut()
      Returns the collection of vertices reachable from this vertex by a single edge.
      Returns:
      the collection of vertices reachable from this vertex by a single edge.
    • neighborsIn

      public Collection<Graph.Vertex<V,E>> neighborsIn()
      Returns the collection of vertices who can reach this vertex by a single edge.
      Returns:
      the collection of vertices who can reach this vertex by a single edge.
    • edgesOut

      public Collection<Graph.Edge<V,E>> edgesOut()
      Returns the collection of edges leaving this vertex.
      Returns:
      the collection of edges leaving this vertex.
    • edgesIn

      public Collection<Graph.Edge<V,E>> edgesIn()
      Returns the collection of edges entering this vertex.
      Returns:
      the collection of edges entering this vertex.