View Javadoc
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.dsol.OTSDEVSSimulatorInterface;
9   import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
10  import org.opentrafficsim.core.gtu.RelativePosition;
11  import org.opentrafficsim.core.network.NetworkException;
12  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
13  import org.opentrafficsim.road.network.animation.SinkAnimation;
14  import org.opentrafficsim.road.network.lane.CrossSectionElement;
15  import org.opentrafficsim.road.network.lane.Lane;
16  
17  import nl.tudelft.simulation.language.Throw;
18  
19  /**
20   * sensor that deletes the GTU.
21   * <p>
22   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
23   * All rights reserved. <br>
24   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25   * <p>
26   * $LastChangedDate: 2015-08-12 16:37:45 +0200 (Wed, 12 Aug 2015) $, @version $Revision: 1240 $, by $Author: averbraeck $,
27   * initial version an 30, 2015 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   */
31  public class SinkSensor extends AbstractSensor
32  {
33      /** */
34      private static final long serialVersionUID = 20150130L;
35  
36      /**
37       * @param lane the lane that triggers the deletion of the GTU.
38       * @param position the position of the sensor
39       * @param simulator the simulator to enable animation.
40       * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
41       */
42      public SinkSensor(final Lane lane, final Length position, final OTSDEVSSimulatorInterface simulator) throws NetworkException
43      {
44          super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator);
45          try
46          {
47              new SinkAnimation(this, simulator);
48          }
49          catch (RemoteException | NamingException exception)
50          {
51              exception.printStackTrace();
52          }
53      }
54  
55      /**
56       * @param dummy1 dummy
57       * @param lane the lane that triggers the deletion of the GTU.
58       * @param position the position of the sensor
59       * @param dummy2 dummy
60       * @param simulator the simulator to enable animation.
61       * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
62       */
63      public SinkSensor(final String dummy1, final Lane lane, final Length position, final RelativePosition.TYPE dummy2,
64              final OTSDEVSSimulatorInterface simulator) throws NetworkException
65      {
66          super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator);
67          try
68          {
69              new SinkAnimation(this, simulator);
70          }
71          catch (RemoteException | NamingException exception)
72          {
73              exception.printStackTrace();
74          }
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public final void triggerResponse(final LaneBasedGTU gtu)
80      {
81          gtu.destroy();
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public final String toString()
87      {
88          return "SinkSensor [Lane=" + this.getLane() + "]";
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      @SuppressWarnings("checkstyle:designforextension")
94      public SinkSensor clone(final CrossSectionElement newCSE, final OTSSimulatorInterface newSimulator, final boolean animation)
95              throws NetworkException
96      {
97          Throw.when(!(newCSE instanceof Lane), NetworkException.class, "sensors can only be cloned for Lanes");
98          Throw.when(!(newSimulator instanceof OTSDEVSSimulatorInterface), NetworkException.class,
99                  "simulator should be a DEVSSimulator");
100         return new SinkSensor((Lane) newCSE, getLongitudinalPosition(), (OTSDEVSSimulatorInterface) newSimulator);
101     }
102 
103 }