LinkDirection.java

  1. package org.opentrafficsim.core.network;

  2. import java.io.Serializable;

  3. import org.opentrafficsim.core.gtu.GTUDirectionality;

  4. /**
  5.  * Storage for a Link and a GTUDirectionality.
  6.  * <p>
  7.  * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  8.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  9.  * </p>
  10.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  11.  * initial version Dec 2, 2015 <br>
  12.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  13.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  14.  */
  15. public class LinkDirection implements Serializable
  16. {
  17.     /** */
  18.     private static final long serialVersionUID = 20150000L;

  19.     /** The link. */
  20.     private final Link link;

  21.     /** The direction on the link, with or against the design line. */
  22.     private final GTUDirectionality direction;

  23.     /**
  24.      * @param link the link
  25.      * @param direction the direction on the link, with or against the design line
  26.      */
  27.     public LinkDirection(final Link link, final GTUDirectionality direction)
  28.     {
  29.         super();
  30.         this.link = link;
  31.         this.direction = direction;
  32.     }

  33.     /**
  34.      * @return link
  35.      */
  36.     public final Link getLink()
  37.     {
  38.         return this.link;
  39.     }

  40.     /**
  41.      * @return direction
  42.      */
  43.     public final GTUDirectionality getDirection()
  44.     {
  45.         return this.direction;
  46.     }

  47.     /**
  48.      * @return the destination node of the linkdirection
  49.      */
  50.     public final Node getNodeTo()
  51.     {
  52.         return this.direction.equals(GTUDirectionality.DIR_PLUS) ? this.link.getEndNode() : this.link.getStartNode();
  53.     }

  54.     /**
  55.      * @return the origin node of the linkdirection
  56.      */
  57.     public final Node getNodeFrom()
  58.     {
  59.         return this.direction.equals(GTUDirectionality.DIR_PLUS) ? this.link.getStartNode() : this.link.getEndNode();
  60.     }

  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public final String toString()
  64.     {
  65.         return "LinkDirection [link=" + this.link + ", direction=" + this.direction + "]";
  66.     }
  67. }