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://tudelft.nl/staff/p.knoppers-1">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 String; wrapped link name
38       * @param startNode NodeData; data of start node
39       * @param endNode NodeData; data of end node
40       * @param length 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 LaneData; the lane to add
53       */
54      public void addLaneData(final LaneDataSim0 laneData)
55      {
56          this.laneDataList.add(laneData);
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public final List<LaneDataSim0> getLaneDatas()
62      {
63          return this.laneDataList;
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public final Length getLength()
69      {
70          return this.length;
71      }
72  
73      /**
74       * @return startNode
75       */
76      public final String getStartNode()
77      {
78          return this.startNode;
79      }
80  
81      /**
82       * @return endNode
83       */
84      public final String getEndNode()
85      {
86          return this.endNode;
87      }
88  
89      /**
90       * @return linkName
91       */
92      public final String getLinkName()
93      {
94          return this.linkName;
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      public String getId()
100     {
101         return this.linkName;
102     }
103 
104     /** {@inheritDoc} */
105     @Override
106     public int hashCode()
107     {
108         final int prime = 31;
109         int result = 1;
110         result = prime * result + ((this.endNode == null) ? 0 : this.endNode.hashCode());
111         result = prime * result + ((this.length == null) ? 0 : this.length.hashCode());
112         result = prime * result + ((this.linkName == null) ? 0 : this.linkName.hashCode());
113         result = prime * result + ((this.startNode == null) ? 0 : this.startNode.hashCode());
114         return result;
115     }
116 
117     /** {@inheritDoc} */
118     @Override
119     public boolean equals(final Object obj)
120     {
121         if (this == obj)
122             return true;
123         if (obj == null)
124             return false;
125         if (getClass() != obj.getClass())
126             return false;
127         LinkDataSim0 other = (LinkDataSim0) obj;
128         if (this.linkName == null)
129         {
130             if (other.linkName != null)
131                 return false;
132         }
133         else if (!this.linkName.equals(other.linkName))
134             return false;
135         return true;
136     }
137 
138     /** {@inheritDoc} */
139     @Override
140     public String toString()
141     {
142         return "LinkData [linkName=" + this.linkName + ", startNode=" + this.startNode + ", endNode=" + this.endNode
143                 + ", length=" + this.length + ", laneDataList.size()=" + this.laneDataList.size() + "]";
144     }
145 
146 }