Package org.djunits.quantity.def
Class AbstractReference<R extends AbstractReference<R,A,Q>,A extends AbsQuantity<A,Q,R>,Q extends Quantity<Q>>
java.lang.Object
org.djunits.quantity.def.AbstractReference<R,A,Q>
- Type Parameters:
R- the reference type itselfA- the absolute quantity type for generics instantiationQ- the relative quantity type for the offset
- All Implemented Interfaces:
Reference<R,,A, Q> org.djutils.base.Identifiable
- Direct Known Subclasses:
Direction.Reference,Position.Reference,Temperature.Reference,Time.Reference
public abstract class AbstractReference<R extends AbstractReference<R,A,Q>,A extends AbsQuantity<A,Q,R>,Q extends Quantity<Q>>
extends Object
implements Reference<R,A,Q>
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
Fields -
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 Reference<R,?, ?>>
RFetch a reference by class and id.getId()getName()Return the description of this reference point.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.Return a safe copy of the static reference map for this Reference subclass.inthashCode()abstract Ainstantiate(Q quantity) Return a strongly typed absolute quantity belonging to this reference.Get or create the inner map for a specific Reference subclass.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.- Specified by:
getReferenceMapin interfaceReference<R extends AbstractReference<R,A, Q>, A extends AbsQuantity<A, Q, R>, Q extends Quantity<Q>> - 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.- Specified by:
unregisterin interfaceReference<R extends AbstractReference<R,A, Q>, A extends AbsQuantity<A, Q, R>, Q extends Quantity<Q>> - Returns:
- true if this reference was removed from the registry; false if it was not present
-
instantiate
Return a strongly typed absolute quantity belonging to this reference.- Specified by:
instantiatein interfaceReference<R extends AbstractReference<R,A, Q>, A extends AbsQuantity<A, Q, R>, Q extends Quantity<Q>> - Parameters:
quantity- the relative quantity that indicates the 'distance' to this reference point- Returns:
- a strongly typed absolute quantity belonging to this reference
-
getOffset
Return the offset w.r.t. the offset reference, or zero when the offset is not defined. -
getOffsetReference
Return the offset reference for the offset, or null when the offset reference is not defined.- Specified by:
getOffsetReferencein interfaceReference<R extends AbstractReference<R,A, Q>, A extends AbsQuantity<A, Q, R>, Q extends Quantity<Q>> - Returns:
- the offset reference
-
getId
- Specified by:
getIdin interfaceorg.djutils.base.Identifiable
-
getName
Description copied from interface:ReferenceReturn the description of this reference point. -
hashCode
public int hashCode() -
equals
-
toString
-