1 package org.opentrafficsim.road.network.lane.object.sensor;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.djutils.exceptions.Throw;
5 import org.opentrafficsim.core.compatibility.Compatible;
6 import org.opentrafficsim.core.gtu.RelativePosition;
7 import org.opentrafficsim.core.network.NetworkException;
8 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9 import org.opentrafficsim.road.network.lane.CrossSectionElement;
10 import org.opentrafficsim.road.network.lane.Lane;
11
12 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
13 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class SinkSensor extends AbstractSensor
28 {
29
30 private static final long serialVersionUID = 20150130L;
31
32
33
34
35
36
37
38 public SinkSensor(final Lane lane, final Length position, final DEVSSimulatorInterface.TimeDoubleUnit simulator)
39 throws NetworkException
40 {
41 super("SINK@" + lane.getFullId(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
42 }
43
44
45
46
47
48
49
50
51
52 public SinkSensor(final String dummy1, final Lane lane, final Length position, final RelativePosition.TYPE dummy2,
53 final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
54 {
55 super("SINK@" + lane.getFullId(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
56 }
57
58
59 @Override
60 public final void triggerResponse(final LaneBasedGTU gtu)
61 {
62 gtu.destroy();
63 }
64
65
66 @Override
67 public final String toString()
68 {
69 return "SinkSensor [Lane=" + this.getLane() + "]";
70 }
71
72
73 @Override
74 @SuppressWarnings("checkstyle:designforextension")
75 public SinkSensor clone(final CrossSectionElement newCSE, final SimulatorInterface.TimeDoubleUnit newSimulator)
76 throws NetworkException
77 {
78 Throw.when(!(newCSE instanceof Lane), NetworkException.class, "sensors can only be cloned for Lanes");
79 Throw.when(!(newSimulator instanceof DEVSSimulatorInterface.TimeDoubleUnit), NetworkException.class,
80 "simulator should be a DEVSSimulator");
81 return new SinkSensor((Lane) newCSE, getLongitudinalPosition(), (DEVSSimulatorInterface.TimeDoubleUnit) newSimulator);
82 }
83
84 }