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-2019 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 Details

    • GTUCompatibility

      public GTUCompatibility​(I infrastructure)
      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

      public GTUCompatibility​(GTUCompatibility<I> original)
      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

      public final java.lang.Boolean isCompatible​(GTUType gtuType, GTUDirectionality directionality)
      Determine if this Compatibility allows or denies a particular GTUType.
      Specified by:
      isCompatible in interface Compatibility<GTUType,​I extends HierarchicalType<I> & Compatibility<GTUType,​I>>
      Parameters:
      gtuType - GTUType; the GTUType to check
      directionality - 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.NullPointerException
      Add a GTUType to this GTUCompatibility.
      Parameters:
      gtuType - GTUType; the GTUType to add to the allowed set of this Compatibility
      directionality - LongitudinalDirectionality; directionality for which the GTUType must be added
      Returns:
      GTYUCompatibility<I>; this GTUCompatibility for method call chaining
      Throws:
      java.lang.NullPointerException - when directionality is 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 set
      directionality - 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:
      toString in class java.lang.Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public final boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • isCompatibleWith

      public final void isCompatibleWith​(Compatibility<GTUType,​?> parentCompatibility, boolean tryParentsOfGTUType) throws GTUException
      Check 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 object
      tryParentsOfGTUType - 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 of tryParentsOfGTUType.
      If tryParentsOfGTUType 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 returns LongitudinalDirectionality.DIR_NONE.
      Specified by:
      getDirectionality in interface Compatibility<GTUType,​I extends HierarchicalType<I> & Compatibility<GTUType,​I>>
      Parameters:
      gtuType - G; type of the GTU
      tryParentsOfGTUType - 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