Class HierarchicalType<T extends HierarchicalType<T,I>,I extends HierarchicallyTyped<T,I>>

java.lang.Object
org.opentrafficsim.base.HierarchicalType<T,I>
Type Parameters:
T - Self-reference to type.
I - Infrastructure type belonging to hierarchical type
All Implemented Interfaces:
Identifiable, Type<T>

public abstract class HierarchicalType<T extends HierarchicalType<T,I>,I extends HierarchicallyTyped<T,I>> extends Object implements Identifiable, Type<T>
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-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Constructor Details

    • HierarchicalType

      protected HierarchicalType(String id) throws NullPointerException
      Constructor for creating the top level types in subclasses.
      Parameters:
      id - 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 that creates a hierarchical type including a link to a parent type.
      Parameters:
      id - The id of the type to make it identifiable.
      parent - parent type; can be null, in that case no parent will be identified
      Throws:
      NullPointerException - if the id is null
  • Method Details

    • getId

      public final String getId()
      Specified by:
      getId in interface Identifiable
    • getParent

      public final Optional<T> getParent()
      Return the parent of this type, or null when no parent was identified.
      Returns:
      parent, empty if this is a top level type
    • getChildren

      public Set<T> getChildren()
      Return the children of this hierarchical type.
      Returns:
      children Set<T> The set of children of the hierarchical type
    • isOfType

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

      public final Optional<T> commonAncestor(T type)
      Returns the common ancestor of both types.
      Parameters:
      type - other type.
      Returns:
      common ancestor of both types, empty if none
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object