View Javadoc
1   package org.opentrafficsim.road.network.lane.object.trafficlight;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djutils.exceptions.Throw;
5   import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
6   import org.opentrafficsim.core.network.NetworkException;
7   import org.opentrafficsim.road.network.lane.CrossSectionElement;
8   import org.opentrafficsim.road.network.lane.Lane;
9   
10  /**
11   * Standard implementation of a traffic light.
12   * <p>
13   * Copyright (c) 2013-2022 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   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
17   * initial version Nov 30, 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 SimpleTrafficLight extends AbstractTrafficLight
22  {
23      /** */
24      private static final long serialVersionUID = 201601001L;
25  
26      /**
27       * @param id String; traffic light id
28       * @param lane Lane; lane where the traffic light is located
29       * @param longitudinalPosition Length; position of the traffic light on the lane, in the design direction
30       * @param simulator OTSSimulatorInterface; the simulator for animation and timed events
31       * @throws NetworkException on failure to place the object
32       */
33      public SimpleTrafficLight(final String id, final Lane lane, final Length longitudinalPosition,
34              final OTSSimulatorInterface simulator) throws NetworkException
35      {
36          super(id, lane, longitudinalPosition, simulator);
37      }
38  
39      /** {@inheritDoc} */
40      @Override
41      @SuppressWarnings("checkstyle:designforextension")
42      public String toString()
43      {
44          return "SimpleTrafficLight [trafficLightColor=" + getTrafficLightColor() + "]";
45      }
46  
47      /** {@inheritDoc} */
48      @Override
49      @SuppressWarnings("checkstyle:designforextension")
50      public SimpleTrafficLight clone(final CrossSectionElement newCSE, final OTSSimulatorInterface newSimulator)
51              throws NetworkException
52      {
53          Throw.when(!(newCSE instanceof Lane), NetworkException.class, "traffic lights can only be cloned for Lanes");
54          Throw.when(!(newSimulator instanceof OTSSimulatorInterface), NetworkException.class,
55                  "simulator should be a DEVSSimulator");
56          return new SimpleTrafficLight(getId(), (Lane) newCSE, getLongitudinalPosition(),
57                  (OTSSimulatorInterface) newSimulator);
58      }
59  
60  }