1 package org.opentrafficsim.road.gtu.lane.perception.headway;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.djutils.exceptions.Throw;
5 import org.opentrafficsim.core.gtu.GTUException;
6 import org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLight;
7 import org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLightColor;
8
9 /**
10 * Container for a reference to information about a (lane based) traffic light and a headway to the traffic light.
11 * <p>
12 * Copyright (c) 2013-2020 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 * @version $Revision: 1368 $, $LastChangedDate: 2015-09-02 00:20:20 +0200 (Wed, 02 Sep 2015) $, by $Author: averbraeck $,
16 * initial version 11 feb. 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 HeadwayTrafficLight extends AbstractHeadwayLaneBasedObject
21 {
22 /** */
23 private static final long serialVersionUID = 20160410L;
24
25 /** the traffic light object for further observation, can not be null. */
26 private final TrafficLight trafficLight;
27
28 /**
29 * Construct a new Headway information object, for a traffic light ahead of us (or behind us, although that does not seem
30 * very useful).
31 * @param trafficLight TrafficLight; the traffic light object for further observation, can not be null.
32 * @param distance Length; the distance to the traffic light, distance cannot be null.
33 * @throws GTUException when id is null, or parameters are inconsistent
34 */
35 public HeadwayTrafficLight(final TrafficLight trafficLight, final Length distance) throws GTUException
36 {
37 super(ObjectType.TRAFFICLIGHT, id(trafficLight), distance, trafficLight.getLane());
38 this.trafficLight = trafficLight;
39 }
40
41 /**
42 * Get the id of the traffic light; throw an exception if traffic light is null.
43 * @param trafficLight TrafficLight; the traffic light object for further observation, can not be null.
44 * @return he id of the traffic light.
45 * @throws GTUException when the trafficLight object is null
46 */
47 private static String id(final TrafficLight trafficLight) throws GTUException
48 {
49 Throw.when(trafficLight == null, GTUException.class, "Headway constructor: trafficLight == null");
50 return trafficLight.getId();
51 }
52
53 /**
54 * @return the traffic light color.
55 */
56 public final TrafficLightColor getTrafficLightColor()
57 {
58 return this.trafficLight.getTrafficLightColor();
59 }
60
61 /** {@inheritDoc} */
62 @Override
63 public final String toString()
64 {
65 return "HeadwayTrafficLight [trafficLight=" + this.trafficLight + "]";
66 }
67 }