View Javadoc
1   package org.opentrafficsim.road.network.sampling;
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   import org.opentrafficsim.road.network.lane.CrossSectionLink;
9   import org.opentrafficsim.road.network.lane.Lane;
10  
11  /**
12   * Link representation in road sampler.
13   * <p>
14   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * </p>
17   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
18   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
19   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
20   */
21  public class LinkDataRoad implements LinkData<LaneDataRoad>
22  {
23  
24      /** Wrapped link. */
25      private final CrossSectionLink link;
26  
27      /**
28       * Constructor.
29       * @param link wrapped link
30       */
31      public LinkDataRoad(final CrossSectionLink link)
32      {
33          this.link = link;
34      }
35  
36      /**
37       * Return link.
38       * @return link.
39       */
40      public final CrossSectionLink getLink()
41      {
42          return this.link;
43      }
44  
45      @Override
46      public final List<LaneDataRoad> getLanes()
47      {
48          List<LaneDataRoad> lanes = new ArrayList<>();
49          for (Lane lane : this.link.getLanes())
50          {
51              lanes.add(new LaneDataRoad(lane));
52          }
53          return lanes;
54      }
55  
56      @Override
57      public final Length getLength()
58      {
59          return this.link.getLength();
60      }
61  
62      @Override
63      public final String getId()
64      {
65          return this.link.getId();
66      }
67  
68      @Override
69      public final int hashCode()
70      {
71          final int prime = 31;
72          int result = 1;
73          result = prime * result + ((this.link == null) ? 0 : this.link.hashCode());
74          return result;
75      }
76  
77      @Override
78      public final boolean equals(final Object obj)
79      {
80          if (this == obj)
81          {
82              return true;
83          }
84          if (obj == null)
85          {
86              return false;
87          }
88          if (getClass() != obj.getClass())
89          {
90              return false;
91          }
92          LinkDataRoad other = (LinkDataRoad) obj;
93          if (this.link == null)
94          {
95              if (other.link != null)
96              {
97                  return false;
98              }
99          }
100         else if (!this.link.equals(other.link))
101         {
102             return false;
103         }
104         return true;
105     }
106 
107     @Override
108     public final String toString()
109     {
110         return "LinkData [link=" + this.link + "]";
111     }
112 
113 }