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-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14 * </p>
15 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
16 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
17 */
18 public class HeadwayTrafficLight extends AbstractHeadwayLaneBasedObject
19 {
20 /** */
21 private static final long serialVersionUID = 20160410L;
22
23 /** the traffic light object for further observation, can not be null. */
24 private final TrafficLight trafficLight;
25
26 /**
27 * Construct a new Headway information object, for a traffic light ahead of us (or behind us, although that does not seem
28 * very useful).
29 * @param trafficLight TrafficLight; the traffic light object for further observation, can not be null.
30 * @param distance Length; the distance to the traffic light, distance cannot be null.
31 * @throws GtuException when id is null, or parameters are inconsistent
32 */
33 public HeadwayTrafficLight(final TrafficLight trafficLight, final Length distance) throws GtuException
34 {
35 super(ObjectType.TRAFFICLIGHT, id(trafficLight), distance, trafficLight.getLane());
36 this.trafficLight = trafficLight;
37 }
38
39 /**
40 * Get the id of the traffic light; throw an exception if traffic light is null.
41 * @param trafficLight TrafficLight; the traffic light object for further observation, can not be null.
42 * @return he id of the traffic light.
43 * @throws GtuException when the trafficLight object is null
44 */
45 private static String id(final TrafficLight trafficLight) throws GtuException
46 {
47 Throw.when(trafficLight == null, GtuException.class, "Headway constructor: trafficLight == null");
48 return trafficLight.getId();
49 }
50
51 /**
52 * @return the traffic light color.
53 */
54 public final TrafficLightColor getTrafficLightColor()
55 {
56 return this.trafficLight.getTrafficLightColor();
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public final String toString()
62 {
63 return "HeadwayTrafficLight [trafficLight=" + this.trafficLight + "]";
64 }
65 }