View Javadoc
1   package org.opentrafficsim.sim0mq.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-2019 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 String; wrapped link name
40       * @param startNode NodeData; data of start node
41       * @param endNode NodeData; data of end node
42       * @param length 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 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 String getId()
102     {
103         return this.linkName;
104     }
105 
106     /** {@inheritDoc} */
107     @Override
108     public int hashCode()
109     {
110         final int prime = 31;
111         int result = 1;
112         result = prime * result + ((this.endNode == null) ? 0 : this.endNode.hashCode());
113         result = prime * result + ((this.length == null) ? 0 : this.length.hashCode());
114         result = prime * result + ((this.linkName == null) ? 0 : this.linkName.hashCode());
115         result = prime * result + ((this.startNode == null) ? 0 : this.startNode.hashCode());
116         return result;
117     }
118 
119     /** {@inheritDoc} */
120     @Override
121     public boolean equals(Object obj)
122     {
123         if (this == obj)
124             return true;
125         if (obj == null)
126             return false;
127         if (getClass() != obj.getClass())
128             return false;
129         LinkData other = (LinkData) obj;
130         if (this.linkName == null)
131         {
132             if (other.linkName != null)
133                 return false;
134         }
135         else if (!this.linkName.equals(other.linkName))
136             return false;
137         return true;
138     }
139 
140     /** {@inheritDoc} */
141     @Override
142     public String toString()
143     {
144         return "LinkData [linkName=" + this.linkName + ", startNode=" + this.startNode + ", endNode=" + this.endNode
145                 + ", length=" + this.length + ", laneDataList.size()=" + this.laneDataList.size() + "]";
146     }
147 
148 }