HierarchicallyTyped.java

  1. package org.opentrafficsim.base;

  2. /**
  3.  * HierarchicallyTyped is the interface of objects that are of a HierarchicalType. Examples are Gtu (of type GtuType), Link (of
  4.  * type LinkType), and Detector (of type DetectorType). By making these objects HierarchicallyTyped, they can return their
  5.  * correct 'type' as well as check whether they belong to a certain hierarchical type.
  6.  * <p>
  7.  * Copyright (c) 2022-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  8.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  9.  * </p>
  10.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  11.  * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
  12.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  13.  * @param <T> The HierarchicalType of the typing object
  14.  * @param <I> The type of the typed object
  15.  */
  16. public interface HierarchicallyTyped<T extends HierarchicalType<T, I>, I extends HierarchicallyTyped<T, I>>
  17. {
  18.     /**
  19.      * Return the assigned type of the typed object.
  20.      * @return the assigned type of the typed object
  21.      */
  22.     T getType();

  23.     /**
  24.      * Return whether the object if has type 'type', or one of the subtypes of 'type'. An example is
  25.      * <code>gtu.isOfType(Types.BUS)</code> or <code>link.isOfType(Types.HIGHWAY)</code>.
  26.      * @param type the type to check against
  27.      * @return whether the object if has type 'type', or one of the subtypes of 'type'
  28.      */
  29.     default boolean isOfType(final T type)
  30.     {
  31.         return getType().isOfType(type);
  32.     }
  33. }