Package org.opentrafficsim.base
Class HierarchicalType<T extends HierarchicalType<T>>
- java.lang.Object
-
- org.opentrafficsim.base.Type<T>
-
- org.opentrafficsim.base.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 protectedHierarchicalType(String id)Constructor for creating the top level types in subclasses.HierarchicalType(String id, T parent)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TcommonAncestor(T type)Returns the common ancestor of both types.booleanequals(Object obj)StringgetId()Returns the Id.TgetParent()inthashCode()booleanisOfType(T type)Whether this, or any of the parent types, equals the given type.
-
-
-
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()
Returns the Id.- Specified by:
getIdin interfaceIdentifiable- Returns:
- Id.
-
getParent
public final T getParent()
- Returns:
- parent or
nullif 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,
nullif none
-
-