Package org.djunits.quantity.def
Class AbstractReference<R extends AbstractReference<R,Q>,Q extends Quantity<Q,?>>
java.lang.Object
org.djunits.quantity.def.AbstractReference<R,Q>
- Type Parameters:
R- the reference type itselfQ- the relative quantity for the offset
- All Implemented Interfaces:
org.djutils.base.Identifiable
- Direct Known Subclasses:
Direction.Reference,Position.Reference,Temperature.Reference,Time.Reference
public abstract class AbstractReference<R extends AbstractReference<R,Q>,Q extends Quantity<Q,?>>
extends Object
implements org.djutils.base.Identifiable
Reference contains information about the reference point or origin / zero point of an absolute quantity.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
- Author:
- Alexander Verbraeck
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Map<Class<?>,Map<String, AbstractReference<?, ?>>> Master registry: per concrete Reference subclass we keep a map of id to reference. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractReference(String id, String name, Q offset, R offsetReference) Define a new reference point for the absolute quantity. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsId(Class<?> referenceClass, String id) Check existence of id in a specific Reference subclass.booleanstatic <R extends AbstractReference<R,?>>
RFetch a reference by class and id.getId()getName()Return the offset w.r.t. the offset reference, or zero when the offset is not defined.Return the offset reference for the offset, or null when the offset reference is not defined.Map<String,AbstractReference<?, ?>> Return a safe copy of the static reference map for this Reference subclass.inthashCode()protected static Map<String,AbstractReference<?, ?>> Get or create the inner map for a specific Reference subclass.static Map<String,AbstractReference<?, ?>> snapshotMap(Class<?> referenceClass) Return a safe copy (snapshot) of the registry for a Reference subclass.toString()booleanInstance-level unregister; removes this reference from the per-class registry.
-
Field Details
-
REFERENCES
Master registry: per concrete Reference subclass we keep a map of id to reference. This prevents name collisions between different absolute quantities.
-
-
Constructor Details
-
AbstractReference
Define a new reference point for the absolute quantity. Prevent duplicate registration of the same id within the same Reference subclass.- Parameters:
id- the idname- the name or explanationoffset- the offset w.r.t. the offsetReference, should be ZERO when offsetReference is nulloffsetReference- the reference to which the offset is relative, can be null- Throws:
IllegalArgumentException- if an id is already registered for this Reference subclass
-
-
Method Details
-
mapFor
Get or create the inner map for a specific Reference subclass.- Parameters:
referenceClass- the reference class to look up- Returns:
- the existing or new reference map for the the Reference subclass
-
get
Fetch a reference by class and id. Returns null when not found.- Type Parameters:
R- the reference subclass type- Parameters:
referenceClass- the concrete Reference subclassid- the id- Returns:
- the reference instance or null
-
containsId
Check existence of id in a specific Reference subclass.- Parameters:
referenceClass- the reference subclass to checkid- the id to check- Returns:
- whether the id exists for the Reference subclass
-
snapshotMap
Return a safe copy (snapshot) of the registry for a Reference subclass.- Parameters:
referenceClass- the reference subclass to retrieve- Returns:
- a safe copy of the reference map
-
getReferenceMap
Return a safe copy of the static reference map for this Reference subclass.- Returns:
- a safe copy of the static reference map for this subclass
-
unregister
public boolean unregister()Instance-level unregister; removes this reference from the per-class registry. Intended primarily for unit tests to clean up temporary references. Existing objects that hold a direct pointer to this instance continue to work.- Returns:
- true if this reference was removed from the registry; false if it was not present
-
getOffset
Return the offset w.r.t. the offset reference, or zero when the offset is not defined.- Returns:
- the offset expressed in the relative quantity
-
getOffsetReference
Return the offset reference for the offset, or null when the offset reference is not defined.- Returns:
- the offset reference
-
getId
- Specified by:
getIdin interfaceorg.djutils.base.Identifiable
-
getName
- Returns:
- description of this reference point
-
hashCode
public int hashCode() -
equals
-
toString
-