Package org.opentrafficsim.base
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 Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor for creating the top level types in subclasses.HierarchicalType(String id, T parent) Constructor that creates a hierarchical type including a link to a parent type. -
Method Summary
Modifier and TypeMethodDescriptioncommonAncestor(T type) Returns the common ancestor of both types.booleanReturn the children of this hierarchical type.final StringgetId()Return the parent of this type, or null when no parent was identified.inthashCode()final booleanWhether this, or any of the parent types, equals the given type.
-
Constructor Details
-
HierarchicalType
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
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
- Specified by:
getIdin interfaceIdentifiable
-
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
Return the children of this hierarchical type.- Returns:
- children Set<T> The set of children of the hierarchical type
-
isOfType
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
Returns the common ancestor of both types.- Parameters:
type- other type.- Returns:
- common ancestor of both types, empty if none
-
hashCode
public int hashCode() -
equals
-