View Javadoc
1   package org.opentrafficsim.core.network;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.opentrafficsim.core.gtu.GTUDirectionality;
7   
8   /**
9    * Storage for a Link and a GTUDirectionality.
10   * <p>
11   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13   * </p>
14   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
15   * initial version Dec 2, 2015 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
18   */
19  public class LinkDirection implements Serializable
20  {
21      /** */
22      private static final long serialVersionUID = 20150000L;
23  
24      /** The link. */
25      private final Link link;
26  
27      /** The direction on the link, with or against the design line. */
28      private final GTUDirectionality direction;
29  
30      /**
31       * @param link Link; the link
32       * @param direction GTUDirectionality; the direction on the link, with or against the design line
33       */
34      public LinkDirection(final Link link, final GTUDirectionality direction)
35      {
36          super();
37          this.link = link;
38          this.direction = direction;
39      }
40  
41      /**
42       * @return link
43       */
44      public final Link getLink()
45      {
46          return this.link;
47      }
48  
49      /**
50       * @return String; link id
51       * @see org.opentrafficsim.core.network.Link#getId()
52       */
53      public String getId()
54      {
55          return this.link.getId();
56      }
57  
58      /**
59       * @return LinkType; link type
60       * @see org.opentrafficsim.core.network.Link#getLinkType()
61       */
62      public LinkType getLinkType()
63      {
64          return this.link.getLinkType();
65      }
66  
67      /**
68       * @return Length; length
69       * @see org.opentrafficsim.core.network.Link#getLength()
70       */
71      public Length getLength()
72      {
73          return this.link.getLength();
74      }
75  
76      /**
77       * @return direction
78       */
79      public final GTUDirectionality getDirection()
80      {
81          return this.direction;
82      }
83  
84      /**
85       * @return the destination node of the linkdirection
86       */
87      public final Node getNodeTo()
88      {
89          return this.direction.equals(GTUDirectionality.DIR_PLUS) ? this.link.getEndNode() : this.link.getStartNode();
90      }
91  
92      /**
93       * @return the origin node of the linkdirection
94       */
95      public final Node getNodeFrom()
96      {
97          return this.direction.equals(GTUDirectionality.DIR_PLUS) ? this.link.getStartNode() : this.link.getEndNode();
98      }
99  
100     /** {@inheritDoc} */
101     @Override
102     public int hashCode()
103     {
104         final int prime = 31;
105         int result = 1;
106         result = prime * result + ((this.direction == null) ? 0 : this.direction.hashCode());
107         result = prime * result + ((this.link == null) ? 0 : this.link.hashCode());
108         return result;
109     }
110 
111     /** {@inheritDoc} */
112     @Override
113     public boolean equals(final Object obj)
114     {
115         if (this == obj)
116         {
117             return true;
118         }
119         if (obj == null)
120         {
121             return false;
122         }
123         if (getClass() != obj.getClass())
124         {
125             return false;
126         }
127         LinkDirection other = (LinkDirection) obj;
128         if (this.direction != other.direction)
129         {
130             return false;
131         }
132         if (this.link == null)
133         {
134             if (other.link != null)
135             {
136                 return false;
137             }
138         }
139         else if (!this.link.equals(other.link))
140         {
141             return false;
142         }
143         return true;
144     }
145 
146     /** {@inheritDoc} */
147     @Override
148     public String toString()
149     {
150         return "LinkDirection [link=" + this.link + ", direction=" + this.direction + "]";
151     }
152 }