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 Detail

      • HierarchicalType

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

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

      • getId

        public final String getId()
        Retrieve the id of the object.
        Specified by:
        getId in interface Identifiable
        Returns:
        String; the id of the object
      • 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 Object