1 package org.opentrafficsim.road.network.lane.object.sensor;
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.compatibility.Compatible;
9 import org.opentrafficsim.core.gtu.RelativePosition;
10 import org.opentrafficsim.core.network.NetworkException;
11 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
12 import org.opentrafficsim.road.network.animation.SinkAnimation;
13 import org.opentrafficsim.road.network.lane.CrossSectionElement;
14 import org.opentrafficsim.road.network.lane.Lane;
15
16 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
17 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
18 import nl.tudelft.simulation.language.Throw;
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public class SinkSensor extends AbstractSensor
33 {
34
35 private static final long serialVersionUID = 20150130L;
36
37
38
39
40
41
42
43 public SinkSensor(final Lane lane, final Length position, final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
44 {
45 super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
46 try
47 {
48 new SinkAnimation(this, simulator);
49 }
50 catch (RemoteException | NamingException exception)
51 {
52 exception.printStackTrace();
53 }
54 }
55
56
57
58
59
60
61
62
63
64 public SinkSensor(final String dummy1, final Lane lane, final Length position, final RelativePosition.TYPE dummy2,
65 final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
66 {
67 super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
68 try
69 {
70 new SinkAnimation(this, simulator);
71 }
72 catch (RemoteException | NamingException exception)
73 {
74 exception.printStackTrace();
75 }
76 }
77
78
79 @Override
80 public final void triggerResponse(final LaneBasedGTU gtu)
81 {
82 gtu.destroy();
83 }
84
85
86 @Override
87 public final String toString()
88 {
89 return "SinkSensor [Lane=" + this.getLane() + "]";
90 }
91
92
93 @Override
94 @SuppressWarnings("checkstyle:designforextension")
95 public SinkSensor clone(final CrossSectionElement newCSE, final SimulatorInterface.TimeDoubleUnit newSimulator, final boolean animation)
96 throws NetworkException
97 {
98 Throw.when(!(newCSE instanceof Lane), NetworkException.class, "sensors can only be cloned for Lanes");
99 Throw.when(!(newSimulator instanceof DEVSSimulatorInterface.TimeDoubleUnit), NetworkException.class,
100 "simulator should be a DEVSSimulator");
101 return new SinkSensor((Lane) newCSE, getLongitudinalPosition(), (DEVSSimulatorInterface.TimeDoubleUnit) newSimulator);
102 }
103
104 }