Class WeightedEdge<V,E>

java.lang.Object
com.phasmidsoftware.gryphon.java.Edge<V>
com.phasmidsoftware.gryphon.java.WeightedEdge<V,E>
Type Parameters:
V - the vertex type.
E - the attribute (weight) type.

public class WeightedEdge<V,E> extends Edge<V>
Represents a weighted edge between two vertices, carrying an attribute of type E.

Extends Edge<V> with an additional weight (or attribute). Used wherever edge attributes matter — shortest paths (Dijkstra), minimum spanning trees (Prim, Kruskal), and any other algorithm that discriminates between edges by weight.

The attribute type E is intentionally general: it may be Double for a numeric weight, String for a label, or any other domain-specific type. Use Void (with null attribute) to represent an explicitly unweighted edge in a context that requires the WeightedEdge type.

Edges are immutable. Equality is based on both endpoints and the attribute.

Usage example:


 WeightedEdge<String, Double> e = new WeightedEdge<>("A", "B", 3.7);
 String from   = e.from();      // "A"
 String to     = e.to();        // "B"
 double weight = e.attribute(); // 3.7
 WeightedEdge<String, Double> rev = e.reverse(); // WeightedEdge("B", "A", 3.7)
 
  • Constructor Details

    • WeightedEdge

      public WeightedEdge(V from, V to, E attribute)
      Constructs a weighted edge from from to to with the given attribute.
      Parameters:
      from - the source vertex.
      to - the target vertex.
      attribute - the edge attribute (weight).
  • Method Details

    • of

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

      public E attribute()
      Returns the attribute (weight) of this edge.
      Returns:
      the edge attribute.
    • reverse

      public WeightedEdge<V,E> reverse()
      Returns a WeightedEdge with the endpoints swapped, preserving the attribute.
      Overrides:
      reverse in class Edge<V>
      Returns:
      the reversed weighted edge.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Edge<V>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Edge<V>
    • toString

      public String toString()
      Overrides:
      toString in class Edge<V>