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