1 package org.opentrafficsim.road.network.lane.object.trafficlight;
2
3 import java.rmi.RemoteException;
4
5 import javax.naming.NamingException;
6
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.opentrafficsim.core.network.NetworkException;
9 import org.opentrafficsim.road.network.animation.TrafficLightAnimation;
10 import org.opentrafficsim.road.network.lane.CrossSectionElement;
11 import org.opentrafficsim.road.network.lane.Lane;
12
13 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
14 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
15 import nl.tudelft.simulation.language.Throw;
16
17
18
19
20
21
22
23
24
25
26
27
28 public class SimpleTrafficLight extends AbstractTrafficLight
29 {
30
31 private static final long serialVersionUID = 201601001L;
32
33
34
35
36
37
38
39
40 public SimpleTrafficLight(final String id, final Lane lane, final Length longitudinalPosition,
41 final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
42 {
43 super(id, lane, longitudinalPosition, simulator);
44
45 try
46 {
47 new TrafficLightAnimation(this, simulator);
48 }
49 catch (RemoteException | NamingException exception)
50 {
51 throw new NetworkException(exception);
52 }
53 }
54
55
56 @Override
57 @SuppressWarnings("checkstyle:designforextension")
58 public String toString()
59 {
60 return "SimpleTrafficLight [trafficLightColor=" + getTrafficLightColor() + "]";
61 }
62
63
64 @Override
65 @SuppressWarnings("checkstyle:designforextension")
66 public SimpleTrafficLight clone(final CrossSectionElement newCSE, final SimulatorInterface.TimeDoubleUnit newSimulator,
67 final boolean animation) throws NetworkException
68 {
69 Throw.when(!(newCSE instanceof Lane), NetworkException.class, "traffic lights can only be cloned for Lanes");
70 Throw.when(!(newSimulator instanceof DEVSSimulatorInterface.TimeDoubleUnit), NetworkException.class,
71 "simulator should be a DEVSSimulator");
72 return new SimpleTrafficLight(getId(), (Lane) newCSE, getLongitudinalPosition(),
73 (DEVSSimulatorInterface.TimeDoubleUnit) newSimulator);
74
75
76 }
77
78 }