View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.following;
2   
3   import org.djunits.unit.LengthUnit;
4   import org.djunits.value.vdouble.scalar.Length;
5   import org.djunits.value.vdouble.scalar.Speed;
6   import org.opentrafficsim.core.gtu.GTUType;
7   
8   /**
9    * Container for a reference to information about a (lane based) GTU and a headway.
10   * <p>
11   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13   * <p>
14   * @version $Revision: 1368 $, $LastChangedDate: 2015-09-02 00:20:20 +0200 (Wed, 02 Sep 2015) $, by $Author: averbraeck $,
15   *          initial version 11 feb. 2015 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
18   */
19  public class HeadwayGTU
20  {
21      /** The id of the GTU for comparison purposes. */
22      private final String gtuId;
23  
24      /** The (perceived) speed of the other GTU. Can be null if unknown. */
25      private final Speed gtuSpeed;
26  
27      /** The (perceived) distance to the GTU. */
28      private final Length.Rel distance;
29  
30      /** The perceived GTU type. */
31      private final GTUType gtuType;
32  
33      /**
34       * Construct a new HeadwayGTU information object.
35       * @param gtuId the id of the GTU for comparison purposes, can be null if no GTU but just headway
36       * @param gtuSpeed the (perceived) speed of the GTU in front of us; can be null if unknown
37       * @param distance the distance to the other GTU; if the other GTU is parallel, use distance null
38       * @param gtuType the perceived GTU type, can be null if GTU unknown
39       */
40      public HeadwayGTU(final String gtuId, final Speed gtuSpeed, final Length.Rel distance, final GTUType gtuType)
41      {
42          this.gtuId = gtuId;
43          this.gtuSpeed = gtuSpeed;
44          this.distance = distance;
45          this.gtuType = gtuType;
46      }
47  
48      /**
49       * Construct a new HeadwayGTU information object.
50       * @param gtuId the id of the GTU for comparison purposes, can be null if no GTU but just headway
51       * @param gtuSpeed the (perceived) speed of the GTU in front of us; can be null if unknown
52       * @param distanceSI the distance to the other GTU; if the other GTU is parallel, use distance null
53       * @param gtuType the perceived GTU type, can be null if GTU unknown
54       */
55      public HeadwayGTU(final String gtuId, final Speed gtuSpeed, final double distanceSI, final GTUType gtuType)
56      {
57          this.gtuId = gtuId;
58          this.gtuSpeed = gtuSpeed;
59          if (Double.isNaN(distanceSI))
60          {
61              this.distance = null;
62          }
63          else
64          {
65              this.distance = new Length.Rel(distanceSI, LengthUnit.SI);
66          }
67          this.gtuType = gtuType;
68      }
69  
70      /**
71       * @return the id of the GTU for comparison purposes, can be null if no GTU but just headway
72       */
73      public final String getGtuId()
74      {
75          return this.gtuId;
76      }
77  
78      /**
79       * @return the (perceived) speed of the GTU in front of us; can be null if unknown.
80       */
81      public final Speed getGtuSpeed()
82      {
83          return this.gtuSpeed;
84      }
85  
86      /**
87       * Retrieve the strongly typed distance to the other GTU.
88       * @return Length.Rel; the distance to the GTU, return value null indicates that the other GTU is parallel to the reference
89       *         GTU
90       */
91      public final Length.Rel getDistance()
92      {
93          return this.distance;
94      }
95  
96      /**
97       * @return the (perceived) gtuType, can be null if no GTU but just headway
98       */
99      public final GTUType getGtuType()
100     {
101         return this.gtuType;
102     }
103 
104     /** {@inheritDoc} */
105     public final String toString()
106     {
107         return String.format("Headway %s to GTU %s of type %s with speed %s", getDistance(), getGtuId(), getGtuType(),
108             getGtuSpeed());
109     }
110 
111 }