Package org.graph4j

Class Edge<E>

java.lang.Object
org.graph4j.Edge<E>
Type Parameters:
E - the type of edge labels in this graph.
All Implemented Interfaces:
Comparable<Edge>

public class Edge<E> extends Object implements Comparable<Edge>
An edge is a pair of vertices. It may or may not be part of the graph. Edges are not stored as objects in the graph structure, instead they are created on demand.
Author:
Cristian Frăsinaru
  • Field Details

    • directed

      protected boolean directed
    • source

      protected int source
    • target

      protected int target
    • data

      protected Double[] data
    • label

      protected E label
  • Constructor Details

    • Edge

      public Edge(int source, int target)
      Parameters:
      source - the source endpoint of the edge.
      target - the target endpoint of the edge.
    • Edge

      public Edge(int source, int target, boolean directed)
      Parameters:
      source - the source endpoint of the edge.
      target - the target endpoint of the edge.
      directed - true if the edge has a direction (in case of digraphs).
    • Edge

      public Edge(int source, int target, double weight)
      Parameters:
      source - the source endpoint of the edge.
      target - the target endpoint of the edge.
      weight - the weight of the edge.
    • Edge

      public Edge(int source, int target, E label)
      Parameters:
      source - the source endpoint of the edge.
      target - the target endpoint of the edge.
      label - the label of the edge.
    • Edge

      public Edge(int source, int target, E label, double weight)
      Parameters:
      source - the source endpoint of the edge.
      target - the target endpoint of the edge.
      label - the label of the edge.
      weight - the weight of the edge.
    • Edge

      public Edge(int source, int target, E label, Double... data)
      Parameters:
      source - the source endpoint of the edge.
      target - target the target endpoint of the edge.
      label - the label of the edge.
      data - the data associated with the edge.
  • Method Details

    • source

      public int source()
      Returns:
      the source endpoint of the edge.
    • target

      public int target()
      Returns:
      the target (sink) endpoint of the edge.
    • isDirected

      public boolean isDirected()
      Returns:
      true if the edge is directed (is case of digraphs).
    • isSelfLoop

      public boolean isSelfLoop()
      Returns:
      true if the source and the target are the same.
    • weight

      public double weight()
      Returns:
      the weight associated with the edge, or 1 in the case of unweighted graphs.
    • data

      public Double data(int dataType)
    • dataOrDefault

      public double dataOrDefault(int dataType, int defaultValue)
    • label

      public E label()
      Returns:
      the label associated with the edge, or null in the case of unlabeled graphs.
    • flip

      public Edge<E> flip()
      Flips source and target, for directed edges.
      Returns:
      a new edge with the direction reversed.
    • isAdjacentTo

      public boolean isAdjacentTo(Edge other)
      Parameters:
      other - another edge.
      Returns:
      true if this edge has a common endpoint with the other.
    • toString

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

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(Edge o)
      Specified by:
      compareTo in interface Comparable<E>