Package org.opentrafficsim.core.network
Class LinkType
- java.lang.Object
-
- org.opentrafficsim.base.Type<T>
-
- org.opentrafficsim.base.HierarchicalType<LinkType>
-
- org.opentrafficsim.core.network.LinkType
-
- All Implemented Interfaces:
Serializable
,Identifiable
,Compatibility<GTUType,LinkType>
public class LinkType extends HierarchicalType<LinkType> implements Serializable, Identifiable, Compatibility<GTUType,LinkType>
Link type to indicate compatibility with GTU types. The id of a LinkType should be unique within a simulation. This is, however, not checked or enforced, as different simulations running in the same JVM can have different compatibilitySets for LinkTypes with the same id. Therefore, uniqueness is not enforced.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: 2015-08-30 00:16:51 +0200 (Sun, 30 Aug 2015) $, @version $Revision: 1329 $, by $Author: averbraeck $, initial version Aug 21, 2014
- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LinkType.DEFAULTS
Default types with their name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GTUCompatibility<LinkType>
getCompatibility()
This method won't work correctly in a ReverseLinkType; it should only be used to clone a network; nowhere else.LongitudinalDirectionality
getDirectionality(GTUType gtuType, boolean tryParentsOfGTUType)
Retrieve the allowed driving directions for a GTUType.Network
getNetwork()
Boolean
isCompatible(GTUType gtuType, GTUDirectionality directionality)
Test if a GTUType can travel over the infrastructure.boolean
isConnector()
boolean
isNone()
boolean
isOfType(LinkType.DEFAULTS type)
Whether this, or any of the parent types, equals the given type.boolean
isRailWay()
boolean
isRoad()
boolean
isWaterWay()
LinkType
reverse()
Returns a link type with directionality reversed.String
toString()
-
Methods inherited from class org.opentrafficsim.base.HierarchicalType
commonAncestor, equals, getId, getParent, hashCode, isOfType
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.opentrafficsim.base.Identifiable
getId
-
-
-
-
Constructor Detail
-
LinkType
public LinkType(String id, LinkType parent, GTUCompatibility<LinkType> compatibility, Network network)
Create a new Link type with compatibility set.- Parameters:
id
- String; the id of the lane type (may not be null)parent
- LinkType; the parent type (may be null)compatibility
- the collection of compatible GTUTypes for this LinkType; can be null (resulting in a LinkType that is inaccessible to all GTU types). This constructor makes a deep copy of thecompatibility
.network
- Network; The network to which the LinkType belongs
-
-
Method Detail
-
isOfType
public boolean isOfType(LinkType.DEFAULTS type)
Whether this, or any of the parent types, equals the given type.- Parameters:
type
- DEFAULTS; type- Returns:
- whether this, or any of the parent types, equals the given type
-
isCompatible
public Boolean isCompatible(GTUType gtuType, GTUDirectionality directionality)
Test if a GTUType can travel over the infrastructure.- Specified by:
isCompatible
in interfaceCompatibility<GTUType,LinkType>
- Parameters:
gtuType
- G; the type of the GTUdirectionality
- GTUDirectionality; the direction of the GTU with respect to the design direction of the infrastructure- Returns:
- boolean; true if the GTU can travel over the infrastructure in the given direction; false if the GTU can not
travel over the infrastructure in the given direction; null if the decision should be made by calling
isCompatible
on a higher level in the infrastructure hierarchy
-
getCompatibility
public GTUCompatibility<LinkType> getCompatibility()
This method won't work correctly in a ReverseLinkType; it should only be used to clone a network; nowhere else.- Returns:
- GTUCompatibility<LinkType>; the GTU compatibility for this LinkType
-
reverse
public final LinkType reverse()
Returns a link type with directionality reversed.- Returns:
- LinkType; link type with directionality reversed
-
isNone
public final boolean isNone()
- Returns:
- whether this is
NONE
-
isRoad
public final boolean isRoad()
- Returns:
- whether this is
ROAD
-
isWaterWay
public final boolean isWaterWay()
- Returns:
- whether this is
WATER_WAY
-
isRailWay
public final boolean isRailWay()
- Returns:
- whether this is
RAIL_WAY
-
isConnector
public final boolean isConnector()
- Returns:
- whether this is
CONNECTOR
-
getNetwork
public Network getNetwork()
- Returns:
- the network to which the LinkType belongs
-
getDirectionality
public LongitudinalDirectionality getDirectionality(GTUType gtuType, boolean tryParentsOfGTUType)
Retrieve the allowed driving directions for a GTUType. If there is no match for the specified GTUType in this infrastructure type, this method will recursively check the parent types of the infrastructure element until either a match is found or the root parental type of the infrastructure is reached. When the latter happens without finding a match, what happens next depends on the value oftryParentsOfGTUType
.
IftryParentsOfGTUType
is false, the value null is returned. If true; the parent of the GTUType is used and the search is repeated, etc. If none of the parents of the GTUType yields a result, this method returnsLongitudinalDirectionality.DIR_NONE
.- Specified by:
getDirectionality
in interfaceCompatibility<GTUType,LinkType>
- Parameters:
gtuType
- G; type of the GTUtryParentsOfGTUType
- boolean; if true; the parents of the GTUType are tried if no match was found for the given GTUType- Returns:
- LongitudinalDirectionality; the driving directions for the GTUType, or
LongitudinalDirectionality.DIR_NONE
if neither the GTUType or any of its parents specifies a directionality
-
-