LinkDirection.java

  1. package org.opentrafficsim.core.network;

  2. import java.io.Serializable;

  3. import org.djunits.value.vdouble.scalar.Length;
  4. import org.opentrafficsim.core.gtu.GTUDirectionality;

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

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

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

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

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

  41.     /**
  42.      * @return String; link id
  43.      * @see org.opentrafficsim.core.network.Link#getId()
  44.      */
  45.     public String getId()
  46.     {
  47.         return this.link.getId();
  48.     }

  49.     /**
  50.      * @return LinkType; link type
  51.      * @see org.opentrafficsim.core.network.Link#getLinkType()
  52.      */
  53.     public LinkType getLinkType()
  54.     {
  55.         return this.link.getLinkType();
  56.     }

  57.     /**
  58.      * @return Length; length
  59.      * @see org.opentrafficsim.core.network.Link#getLength()
  60.      */
  61.     public Length getLength()
  62.     {
  63.         return this.link.getLength();
  64.     }

  65.     /**
  66.      * @return direction
  67.      */
  68.     public final GTUDirectionality getDirection()
  69.     {
  70.         return this.direction;
  71.     }

  72.     /**
  73.      * @return the destination node of the linkdirection
  74.      */
  75.     public final Node getNodeTo()
  76.     {
  77.         return this.direction.equals(GTUDirectionality.DIR_PLUS) ? this.link.getEndNode() : this.link.getStartNode();
  78.     }

  79.     /**
  80.      * @return the origin node of the linkdirection
  81.      */
  82.     public final Node getNodeFrom()
  83.     {
  84.         return this.direction.equals(GTUDirectionality.DIR_PLUS) ? this.link.getStartNode() : this.link.getEndNode();
  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     public int hashCode()
  89.     {
  90.         final int prime = 31;
  91.         int result = 1;
  92.         result = prime * result + ((this.direction == null) ? 0 : this.direction.hashCode());
  93.         result = prime * result + ((this.link == null) ? 0 : this.link.hashCode());
  94.         return result;
  95.     }

  96.     /** {@inheritDoc} */
  97.     @Override
  98.     public boolean equals(final Object obj)
  99.     {
  100.         if (this == obj)
  101.         {
  102.             return true;
  103.         }
  104.         if (obj == null)
  105.         {
  106.             return false;
  107.         }
  108.         if (getClass() != obj.getClass())
  109.         {
  110.             return false;
  111.         }
  112.         LinkDirection other = (LinkDirection) obj;
  113.         if (this.direction != other.direction)
  114.         {
  115.             return false;
  116.         }
  117.         if (this.link == null)
  118.         {
  119.             if (other.link != null)
  120.             {
  121.                 return false;
  122.             }
  123.         }
  124.         else if (!this.link.equals(other.link))
  125.         {
  126.             return false;
  127.         }
  128.         return true;
  129.     }

  130.     /** {@inheritDoc} */
  131.     @Override
  132.     public String toString()
  133.     {
  134.         return "LinkDirection [link=" + this.link + ", direction=" + this.direction + "]";
  135.     }
  136. }