Package org.opentrafficsim.core.network
Class OTSLink
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.opentrafficsim.core.network.OTSLink
-
- All Implemented Interfaces:
Serializable,Locatable,EventProducerInterface,Identifiable,Drawable,Link
- Direct Known Subclasses:
CapacityOTSLink
public class OTSLink extends EventProducer implements Link, Serializable, Locatable
A standard implementation of a link between two OTSNodes.Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
$LastChangedDate: 2020-05-14 13:12:03 +0200 (Thu, 14 May 2020) $, @version $Revision: 6470 $, by $Author: pknoppers $, initial version Aug 19, 2014
BSD-style license. See OpenTrafficSim License.- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.djutils.event.EventProducer
eventProducerImpl
-
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
-
Fields inherited from interface org.opentrafficsim.core.network.Link
GTU_ADD_EVENT, GTU_REMOVE_EVENT
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGTU(GTU gtu)Add a GTU to this link (e.g., for statistical purposes, or for a model on macro level).OTSLinkclone(OTSNetwork newNetwork)Clone the OTSLink for e.g., copying a network.booleanequals(Object obj)javax.media.j3d.BoundsgetBounds()OTSLine3DgetDesignLine()LongitudinalDirectionalitygetDirectionality(GTUType gtuType)This method returns the directionality of the link for a GTU type.NodegetEndNode()intgetGTUCount()Provide the number of GTUs on this link.Set<GTU>getGTUs()Provide a safe copy of the set of GTUs.StringgetId()LengthgetLength()LinkTypegetLinkType()DirectedPointgetLocation()NetworkgetNetwork()Return the network in which this link is registered.OTSSimulatorInterfacegetSimulator()SerializablegetSourceId()NodegetStartNode()inthashCode()voidremoveGTU(GTU gtu)Remove a GTU from this link.StringtoString()-
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
-
-
-
Constructor Detail
-
OTSLink
public OTSLink(Network network, String id, Node startNode, Node endNode, LinkType linkType, OTSLine3D designLine) throws NetworkException
Construct a new link.- Parameters:
network- Network; the network to which the link belongsid- String; the link idstartNode- Node; start node (directional)endNode- Node; end node (directional)linkType- LinkType; Link type to indicate compatibility with GTU typesdesignLine- OTSLine3D; the OTSLine3D design line of the Link- Throws:
NetworkException- if link already exists in the network, if name of the link is not unique, or if the start node or the end node of the link are not registered in the network.
-
OTSLink
protected OTSLink(Network newNetwork, OTSLink link) throws NetworkException
Clone a link for a new network.- Parameters:
newNetwork- Network; the new network to which the clone belongslink- OTSLink; the link to clone from- Throws:
NetworkException- if link already exists in the network, if name of the link is not unique, or if the start node or the end node of the link are not registered in the network.
-
-
Method Detail
-
getDirectionality
public final LongitudinalDirectionality getDirectionality(GTUType gtuType)
This method returns the directionality of the link for a GTU type. It might be that the link is FORWARD (from start node to end node) for the GTU type CAR, but BOTH for the GTU type BICYCLE (i.e., bicycles can also go from end node to start node). If there is no entry for the given GTU Type, the values of GTUType.ALL will be returned. If this entry is not present, LongitudinalDirectionality.NONE will be returned.- Specified by:
getDirectionalityin interfaceLink- Parameters:
gtuType- GTUType; the GTU type to request the directionality for- Returns:
- the longitudinal directionality of the link (FORWARD, BACKWARD, BOTH or NONE) for the given GTU type. NONE will be returned if no directionality is given.
-
addGTU
public final void addGTU(GTU gtu)
Add a GTU to this link (e.g., for statistical purposes, or for a model on macro level). It is safe to add a GTU again. No warning or error will be given. The GTU_ADD_EVENT will only be fired when the GTU was not already on the link.
-
removeGTU
public final void removeGTU(GTU gtu)
Remove a GTU from this link. It is safe to try to remove a GTU again. No warning or error will be given. The GTU_REMOVE_EVENT will only be fired when the GTU was on the link.
-
getGTUCount
public final int getGTUCount()
Provide the number of GTUs on this link.- Specified by:
getGTUCountin interfaceLink- Returns:
- int; the number of GTUs on this link
-
getNetwork
public Network getNetwork()
Return the network in which this link is registered. Cannot be null.- Specified by:
getNetworkin interfaceLink- Returns:
- Network; the network in which this link is registered
-
getId
public final String getId()
- Specified by:
getIdin interfaceIdentifiable- Specified by:
getIdin interfaceLink- Returns:
- id.
-
getStartNode
public final Node getStartNode()
- Specified by:
getStartNodein interfaceLink- Returns:
- start node.
-
getEndNode
public final Node getEndNode()
- Specified by:
getEndNodein interfaceLink- Returns:
- end node.
-
getLinkType
public final LinkType getLinkType()
- Specified by:
getLinkTypein interfaceLink- Returns:
- the link type.
-
getDesignLine
public final OTSLine3D getDesignLine()
- Specified by:
getDesignLinein interfaceLink- Returns:
- the design line.
-
getSimulator
public final OTSSimulatorInterface getSimulator()
- Specified by:
getSimulatorin interfaceLink- Returns:
- the simulator.
-
getLength
public final Length getLength()
-
getLocation
public DirectedPoint getLocation()
- Specified by:
getLocationin interfaceLocatable
-
clone
public OTSLink clone(OTSNetwork newNetwork) throws NetworkException
Clone the OTSLink for e.g., copying a network.- Parameters:
newNetwork- Network; the new network to which the clone belongs- Returns:
- a clone of this object
- Throws:
NetworkException- in case the cloning fails
-
getSourceId
public Serializable getSourceId()
- Specified by:
getSourceIdin interfaceEventProducerInterface- Specified by:
getSourceIdin classEventProducer
-
-