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.LaneDataInterface;
8   import org.opentrafficsim.kpi.interfaces.LinkDataInterface;
9   import org.opentrafficsim.road.network.lane.CrossSectionLink;
10  import org.opentrafficsim.road.network.lane.Lane;
11  
12  /**
13   * <p>
14   * Copyright (c) 2013-2016 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<LaneDataInterface> getLaneDatas()
47      {
48          List<LaneDataInterface> 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 int hashCode()
66      {
67          final int prime = 31;
68          int result = 1;
69          result = prime * result + ((this.link == null) ? 0 : this.link.hashCode());
70          return result;
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public final boolean equals(final Object obj)
76      {
77          if (this == obj)
78          {
79              return true;
80          }
81          if (obj == null)
82          {
83              return false;
84          }
85          if (getClass() != obj.getClass())
86          {
87              return false;
88          }
89          LinkData other = (LinkData) obj;
90          if (this.link == null)
91          {
92              if (other.link != null)
93              {
94                  return false;
95              }
96          }
97          else if (!this.link.equals(other.link))
98          {
99              return false;
100         }
101         return true;
102     }
103 
104     /** {@inheritDoc} */
105     @Override
106     public final String toString()
107     {
108         return "LinkData [link=" + this.link + "]";
109     }
110     
111 }