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.LinkDataInterface;
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-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 13 okt. 2016 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
21   */
22  public class LinkData implements LinkDataInterface
23  {
24  
25      /** Wrapped link. */
26      private final CrossSectionLink link;
27  
28      /**
29       * @param link wrapped link
30       */
31      public LinkData(final CrossSectionLink link)
32      {
33          this.link = link;
34      }
35  
36      /**
37       * @return link.
38       */
39      public final CrossSectionLink getLink()
40      {
41          return this.link;
42      }
43  
44      /** {@inheritDoc} */
45      @Override
46      public final List<LaneData> getLaneDatas()
47      {
48          List<LaneData> lanes = new ArrayList<>();
49          for (Lane lane : this.link.getLanes())
50          {
51              lanes.add(new LaneData(lane));
52          }
53          return lanes;
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public final Length getLength()
59      {
60          return this.link.getLength();
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public final String getId()
66      {
67          return this.link.getId();
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public final int hashCode()
73      {
74          final int prime = 31;
75          int result = 1;
76          result = prime * result + ((this.link == null) ? 0 : this.link.hashCode());
77          return result;
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public final boolean equals(final Object obj)
83      {
84          if (this == obj)
85          {
86              return true;
87          }
88          if (obj == null)
89          {
90              return false;
91          }
92          if (getClass() != obj.getClass())
93          {
94              return false;
95          }
96          LinkData other = (LinkData) obj;
97          if (this.link == null)
98          {
99              if (other.link != null)
100             {
101                 return false;
102             }
103         }
104         else if (!this.link.equals(other.link))
105         {
106             return false;
107         }
108         return true;
109     }
110 
111     /** {@inheritDoc} */
112     @Override
113     public final String toString()
114     {
115         return "LinkData [link=" + this.link + "]";
116     }
117 
118 }