Class GTUCompatibility<I extends HierarchicalType<I> & Compatibility<GTUType,I>>
java.lang.Object
org.opentrafficsim.core.compatibility.GTUCompatibility<I>
- Type Parameters:
I- infrastructure type, e.g. LinkType or LaneType, or water way type
- All Implemented Interfaces:
Compatibility<GTUType,I>
public class GTUCompatibility<I extends HierarchicalType<I> & Compatibility<GTUType,I>> extends java.lang.Object implements Compatibility<GTUType,I>
Directional GTUType dependent compatibility.
Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version Aug 25, 2017
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Constructor Summary
Constructors Constructor Description GTUCompatibility(I infrastructure)Construct a new Compatibility object with empty allowed and forbidden sets for both directions.GTUCompatibility(GTUCompatibility<I> original)Construct a new Compatibility and deep copy the allowed and forbidden sets for both directions from an existing Compatibility. -
Method Summary
Modifier and Type Method Description GTUCompatibility<I>addAllowedGTUType(GTUType gtuType, LongitudinalDirectionality directionality)Add a GTUType to this GTUCompatibility.booleanequals(java.lang.Object obj)LongitudinalDirectionalitygetDirectionality(GTUType gtuType, boolean tryParentsOfGTUType)Retrieve the allowed driving directions for a GTUType.inthashCode()java.lang.BooleanisCompatible(GTUType gtuType, GTUDirectionality directionality)Determine if this Compatibility allows or denies a particular GTUType.voidisCompatibleWith(Compatibility<GTUType,?> parentCompatibility, boolean tryParentsOfGTUType)Check if a GTUCompatibility does not allow things that the GTUCompatibility of a parent object disallows, e.g.GTUCompatibility<I>removeAllowedGTUType(GTUType gtuType, LongitudinalDirectionality directionality)Remove a GTUType from the allowed set of this Compatibility.java.lang.StringtoString()
-
Constructor Details
-
GTUCompatibility
Construct a new Compatibility object with empty allowed and forbidden sets for both directions.- Parameters:
infrastructure- I; the infrastructure type, e.g. LinkType, LaneType, SensorType.
-
GTUCompatibility
Construct a new Compatibility and deep copy the allowed and forbidden sets for both directions from an existing Compatibility.- Parameters:
original- GTUCompatibility<I>; the Compatibility from which the allowed and forbidden sets for both directions will be copied
-
-
Method Details
-
isCompatible
Determine if this Compatibility allows or denies a particular GTUType.- Specified by:
isCompatiblein interfaceCompatibility<GTUType,I extends HierarchicalType<I> & Compatibility<GTUType,I>>- Parameters:
gtuType- GTUType; the GTUType to checkdirectionality- GTUDirectionality; the GTUDirectionality in which the GTUType wants to move- Returns:
- Boolean; true if the GTUType is compatible; false if the GTUType is not compatible; null if this Compatibility cannot decide (the Compatibility of a super type should then determine whether the GTUType is compatible)
-
addAllowedGTUType
public final GTUCompatibility<I> addAllowedGTUType(GTUType gtuType, LongitudinalDirectionality directionality) throws java.lang.NullPointerExceptionAdd a GTUType to this GTUCompatibility.- Parameters:
gtuType- GTUType; the GTUType to add to the allowed set of this Compatibilitydirectionality- LongitudinalDirectionality; directionality for which the GTUType must be added- Returns:
- GTYUCompatibility<I>; this GTUCompatibility for method call chaining
- Throws:
java.lang.NullPointerException- whendirectionalityis null
-
removeAllowedGTUType
public final GTUCompatibility<I> removeAllowedGTUType(GTUType gtuType, LongitudinalDirectionality directionality)Remove a GTUType from the allowed set of this Compatibility. This method cannot fail; no warning is issued when the GTUType is not currently in the allowed set.- Parameters:
gtuType- GTUType; the GTUType to remove from the allowed setdirectionality- LongitudinalDirectionality; the longitudinal directionality for which the GTUType must be removed- Returns:
- GTYUCompatibility<I>; this GTUCompatibility for method call chaining
-
toString
public final java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
hashCode
public final int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
isCompatibleWith
public final void isCompatibleWith(Compatibility<GTUType,?> parentCompatibility, boolean tryParentsOfGTUType) throws GTUExceptionCheck if a GTUCompatibility does not allow things that the GTUCompatibility of a parent object disallows, e.g. a permitted driving direction on a Lane should not be forbidden on the Link that the Lane is part of.- Parameters:
parentCompatibility- Compatibility<GTUType, ?>; the GTUCompatibility of the parent objecttryParentsOfGTUType- boolean; whether to try parent GTU types- Throws:
GTUException- if a conflict is found
-
getDirectionality
public final 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.
IftryParentsOfGTUTypeis 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:
getDirectionalityin interfaceCompatibility<GTUType,I extends HierarchicalType<I> & Compatibility<GTUType,I>>- 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_NONEif neither the GTUType or any of its parents specifies a directionality
-