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       * @param link wrapped link
29       */
30      public LinkDataRoad(final CrossSectionLink link)
31      {
32          this.link = link;
33      }
34  
35      /**
36       * @return link.
37       */
38      public final CrossSectionLink getLink()
39      {
40          return this.link;
41      }
42  
43      @Override
44      public final List<LaneDataRoad> getLanes()
45      {
46          List<LaneDataRoad> lanes = new ArrayList<>();
47          for (Lane lane : this.link.getLanes())
48          {
49              lanes.add(new LaneDataRoad(lane));
50          }
51          return lanes;
52      }
53  
54      @Override
55      public final Length getLength()
56      {
57          return this.link.getLength();
58      }
59  
60      @Override
61      public final String getId()
62      {
63          return this.link.getId();
64      }
65  
66      @Override
67      public final int hashCode()
68      {
69          final int prime = 31;
70          int result = 1;
71          result = prime * result + ((this.link == null) ? 0 : this.link.hashCode());
72          return result;
73      }
74  
75      @Override
76      public final boolean equals(final Object obj)
77      {
78          if (this == obj)
79          {
80              return true;
81          }
82          if (obj == null)
83          {
84              return false;
85          }
86          if (getClass() != obj.getClass())
87          {
88              return false;
89          }
90          LinkDataRoad other = (LinkDataRoad) obj;
91          if (this.link == null)
92          {
93              if (other.link != null)
94              {
95                  return false;
96              }
97          }
98          else if (!this.link.equals(other.link))
99          {
100             return false;
101         }
102         return true;
103     }
104 
105     @Override
106     public final String toString()
107     {
108         return "LinkData [link=" + this.link + "]";
109     }
110 
111 }