LinkEdge.java

  1. package org.opentrafficsim.core.network;

  2. import org.jgrapht.graph.DefaultWeightedEdge;

  3. /**
  4.  * The LinkEdge is a class that embeds a Link (extension of AbstractLink) to be put in a graph. Typical code to add a link
  5.  * called <code>link</code> with nodes <code>nodeA</code> and <code>nodeB</code> to a graph is:
  6.  *
  7.  * <pre>
  8.  * SimpleWeightedGraph&lt;Node, LinkEdge&gt; linkGraph = new SimpleWeightedGraph&lt;&gt;(LinkEdge.class);
  9.  * ...
  10.  * Link link = new Link(nodeA, nodeB, name);
  11.  * LinkEdge linkEdge = new LinkEdge(link);
  12.  * linkGraph.addEdge(nodeA, nodeB, linkEdge);
  13.  * linkGraph.setEdgeWeight(linkEdge, link.getLength().doubleValue());
  14.  * </pre>
  15.  * <p>
  16.  * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  17.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  18.  * <p>
  19.  * $LastChangedDate: 2016-05-28 11:33:31 +0200 (Sat, 28 May 2016) $, @version $Revision: 2051 $, by $Author: averbraeck $,
  20.  * initial version Sep 12, 2014 <br>
  21.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  22.  * @param <LINK> the link type.
  23.  */
  24. public class LinkEdge<LINK extends Link> extends DefaultWeightedEdge
  25. {
  26.     /** */
  27.     private static final long serialVersionUID = 1L;

  28.     /** Edge object. */
  29.     private LINK link;

  30.     /**
  31.      * @param link the edge to take into the graph.
  32.      */
  33.     public LinkEdge(final LINK link)
  34.     {
  35.         super();
  36.         this.link = link;
  37.     }

  38.     /**
  39.      * @return the link that is taken as an edge in the graph.
  40.      */
  41.     public final LINK getLink()
  42.     {
  43.         return this.link;
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     public final String toString()
  48.     {
  49.         return "LinkEdge [link=" + this.link + "]";
  50.     }

  51. }