SinkSensor.java
package org.opentrafficsim.road.network.lane.object.sensor;
import java.rmi.RemoteException;
import javax.naming.NamingException;
import org.djunits.value.vdouble.scalar.Length;
import org.opentrafficsim.core.compatibility.Compatible;
import org.opentrafficsim.core.gtu.RelativePosition;
import org.opentrafficsim.core.network.NetworkException;
import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
import org.opentrafficsim.road.network.animation.SinkAnimation;
import org.opentrafficsim.road.network.lane.CrossSectionElement;
import org.opentrafficsim.road.network.lane.Lane;
import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
import nl.tudelft.simulation.language.Throw;
/**
* A SinkSensor is a sensor that deletes every GTU that hits it.
* <p>
* Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
* All rights reserved. <br>
* BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
* <p>
* $LastChangedDate: 2015-08-12 16:37:45 +0200 (Wed, 12 Aug 2015) $, @version $Revision: 1240 $, by $Author: averbraeck $,
* initial version an 30, 2015 <br>
* @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
* @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
*/
public class SinkSensor extends AbstractSensor
{
/** */
private static final long serialVersionUID = 20150130L;
/**
* @param lane the lane that triggers the deletion of the GTU.
* @param position the position of the sensor
* @param simulator the simulator to enable animation.
* @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
*/
public SinkSensor(final Lane lane, final Length position, final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
{
super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
try
{
new SinkAnimation(this, simulator);
}
catch (RemoteException | NamingException exception)
{
exception.printStackTrace();
}
}
/**
* @param dummy1 dummy
* @param lane the lane that triggers the deletion of the GTU.
* @param position the position of the sensor
* @param dummy2 dummy
* @param simulator the simulator to enable animation.
* @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
*/
public SinkSensor(final String dummy1, final Lane lane, final Length position, final RelativePosition.TYPE dummy2,
final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
{
super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
try
{
new SinkAnimation(this, simulator);
}
catch (RemoteException | NamingException exception)
{
exception.printStackTrace();
}
}
/** {@inheritDoc} */
@Override
public final void triggerResponse(final LaneBasedGTU gtu)
{
gtu.destroy();
}
/** {@inheritDoc} */
@Override
public final String toString()
{
return "SinkSensor [Lane=" + this.getLane() + "]";
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:designforextension")
public SinkSensor clone(final CrossSectionElement newCSE, final SimulatorInterface.TimeDoubleUnit newSimulator, final boolean animation)
throws NetworkException
{
Throw.when(!(newCSE instanceof Lane), NetworkException.class, "sensors can only be cloned for Lanes");
Throw.when(!(newSimulator instanceof DEVSSimulatorInterface.TimeDoubleUnit), NetworkException.class,
"simulator should be a DEVSSimulator");
return new SinkSensor((Lane) newCSE, getLongitudinalPosition(), (DEVSSimulatorInterface.TimeDoubleUnit) newSimulator);
}
}