package rpi.goldsd.graph;

import rpi.goldsd.container.Hashable;

/**
 * The <tt>DirectedEdge</tt> class is used to represent a directed edge.
 *
 * @see GraphBase
 * @see Edge
 * @version 2.0, 4/19/98
 * @author David Goldschmidt
 */
public class DirectedEdge extends Edge
{
  /* ******************  CONSTRUCTOR METHODS  ****************** */

  /**
   * Constructs a directed edge with the given start and end
   * vertices, the initial <tt>Hashable</tt> object to be associated
   * with this directed edge, and the initial weight.
   * @param startVertex the vertex from which this directed edge originates.
   * @param endVertex the vertex to which this directed edge leads.
   * @param data the <tt>Hashable</tt> object to be associated with this
   *             directed edge.
   * @param weight the initial weight of this directed edge.
   */
  public DirectedEdge( Vertex startVertex, Vertex endVertex, Hashable data,
                       double weight )
  {
    super( startVertex, endVertex, data, weight );
  }


  /**
   * Constructs a directed edge with the given start and end
   * vertices, and the initial weight.
   * @param startVertex the vertex from which this directed edge originates.
   * @param endVertex the vertex to which this directed edge leads.
   * @param weight the initial weight of this directed edge.
   */
  public DirectedEdge( Vertex startVertex, Vertex endVertex, double weight )
  {
    super( startVertex, endVertex, weight );
  }


  /**
   * Constructs a directed edge with the given start and end
   * vertices, and the initial <tt>Hashable</tt> object to be associated
   * with this directed edge.
   * @param startVertex the vertex from which this directed edge originates.
   * @param endVertex the vertex to which this directed edge leads.
   * @param data the <tt>Hashable</tt> object to be associated with this
   *             directed edge.
   */
  public DirectedEdge( Vertex startVertex, Vertex endVertex, Hashable data )
  {
    super( startVertex, endVertex, data );
  }


  /**
   * Constructs a directed edge with the given start and end vertices.
   * @param startVertex the vertex from which this directed edge originates.
   * @param endVertex the vertex to which this directed edge leads.
   */
  public DirectedEdge( Vertex startVertex, Vertex endVertex )
  {
    super( startVertex, endVertex );
  }


  /**
   * The default constructor is not to be used, since a directed edge
   * must have a given start and end vertex.
   */
  protected DirectedEdge()  { }



  /* ******************  ACCESSOR METHODS  ****************** */

  /**
   * Returns the vertex at the head of this directed edge (the
   * vertex to which this directed edge leads).
   * @return the vertex to which this directed edge leads.
   */
  public Vertex head()  { return endVertex(); }


  /**
   * Returns the vertex at the tail of this directed edge (the
   * vertex from which this directed edge originates).
   * @return the vertex from which this directed edge originates.
   */
  public Vertex tail()  { return startVertex(); }


  /**
   * Traverses this directed edge from a given vertex, returning the
   * destination vertex.
   * @param V the vertex from which the traversal begins.
   * @return the vertex that this directed edge leads to; or <tt>null</tt>
   *         if <tt>V</tt> is not the tail of this directed edge.
   */
  public Vertex traverseFrom( Vertex V )
  {
    return ( startVertex == V ? endVertex : null );
  }
}

