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.LaneDataInterface;
8   
9   /**
10   * Store one position, direction and lane of a GTU.
11   * <p>
12   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14   * </p>
15   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
16   * initial version Nov 11, 2015 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
19   */
20  public class KpiDirectedLanePosition implements Serializable
21  {
22      /** */
23      private static final long serialVersionUID = 20151111L;
24  
25      /** The lane for the position. */
26      private final LaneDataInterface lane;
27  
28      /** The position on the lane, relative to the cross section link (design line). */
29      private final Length position;
30  
31      /** The direction the vehicle is driving to -- either in the direction of the design line, or against it. */
32      private final KpiGtuDirectionality gtuDirection;
33  
34      /**
35       * Construct a new DirectedLanePosition.
36       * @param lane LaneDataInterface; the lane for the position
37       * @param position Length; the position on the lane, relative to the cross section link (design line)
38       * @param gtuDirection KpiGtuDirectionality; the direction the vehicle is driving to -- either in the direction of the
39       *            design line, or against it
40       */
41      public KpiDirectedLanePosition(final LaneDataInterface lane, final Length position, final KpiGtuDirectionality gtuDirection)
42      {
43          Throw.whenNull(lane, "lane is null");
44          Throw.whenNull(position, "position is null");
45          Throw.whenNull(gtuDirection, "gtuDirection is null");
46          this.lane = lane;
47          this.position = position;
48          this.gtuDirection = gtuDirection;
49      }
50  
51      /**
52       * Retrieve the lane.
53       * @return LaneDataInterface; the lane for the position
54       */
55      public final LaneDataInterface getLaneData()
56      {
57          return this.lane;
58      }
59  
60      /**
61       * Retrieve the position on the lane.
62       * @return Length; the position on the lane, relative to the cross section link (design line)
63       */
64      public final Length getPosition()
65      {
66          return this.position;
67      }
68  
69      /**
70       * Retrieve the gtuDirection.
71       * @return KpiGtuDirectionality; gtuDirection the direction the vehicle is driving to -- either in the direction of the
72       *         design line, or against it
73       */
74      public final KpiGtuDirectionality getKpiGtuDirection()
75      {
76          return this.gtuDirection;
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public int hashCode()
82      {
83          final int prime = 31;
84          int result = 1;
85          result = prime * result + ((this.gtuDirection == null) ? 0 : this.gtuDirection.hashCode());
86          result = prime * result + ((this.lane == null) ? 0 : this.lane.hashCode());
87          result = prime * result + ((this.position == null) ? 0 : this.position.hashCode());
88          return result;
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      public boolean equals(final Object obj)
94      {
95          if (this == obj)
96              return true;
97          if (obj == null)
98              return false;
99          if (getClass() != obj.getClass())
100             return false;
101         KpiDirectedLanePosition other = (KpiDirectedLanePosition) obj;
102         if (this.gtuDirection != other.gtuDirection)
103             return false;
104         if (this.lane == null)
105         {
106             if (other.lane != null)
107                 return false;
108         }
109         else if (!this.lane.equals(other.lane))
110             return false;
111         if (this.position == null)
112         {
113             if (other.position != null)
114                 return false;
115         }
116         else if (!this.position.equals(other.position))
117             return false;
118         return true;
119     }
120 
121     /** {@inheritDoc} */
122     @Override
123     public String toString()
124     {
125         return "DirectedLanePosition [lane=" + this.lane + ", position=" + this.position + ", gtuDirection=" + this.gtuDirection
126                 + "]";
127     }
128 
129 }