View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import java.io.Serializable;
4   
5   import org.opentrafficsim.core.gtu.GTUDirectionality;
6   
7   /**
8    * <p>
9    * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
11   * </p>
12   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
13   * initial version Mar 30, 2016 <br>
14   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   */
17  public class LaneDirection implements Serializable
18  {
19      /** */
20      private static final long serialVersionUID = 20160330L;
21  
22      /** The lane. */
23      private final Lane lane;
24  
25      /** The GTU direction to drive on this lane. */
26      private final GTUDirectionality direction;
27  
28      /**
29       * @param lane the lane
30       * @param direction the direction to drive on this lane
31       */
32      public LaneDirection(final Lane lane, final GTUDirectionality direction)
33      {
34          super();
35          this.lane = lane;
36          this.direction = direction;
37      }
38  
39      /**
40       * @return the lane
41       */
42      public final Lane getLane()
43      {
44          return this.lane;
45      }
46  
47      /**
48       * @return the direction to drive on this lane
49       */
50      public final GTUDirectionality getDirection()
51      {
52          return this.direction;
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public String toString()
58      {
59          return "[" + this.lane + (this.direction.isPlus() ? " +]" : " -]");
60      }
61  
62      /** {@inheritDoc} */
63      @Override
64      public final int hashCode()
65      {
66          final int prime = 31;
67          int result = 1;
68          result = prime * result + ((this.direction == null) ? 0 : this.direction.hashCode());
69          result = prime * result + ((this.lane == null) ? 0 : this.lane.hashCode());
70          return result;
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public final boolean equals(final Object obj)
76      {
77          if (this == obj)
78          {
79              return true;
80          }
81          if (obj == null)
82          {
83              return false;
84          }
85          if (getClass() != obj.getClass())
86          {
87              return false;
88          }
89          LaneDirection other = (LaneDirection) obj;
90          if (this.direction != other.direction)
91          {
92              return false;
93          }
94          if (this.lane == null)
95          {
96              if (other.lane != null)
97              {
98                  return false;
99              }
100         }
101         else if (!this.lane.equals(other.lane))
102         {
103             return false;
104         }
105         return true;
106     }
107     
108 }