Class Edge<V>

java.lang.Object
com.phasmidsoftware.gryphon.java.Edge<V>
Type Parameters:
V - the vertex type.
Direct Known Subclasses:
WeightedEdge

public class Edge<V> extends Object
Represents an unweighted directed or undirected edge between two vertices.

An Edge<V> carries only structural information — the two endpoint vertices. For edges that carry a weight or attribute, use WeightedEdge<V, E> instead.

Edges are immutable. Equality is based on both endpoints.

Usage example:


 Edge<String> e = new Edge<>("A", "B");
 String from = e.from();   // "A"
 String to   = e.to();     // "B"
 Edge<String> rev = e.reverse();  // Edge("B", "A")
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    Edge(V from, V to)
    Constructs an edge from from to to.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    Returns the source vertex of this edge.
    int
     
    static <V> Edge<V>
    of(V from, V to)
    Creates a new Edge from from to to.
    Returns an edge with the endpoints swapped.
    to()
    Returns the target vertex of this edge.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Edge

      public Edge(V from, V to)
      Constructs an edge from from to to.
      Parameters:
      from - the source vertex.
      to - the target vertex.
  • Method Details

    • of

      public static <V> Edge<V> of(V from, V to)
      Creates a new Edge from from to to.
      Type Parameters:
      V - the vertex type.
      Parameters:
      from - the source vertex.
      to - the target vertex.
      Returns:
      a new Edge.
    • from

      public V from()
      Returns the source vertex of this edge.
      Returns:
      the source vertex.
    • to

      public V to()
      Returns the target vertex of this edge.
      Returns:
      the target vertex.
    • reverse

      public Edge<V> reverse()
      Returns an edge with the endpoints swapped.

      For an undirected graph this is equivalent to the original edge; for a directed graph it represents the reverse arc.

      Returns:
      the reversed edge.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object