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-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.$LastChangedDate$, @version $Revision$, by $Author$, initial version Aug 19, 2014
- 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 void
addGTU(GTU gtu)
Add a GTU to this link (e.g., for statistical purposes, or for a model on macro level).OTSLink
clone(OTSNetwork newNetwork)
Clone the OTSLink for e.g., copying a network.boolean
equals(Object obj)
Bounds
getBounds()
OTSLine3D
getDesignLine()
LongitudinalDirectionality
getDirectionality(GTUType gtuType)
This method returns the directionality of the link for a GTU type.Node
getEndNode()
int
getGTUCount()
Provide the number of GTUs on this link.Set<GTU>
getGTUs()
Provide a safe copy of the set of GTUs.String
getId()
Length
getLength()
LinkType
getLinkType()
DirectedPoint
getLocation()
Network
getNetwork()
Return the network in which this link is registered.OTSSimulatorInterface
getSimulator()
Serializable
getSourceId()
Node
getStartNode()
int
hashCode()
void
removeGTU(GTU gtu)
Remove a GTU from this link.String
toString()
-
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:
getDirectionality
in 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:
getGTUCount
in 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:
getNetwork
in interfaceLink
- Returns:
- Network; the network in which this link is registered
-
getId
public final String getId()
- Specified by:
getId
in interfaceIdentifiable
- Specified by:
getId
in interfaceLink
- Returns:
- id.
-
getStartNode
public final Node getStartNode()
- Specified by:
getStartNode
in interfaceLink
- Returns:
- start node.
-
getEndNode
public final Node getEndNode()
- Specified by:
getEndNode
in interfaceLink
- Returns:
- end node.
-
getLinkType
public final LinkType getLinkType()
- Specified by:
getLinkType
in interfaceLink
- Returns:
- the link type.
-
getDesignLine
public final OTSLine3D getDesignLine()
- Specified by:
getDesignLine
in interfaceLink
- Returns:
- the design line.
-
getSimulator
public final OTSSimulatorInterface getSimulator()
- Specified by:
getSimulator
in interfaceLink
- Returns:
- the simulator.
-
getLength
public final Length getLength()
-
getLocation
public DirectedPoint getLocation()
- Specified by:
getLocation
in interfaceLocatable
-
getBounds
public Bounds getBounds()
-
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:
getSourceId
in interfaceEventProducerInterface
- Specified by:
getSourceId
in classEventProducer
-
-