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.dsol.OTSDEVSSimulatorInterface;
9 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
10 import org.opentrafficsim.core.network.NetworkException;
11 import org.opentrafficsim.road.network.lane.CrossSectionElement;
12 import org.opentrafficsim.road.network.lane.Lane;
13 import org.opentrafficsim.road.network.lane.object.AbstractLaneBasedObject;
14 import org.opentrafficsim.road.network.lane.object.LaneBasedObject;
15
16 import nl.tudelft.simulation.language.Throw;
17
18
19
20
21
22
23
24
25
26
27
28 public class SimpleTrafficLight extends AbstractLaneBasedObject implements TrafficLight
29 {
30
31 private static final long serialVersionUID = 201601001L;
32
33
34 private TrafficLightColor trafficLightColor;
35
36
37 private final String id;
38
39
40
41
42
43
44
45
46 public SimpleTrafficLight(final String id, final Lane lane, final Length longitudinalPosition,
47 final OTSDEVSSimulatorInterface simulator) throws NetworkException
48 {
49 super(lane, longitudinalPosition, LaneBasedObject.makeGeometry(lane, longitudinalPosition));
50 Throw.whenNull(id, "Id may not be null");
51 this.id = id;
52 this.trafficLightColor = TrafficLightColor.RED;
53
54 try
55 {
56 new TrafficLightAnimation(this, simulator);
57 }
58 catch (RemoteException exception)
59 {
60 exception.printStackTrace();
61 }
62 catch (NamingException exception)
63 {
64 exception.printStackTrace();
65 }
66 }
67
68
69 @Override
70 public final TrafficLightColor getTrafficLightColor()
71 {
72 return this.trafficLightColor;
73 }
74
75
76 @Override
77 public final void setTrafficLightColor(final TrafficLightColor trafficLightColor)
78 {
79 this.trafficLightColor = trafficLightColor;
80 }
81
82
83 @Override
84 @SuppressWarnings("checkstyle:designforextension")
85 public String toString()
86 {
87 return "SimpleTrafficLight [trafficLightColor=" + this.trafficLightColor + "]";
88 }
89
90
91 @Override
92 public String getId()
93 {
94 return this.id;
95 }
96
97
98 @Override
99 public SimpleTrafficLight clone(final CrossSectionElement newCSE, final OTSSimulatorInterface newSimulator,
100 final boolean animation) throws NetworkException
101 {
102
103 return null;
104 }
105
106 }