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