View Javadoc
1   package org.opentrafficsim.imb.kpi;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.opentrafficsim.kpi.interfaces.LaneDataInterface;
5   import org.opentrafficsim.kpi.interfaces.LinkDataInterface;
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/node/13">OpenTrafficSim License</a>.
11   * <p>
12   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 13 okt. 2016 <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   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
16   */
17  public class LaneData implements LaneDataInterface
18  {
19      /** Corresponding Link. */
20      private LinkData linkData;
21      
22      /** Wrapped lane. */
23      private final String laneName;
24      
25      /** the link length. */
26      final Length length;
27  
28      /**
29       * @param linkData
30       * @param laneName
31       * @param length 
32       */
33      public LaneData(final LinkData linkData, final String laneName, final Length length)
34      {
35          this.linkData = linkData;
36          this.laneName = laneName;
37          this.length = length;
38          this.linkData.addLaneData(this);
39      }
40  
41      /** {@inheritDoc} */
42      @Override
43      public final Length getLength()
44      {
45          return this.length;
46      }
47  
48      /** {@inheritDoc} */
49      @Override
50      public final LinkDataInterface getLinkData()
51      {
52          return this.linkData;
53      }
54  
55      /**
56       * @return laneName
57       */
58      public final String getLaneName()
59      {
60          return this.laneName;
61      }
62  
63      /**
64       * @param linkData set linkData
65       */
66      public final void setLinkData(LinkData linkData)
67      {
68          this.linkData = linkData;
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public int hashCode()
74      {
75          final int prime = 31;
76          int result = 1;
77          result = prime * result + ((this.laneName == null) ? 0 : this.laneName.hashCode());
78          result = prime * result + ((this.length == null) ? 0 : this.length.hashCode());
79          result = prime * result + ((this.linkData == null) ? 0 : this.linkData.hashCode());
80          return result;
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      public boolean equals(Object obj)
86      {
87          if (this == obj)
88              return true;
89          if (obj == null)
90              return false;
91          if (getClass() != obj.getClass())
92              return false;
93          LaneData other = (LaneData) obj;
94          if (this.laneName == null)
95          {
96              if (other.laneName != null)
97                  return false;
98          }
99          else if (!this.laneName.equals(other.laneName))
100             return false;
101         if (this.length == null)
102         {
103             if (other.length != null)
104                 return false;
105         }
106         else if (!this.length.equals(other.length))
107             return false;
108         if (this.linkData == null)
109         {
110             if (other.linkData != null)
111                 return false;
112         }
113         else if (!this.linkData.equals(other.linkData))
114             return false;
115         return true;
116     }
117 
118     /** {@inheritDoc} */
119     @Override
120     public String toString()
121     {
122         return "LaneData [linkData=" + this.linkData + ", laneName=" + this.laneName + ", length=" + this.length + "]";
123     }
124     
125 }