1 package org.opentrafficsim.core.gtu.following;
2
3 import org.opentrafficsim.core.gtu.lane.LaneBasedGTU;
4 import org.opentrafficsim.core.unit.LengthUnit;
5 import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
6
7 /**
8 * Storage for a reference to a LaneBasedGTU and a headway.
9 * <p>
10 * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights
11 * reserved. <br>
12 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
13 * <p>
14 * @version 11 feb. 2015 <br>
15 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
17 */
18 public class HeadwayGTU
19 {
20 /** the other GTU. */
21 private final LaneBasedGTU<?> otherGTU;
22
23 /** the distance to the GTU in meters. */
24 private final double distanceSI;
25
26 /**
27 * Construct a new HeadwayGTU.
28 * @param otherGTU the other GTU
29 * @param distanceSI the distance to the other GTU in meters; if the other GTU is parallel, use distance Double.NaN
30 */
31 public HeadwayGTU(final LaneBasedGTU<?> otherGTU, final double distanceSI)
32 {
33 this.otherGTU = otherGTU;
34 this.distanceSI = distanceSI;
35 }
36
37 /**
38 * @return the other GTU.
39 */
40 public final LaneBasedGTU<?> getOtherGTU()
41 {
42 return this.otherGTU;
43 }
44
45 /**
46 * Retrieve the distance to the other GTU in meters.
47 * @return the distance to the other GTU in SI unit for length (meter), the value Double.NaN is used to indicate
48 * that the other GTU is parallel with the reference GTU
49 */
50 public final double getDistanceSI()
51 {
52 return this.distanceSI;
53 }
54
55 /**
56 * Retrieve the strongly typed distance to the other GTU.
57 * @return DoubleScalar.Rel<LengthUnit>; the distance to the GTU, return value null indicates that the other
58 * GTU is parallel to the reference GTU
59 */
60 public final DoubleScalar.Rel<LengthUnit> getDistance()
61 {
62 if (Double.isNaN(this.distanceSI))
63 {
64 return null;
65 }
66 return new DoubleScalar.Rel<LengthUnit>(this.distanceSI, LengthUnit.SI);
67 }
68
69 /** {@inheritDoc} */
70 public final String toString()
71 {
72 return String.format("Headway %s to %s", getDistance(), this.otherGTU);
73 }
74
75 }