SimpleTrafficLight.java

  1. package org.opentrafficsim.road.network.lane.object.trafficlight;

  2. import org.djunits.value.vdouble.scalar.Length;
  3. import org.djutils.exceptions.Throw;
  4. import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
  5. import org.opentrafficsim.core.network.NetworkException;
  6. import org.opentrafficsim.road.network.lane.CrossSectionElement;
  7. import org.opentrafficsim.road.network.lane.Lane;

  8. /**
  9.  * Standard implementation of a traffic light.
  10.  * <p>
  11.  * Copyright (c) 2013-2022 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.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  15.  * initial version Nov 30, 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 SimpleTrafficLight extends AbstractTrafficLight
  20. {
  21.     /** */
  22.     private static final long serialVersionUID = 201601001L;

  23.     /**
  24.      * @param id String; traffic light id
  25.      * @param lane Lane; lane where the traffic light is located
  26.      * @param longitudinalPosition Length; position of the traffic light on the lane, in the design direction
  27.      * @param simulator OTSSimulatorInterface; the simulator for animation and timed events
  28.      * @throws NetworkException on failure to place the object
  29.      */
  30.     public SimpleTrafficLight(final String id, final Lane lane, final Length longitudinalPosition,
  31.             final OTSSimulatorInterface simulator) throws NetworkException
  32.     {
  33.         super(id, lane, longitudinalPosition, simulator);
  34.     }

  35.     /** {@inheritDoc} */
  36.     @Override
  37.     @SuppressWarnings("checkstyle:designforextension")
  38.     public String toString()
  39.     {
  40.         return "SimpleTrafficLight [trafficLightColor=" + getTrafficLightColor() + "]";
  41.     }

  42.     /** {@inheritDoc} */
  43.     @Override
  44.     @SuppressWarnings("checkstyle:designforextension")
  45.     public SimpleTrafficLight clone(final CrossSectionElement newCSE, final OTSSimulatorInterface newSimulator)
  46.             throws NetworkException
  47.     {
  48.         Throw.when(!(newCSE instanceof Lane), NetworkException.class, "traffic lights can only be cloned for Lanes");
  49.         Throw.when(!(newSimulator instanceof OTSSimulatorInterface), NetworkException.class,
  50.                 "simulator should be a DEVSSimulator");
  51.         return new SimpleTrafficLight(getId(), (Lane) newCSE, getLongitudinalPosition(),
  52.                 (OTSSimulatorInterface) newSimulator);
  53.     }

  54. }