Class HierarchicalType<T extends HierarchicalType<T>>

  • Type Parameters:
    T - Self-reference to type.
    All Implemented Interfaces:
    Identifiable

    public abstract class HierarchicalType<T extends HierarchicalType<T>>
    extends Type<T>
    implements Identifiable
    Super class for types with hierarchical structure. Upper level types without parent can be created in sub classes using a protected constructor without parent.

    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 30 jun. 2017
    Author:
    Alexander Verbraeck, Peter Knoppers, Wouter Schakel
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected HierarchicalType​(java.lang.String id)
      Constructor for creating the top level types in subclasses.
        HierarchicalType​(java.lang.String id, T parent)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T commonAncestor​(T type)
      Returns the common ancestor of both types.
      boolean equals​(java.lang.Object obj)
      java.lang.String getId()
      Returns the Id.
      T getParent()  
      int hashCode()
      boolean isOfType​(T type)
      Whether this, or any of the parent types, equals the given type.
      • Methods inherited from class org.opentrafficsim.base.Type

        isType
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HierarchicalType

        protected HierarchicalType​(java.lang.String id)
                            throws java.lang.NullPointerException
        Constructor for creating the top level types in subclasses.
        Parameters:
        id - String; The id of the type to make it identifiable.
        Throws:
        java.lang.NullPointerException - if the id is null
      • HierarchicalType

        public HierarchicalType​(java.lang.String id,
                                T parent)
                         throws java.lang.NullPointerException
        Constructor.
        Parameters:
        id - String; The id of the type to make it identifiable.
        parent - T; parent type
        Throws:
        java.lang.NullPointerException - if the id is null
    • Method Detail

      • getId

        public final java.lang.String getId()
        Returns the Id.
        Specified by:
        getId in interface Identifiable
        Returns:
        Id.
      • getParent

        public final T getParent()
        Returns:
        parent or null if this is a top level type.
      • isOfType

        public final boolean isOfType​(T type)
        Whether this, or any of the parent types, equals the given type.
        Parameters:
        type - T; type
        Returns:
        whether this, or any of the parent types, equals the given type
      • commonAncestor

        public final T commonAncestor​(T type)
        Returns the common ancestor of both types.
        Parameters:
        type - T; other type.
        Returns:
        common ancestor of both types, null if none
      • hashCode

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

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