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.LinkData;
8   
9   /**
10   * <p>
11   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13   * </p>
14   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
16   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
17   */
18  public class LinkDataSim0 implements LinkData<LaneDataSim0>
19  {
20  
21      /** Wrapped link. */
22      private final String linkName;
23  
24      /** start node. */
25      final String startNode;
26  
27      /** end node. */
28      final String endNode;
29  
30      /** Lanes on this link. */
31      private final List<LaneDataSim0> laneDataList = new ArrayList<>();
32  
33      /** the link length. */
34      private final Length length;
35  
36      /**
37       * @param linkName wrapped link name
38       * @param startNode data of start node
39       * @param endNode data of end node
40       * @param length the length
41       */
42      public LinkDataSim0(final String linkName, final String startNode, final String endNode, final Length length)
43      {
44          this.linkName = linkName;
45          this.length = length;
46          this.startNode = startNode;
47          this.endNode = endNode;
48      }
49  
50      /**
51       * Add the lane to the list of lanes for this link.
52       * @param laneData the lane to add
53       */
54      public void addLaneData(final LaneDataSim0 laneData)
55      {
56          this.laneDataList.add(laneData);
57      }
58  
59      @Override
60      public final List<LaneDataSim0> getLanes()
61      {
62          return this.laneDataList;
63      }
64  
65      @Override
66      public final Length getLength()
67      {
68          return this.length;
69      }
70  
71      /**
72       * @return startNode
73       */
74      public final String getStartNode()
75      {
76          return this.startNode;
77      }
78  
79      /**
80       * @return endNode
81       */
82      public final String getEndNode()
83      {
84          return this.endNode;
85      }
86  
87      /**
88       * @return linkName
89       */
90      public final String getLinkName()
91      {
92          return this.linkName;
93      }
94  
95      @Override
96      public String getId()
97      {
98          return this.linkName;
99      }
100 
101     @Override
102     public int hashCode()
103     {
104         final int prime = 31;
105         int result = 1;
106         result = prime * result + ((this.endNode == null) ? 0 : this.endNode.hashCode());
107         result = prime * result + ((this.length == null) ? 0 : this.length.hashCode());
108         result = prime * result + ((this.linkName == null) ? 0 : this.linkName.hashCode());
109         result = prime * result + ((this.startNode == null) ? 0 : this.startNode.hashCode());
110         return result;
111     }
112 
113     @Override
114     public boolean equals(final 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         LinkDataSim0 other = (LinkDataSim0) obj;
123         if (this.linkName == null)
124         {
125             if (other.linkName != null)
126                 return false;
127         }
128         else if (!this.linkName.equals(other.linkName))
129             return false;
130         return true;
131     }
132 
133     @Override
134     public String toString()
135     {
136         return "LinkData [linkName=" + this.linkName + ", startNode=" + this.startNode + ", endNode=" + this.endNode
137                 + ", length=" + this.length + ", laneDataList.size()=" + this.laneDataList.size() + "]";
138     }
139 
140 }