Class Graph.Edge<V,E>

java.lang.Object
Graph.Edge<V,E>
Direct Known Subclasses:
Graph.WeightedEdge
Enclosing class:
Graph<V,E>

public static class Graph.Edge<V,E> extends Object
A holder class for Edges that allows each Edge to track the Vertex endpoints as well as the associated data of the edge.
  • Field Details

    • data

      public E data
      The data associated with this Edge.
  • Constructor Details

    • Edge

      public Edge(Graph.Vertex<V,E> u, Graph.Vertex<V,E> v)
      Constructs an edge with the specified endpoints.
      Parameters:
      u - an endpoint of this edge
      v - an endpoint of this edge
    • Edge

      public Edge(Graph.Vertex<V,E> u, Graph.Vertex<V,E> v, E data)
      Constructs an edge with the specified endpoints holding the specified data.
      Parameters:
      u - an endpoint of this edge
      v - an endpoint of this edge
      data - the associated data of this edge
    • Edge

      public Edge(Graph.Vertex<V,E> u, Graph.Vertex<V,E> v, boolean directed)
      Constructs an edge with the specified endpoints.

      If directed is true, the constructed edge becomes a directed edge, where u is the source of the edge and v is the target of the edge.

      Parameters:
      u - an endpoint of this edge
      v - an endpoint of this edge
      directed - specified whether this edge is to be directed or undirected
    • Edge

      public Edge(Graph.Vertex<V,E> u, Graph.Vertex<V,E> v, boolean directed, E data)
      Constructs an edge with the specified endpoints holding the specified data.

      If directed is true, the constructed edge becomes a directed edge, where u is the source of the edge and v is the target of the edge.

      Parameters:
      u - an endpoint of this edge
      v - an endpoint of this edge
      directed - specified whether this edge is to be directed or undirected
      data - the associated data of this edge
  • Method Details

    • vertices

      public List<Graph.Vertex<V,E>> vertices()
      Returns a list containing the vertices in this edge.

      For undirected edges the order is meaningless, but for directed edges the source will be before the target.

      Returns:
      a list containing the vertices in this edge.
    • isDirected

      public boolean isDirected()
      Returns whether this edge is directed.
      Returns:
      whether this edge is directed.
    • source

      public Graph.Vertex<V,E> source()
      Returns the source of this directed edge.
      Returns:
      the source of this directed edge.
      Throws:
      UnsupportedOperationException - if this edge is not directed.
    • target

      public Graph.Vertex<V,E> target()
      Returns the target of this directed edge.
      Returns:
      the target of this directed edge.
      Throws:
      UnsupportedOperationException - if this edge is not directed.
    • reverse

      public Graph.Edge<V,E> reverse()
      Returns an edge that is the reverse of this edge.

      If this edge is directed, the edge returned by this method will be directed in the opposite direction.

      Returns:
      an edge that is the reverse of this edge.
    • equals

      public boolean equals(Object o)
      Returns true if the specified object is an edge with the same endpoints and in the same direction (if applicable) as this edge.

      Notably, the data of the edges are not considered.

      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • other

      public Graph.Vertex<V,E> other(Graph.Vertex<V,E> vertex)
      Returns the other endpoint of this edge contrasting the specified vertex, or null if the specified vertex is not an endpoint of this edge.
      Parameters:
      vertex - an endpoint of this edge
      Returns:
      the other endpoint of this edge contrasting the specified vertex, or null if the specified vertex is not an endpoint of this edge.
    • toString

      public String toString()
      Overrides:
      toString in class Object