View Javadoc
1   package org.opentrafficsim.kpi.sampling;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.djutils.exceptions.Throw;
7   import org.opentrafficsim.kpi.interfaces.LaneData;
8   
9   /**
10   * Store one position and lane of a GTU.
11   * <p>
12   * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14   * </p>
15   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
17   */
18  public class LanePosition implements Serializable
19  {
20      /** */
21      private static final long serialVersionUID = 20151111L;
22  
23      /** The lane for the position. */
24      private final LaneData lane;
25  
26      /** The position on the lane, relative to the cross section link (design line). */
27      private final Length position;
28  
29      /**
30       * Construct a new LanePosition.
31       * @param lane LaneData; the lane for the position
32       * @param position Length; the position on the lane, relative to the cross section link (design line)
33       */
34      public LanePosition(final LaneData lane, final Length position)
35      {
36          Throw.whenNull(lane, "lane is null");
37          Throw.whenNull(position, "position is null");
38          this.lane = lane;
39          this.position = position;
40      }
41  
42      /**
43       * Retrieve the lane.
44       * @return LaneData; the lane for the position
45       */
46      public final LaneData getLaneData()
47      {
48          return this.lane;
49      }
50  
51      /**
52       * Retrieve the position on the lane.
53       * @return Length; the position on the lane, relative to the cross section link (design line)
54       */
55      public final Length getPosition()
56      {
57          return this.position;
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public int hashCode()
63      {
64          final int prime = 31;
65          int result = 1;
66          result = prime * result + ((this.lane == null) ? 0 : this.lane.hashCode());
67          result = prime * result + ((this.position == null) ? 0 : this.position.hashCode());
68          return result;
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      @SuppressWarnings("checkstyle:needbraces")
74      public boolean equals(final Object obj)
75      {
76          if (this == obj)
77              return true;
78          if (obj == null)
79              return false;
80          if (getClass() != obj.getClass())
81              return false;
82          LanePosition other = (LanePosition) obj;
83          if (this.lane == null)
84          {
85              if (other.lane != null)
86                  return false;
87          }
88          else if (!this.lane.equals(other.lane))
89              return false;
90          if (this.position == null)
91          {
92              if (other.position != null)
93                  return false;
94          }
95          else if (!this.position.equals(other.position))
96              return false;
97          return true;
98      }
99  
100     /** {@inheritDoc} */
101     @Override
102     public String toString()
103     {
104         return "LanePosition [lane=" + this.lane + ", position=" + this.position + "]";
105     }
106 
107 }