Class UndirectedEdge<T>

java.lang.Object
graphlib.edges.Edge<T>
graphlib.edges.UndirectedEdge<T>

public class UndirectedEdge<T> extends Edge<T>
Represents an undirected edge. This type of edges can be added to a undirected graph. Edges {a,b} and {b,a} are equal.
  • Constructor Details

    • UndirectedEdge

      public UndirectedEdge(Node<T> node1, Node<T> node2, double weight)
      Create an undirected edge between two nodes with given weight. The order in which the nodes are specified is arbitrary.
      Parameters:
      node1 - first node
      node2 - second node
      weight - associated weight
    • UndirectedEdge

      public UndirectedEdge(Node<T> node1, Node<T> node2)
      Create an unweighted undirected edge between two nodes. The order in which the nodes are specified is arbitrary. Calling Edge.getWeight() on this edge will return null. A weight may be assigned later using Edge.setWeight(double).
      Parameters:
      node1 - first node
      node2 - second node
  • Method Details

    • isDirected

      public boolean isDirected()
      Always returns false as this is an undirected edge.
      Specified by:
      isDirected in class Edge<T>
      Returns:
      false
    • getNode1

      public Node<T> getNode1()
      Get the first node of this edge. Whether a node is the first of second node does not mean anything, i.e. order of nodes is arbitrary in an undirected edge.
      Overrides:
      getNode1 in class Edge<T>
      Returns:
      first node
    • getNode2

      public Node<T> getNode2()
      Get the second node of this edge. Whether a node is the first of second node does not mean anything, i.e. order of nodes is arbitrary in an undirected edge.
      Overrides:
      getNode2 in class Edge<T>
      Returns:
      second node
    • toString

      public String toString()
      Create a string representation of the undirected edge, formatted as {a,b}.
      Overrides:
      toString in class Object
      Returns:
      string representation