View Javadoc
1   package org.opentrafficsim.imb.kpi;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.opentrafficsim.kpi.interfaces.LaneDataInterface;
8   import org.opentrafficsim.kpi.interfaces.LinkDataInterface;
9   
10  /**
11   * <p>
12   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
14   * <p>
15   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 13 okt. 2016 <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   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
19   */
20  public class LinkData implements LinkDataInterface
21  {
22  
23      /** Wrapped link. */
24      private final String linkName;
25  
26      /** start node. */
27      final NodeData startNode;
28  
29      /** end node. */
30      final NodeData endNode;
31  
32      /** Lanes on this link. */
33      private final List<LaneDataInterface> laneDataList = new ArrayList<>();
34  
35      /** the link length. */
36      private final Length length;
37  
38      /**
39       * @param linkName wrapped link name
40       * @param startNode
41       * @param endNode
42       * @param length the length
43       */
44      public LinkData(final String linkName, final NodeData startNode, final NodeData endNode, final Length length)
45      {
46          this.linkName = linkName;
47          this.length = length;
48          this.startNode = startNode;
49          this.endNode = endNode;
50      }
51  
52      /**
53       * Add the lane to the list of lanes for this link.
54       * @param laneData the lane to add
55       */
56      public void addLaneData(final LaneData laneData)
57      {
58          this.laneDataList.add(laneData);
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public final List<LaneDataInterface> getLaneDatas()
64      {
65          return this.laneDataList;
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public final Length getLength()
71      {
72          return this.length;
73      }
74  
75      /**
76       * @return startNode
77       */
78      public final NodeData getStartNode()
79      {
80          return this.startNode;
81      }
82  
83      /**
84       * @return endNode
85       */
86      public final NodeData getEndNode()
87      {
88          return this.endNode;
89      }
90  
91      /**
92       * @return linkName
93       */
94      public final String getLinkName()
95      {
96          return this.linkName;
97      }
98  
99      /** {@inheritDoc} */
100     @Override
101     public int hashCode()
102     {
103         final int prime = 31;
104         int result = 1;
105         result = prime * result + ((this.endNode == null) ? 0 : this.endNode.hashCode());
106         result = prime * result + ((this.length == null) ? 0 : this.length.hashCode());
107         result = prime * result + ((this.linkName == null) ? 0 : this.linkName.hashCode());
108         result = prime * result + ((this.startNode == null) ? 0 : this.startNode.hashCode());
109         return result;
110     }
111 
112     /** {@inheritDoc} */
113     @Override
114     public boolean equals(Object obj)
115     {
116         if (this == obj)
117             return true;
118         if (obj == null)
119             return false;
120         if (getClass() != obj.getClass())
121             return false;
122         LinkData other = (LinkData) obj;
123         if (this.endNode == null)
124         {
125             if (other.endNode != null)
126                 return false;
127         }
128         else if (!this.endNode.equals(other.endNode))
129             return false;
130         if (this.length == null)
131         {
132             if (other.length != null)
133                 return false;
134         }
135         else if (!this.length.equals(other.length))
136             return false;
137         if (this.linkName == null)
138         {
139             if (other.linkName != null)
140                 return false;
141         }
142         else if (!this.linkName.equals(other.linkName))
143             return false;
144         if (this.startNode == null)
145         {
146             if (other.startNode != null)
147                 return false;
148         }
149         else if (!this.startNode.equals(other.startNode))
150             return false;
151         return true;
152     }
153 
154     /** {@inheritDoc} */
155     @Override
156     public String toString()
157     {
158         return "LinkData [linkName=" + this.linkName + ", startNode=" + this.startNode + ", endNode=" + this.endNode
159                 + ", length=" + this.length + ", laneDataList.size()=" + this.laneDataList.size() + "]";
160     }
161 
162 }