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-2024 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   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18   */
19  public class LanePosition implements Serializable
20  {
21      /** */
22      private static final long serialVersionUID = 20151111L;
23  
24      /** The lane for the position. */
25      private final LaneData<?> lane;
26  
27      /** The position on the lane, relative to the cross section link (design line). */
28      private final Length position;
29  
30      /**
31       * Construct a new LanePosition.
32       * @param lane LaneData&lt;?&gt;; the lane for the position
33       * @param position Length; the position on the lane, relative to the cross section link (design line)
34       */
35      public LanePosition(final LaneData<?> lane, final Length position)
36      {
37          Throw.whenNull(lane, "lane is null");
38          Throw.whenNull(position, "position is null");
39          this.lane = lane;
40          this.position = position;
41      }
42  
43      /**
44       * Retrieve the lane.
45       * @return LaneData&lt;?&gt;; the lane for the position
46       */
47      public final LaneData<?> getLaneData()
48      {
49          return this.lane;
50      }
51  
52      /**
53       * Retrieve the position on the lane.
54       * @return Length; the position on the lane, relative to the cross section link (design line)
55       */
56      public final Length getPosition()
57      {
58          return this.position;
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public int hashCode()
64      {
65          final int prime = 31;
66          int result = 1;
67          result = prime * result + ((this.lane == null) ? 0 : this.lane.hashCode());
68          result = prime * result + ((this.position == null) ? 0 : this.position.hashCode());
69          return result;
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      @SuppressWarnings("checkstyle:needbraces")
75      public boolean equals(final Object obj)
76      {
77          if (this == obj)
78              return true;
79          if (obj == null)
80              return false;
81          if (getClass() != obj.getClass())
82              return false;
83          LanePosition other = (LanePosition) obj;
84          if (this.lane == null)
85          {
86              if (other.lane != null)
87                  return false;
88          }
89          else if (!this.lane.equals(other.lane))
90              return false;
91          if (this.position == null)
92          {
93              if (other.position != null)
94                  return false;
95          }
96          else if (!this.position.equals(other.position))
97              return false;
98          return true;
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     public String toString()
104     {
105         return "LanePosition [lane=" + this.lane + ", position=" + this.position + "]";
106     }
107 
108 }