Class OTSLink

java.lang.Object
nl.tudelft.simulation.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-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

$LastChangedDate: 2019-07-15 11:39:08 +0200 (Mon, 15 Jul 2019) $, @version $Revision: 5564 $, by $Author: pknoppers $, initial version Aug 19, 2014

Author:
Alexander Verbraeck, Peter Knoppers
See Also:
Serialized Form
  • Constructor Details

    • OTSLink

      public OTSLink​(Network network, String id, Node startNode, Node endNode, LinkType linkType, OTSLine3D designLine, OTSSimulatorInterface simulator) throws NetworkException
      Construct a new link.
      Parameters:
      network - Network; the network to which the link belongs
      id - String; the link id
      startNode - Node; start node (directional)
      endNode - Node; end node (directional)
      linkType - LinkType; Link type to indicate compatibility with GTU types
      designLine - OTSLine3D; the OTSLine3D design line of the Link
      simulator - OTSSimulatorInterface; the simulator on which events can be scheduled
      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, OTSSimulatorInterface newSimulator, OTSLink link) throws NetworkException
      Clone a link for a new network.
      Parameters:
      newNetwork - Network; the new network to which the clone belongs
      newSimulator - OTSSimulatorInterface; the new simulator for this network
      link - 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 Details

    • 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 interface Link
      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.
      Specified by:
      addGTU in interface Link
      Parameters:
      gtu - GTU; the GTU to add.
    • 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.
      Specified by:
      removeGTU in interface Link
      Parameters:
      gtu - GTU; the GTU to remove.
    • getGTUs

      public final Set<GTU> getGTUs()
      Provide a safe copy of the set of GTUs.
      Specified by:
      getGTUs in interface Link
      Returns:
      Set<GTU>; a safe copy of the set of GTUs
    • getGTUCount

      public final int getGTUCount()
      Provide the number of GTUs on this link.
      Specified by:
      getGTUCount in interface Link
      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 interface Link
      Returns:
      Network; the network in which this link is registered
    • getId

      public final String getId()
      Specified by:
      getId in interface Identifiable
      Specified by:
      getId in interface Link
      Returns:
      id.
    • getStartNode

      public final Node getStartNode()
      Specified by:
      getStartNode in interface Link
      Returns:
      start node.
    • getEndNode

      public final Node getEndNode()
      Specified by:
      getEndNode in interface Link
      Returns:
      end node.
    • getLinkType

      public final LinkType getLinkType()
      Specified by:
      getLinkType in interface Link
      Returns:
      the link type.
    • getDesignLine

      public final OTSLine3D getDesignLine()
      Specified by:
      getDesignLine in interface Link
      Returns:
      the design line.
    • getSimulator

      public final OTSSimulatorInterface getSimulator()
      Specified by:
      getSimulator in interface Link
      Returns:
      the simulator.
    • getLength

      public final Length getLength()
      Specified by:
      getLength in interface Link
      Returns:
      length of the link.
    • getLocation

      public DirectedPoint getLocation()
      Specified by:
      getLocation in interface Locatable
    • getBounds

      public javax.media.j3d.Bounds getBounds()
      Specified by:
      getBounds in interface Locatable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals​(Object obj)
      Overrides:
      equals in class Object
    • clone

      public OTSLink clone​(Network newNetwork, OTSSimulatorInterface newSimulator) throws NetworkException
      Clone the OTSLink for e.g., copying a network.
      Parameters:
      newNetwork - Network; the new network to which the clone belongs
      newSimulator - OTSSimulatorInterface; the new simulator for this network
      Returns:
      a clone of this object
      Throws:
      NetworkException - in case the cloning fails