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