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 itself
A - the absolute quantity type for generics instantiation
Q - 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
    Modifier and Type
    Field
    Description
    protected static final Map<Class<?>,Map<String,Reference<?,?,?>>>
    Master registry: per concrete Reference subclass we keep a map of id to reference.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractReference(String id, String name, Q offset, R offsetReference)
    Define a new reference point for the absolute quantity.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    containsId(Class<?> referenceClass, String id)
    Check existence of id in a specific Reference subclass.
    boolean
     
    static <R extends Reference<R, ?, ?>>
    R
    get(Class<R> referenceClass, String id)
    Fetch a reference by class and id.
     
    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.
    int
     
    abstract A
    instantiate(Q quantity)
    Return a strongly typed absolute quantity belonging to this reference.
    protected static Map<String,Reference<?,?,?>>
    mapFor(Class<?> referenceClass)
    Get or create the inner map for a specific Reference subclass.
    static Map<String,Reference<?,?,?>>
    snapshotMap(Class<?> referenceClass)
    Return a safe copy (snapshot) of the registry for a Reference subclass.
     
    boolean
    Instance-level unregister; removes this reference from the per-class registry.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • REFERENCES

      protected static final Map<Class<?>,Map<String,Reference<?,?,?>>> 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

      public AbstractReference(String id, String name, Q offset, R offsetReference)
      Define a new reference point for the absolute quantity. Prevent duplicate registration of the same id within the same Reference subclass.
      Parameters:
      id - the id
      name - the name or explanation
      offset - the offset w.r.t. the offsetReference, should be ZERO when offsetReference is null
      offsetReference - 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

      protected static Map<String,Reference<?,?,?>> mapFor(Class<?> referenceClass)
      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

      public static <R extends Reference<R, ?, ?>> R get(Class<R> referenceClass, String id)
      Fetch a reference by class and id. Returns null when not found.
      Type Parameters:
      R - the reference subclass type
      Parameters:
      referenceClass - the concrete Reference subclass
      id - the id
      Returns:
      the reference instance or null
    • containsId

      public static boolean containsId(Class<?> referenceClass, String id)
      Check existence of id in a specific Reference subclass.
      Parameters:
      referenceClass - the reference subclass to check
      id - the id to check
      Returns:
      whether the id exists for the Reference subclass
    • snapshotMap

      public static Map<String,Reference<?,?,?>> snapshotMap(Class<?> referenceClass)
      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

      public Map<String,Reference<?,?,?>> getReferenceMap()
      Return a safe copy of the static reference map for this Reference subclass.
      Specified by:
      getReferenceMap in interface Reference<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:
      unregister in interface Reference<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

      public abstract A instantiate(Q quantity)
      Return a strongly typed absolute quantity belonging to this reference.
      Specified by:
      instantiate in interface Reference<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

      public Q getOffset()
      Return the offset w.r.t. the offset reference, or zero when the offset is not defined.
      Specified by:
      getOffset in interface Reference<R extends AbstractReference<R,A,Q>,A extends AbsQuantity<A,Q,R>,Q extends Quantity<Q>>
      Returns:
      the offset expressed in the relative quantity
    • getOffsetReference

      public R getOffsetReference()
      Return the offset reference for the offset, or null when the offset reference is not defined.
      Specified by:
      getOffsetReference in interface Reference<R extends AbstractReference<R,A,Q>,A extends AbsQuantity<A,Q,R>,Q extends Quantity<Q>>
      Returns:
      the offset reference
    • getId

      public String getId()
      Specified by:
      getId in interface org.djutils.base.Identifiable
    • getName

      public String getName()
      Description copied from interface: Reference
      Return the description of this reference point.
      Specified by:
      getName in interface Reference<R extends AbstractReference<R,A,Q>,A extends AbsQuantity<A,Q,R>,Q extends Quantity<Q>>
      Returns:
      description of this reference point
    • hashCode

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

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

      public String toString()
      Overrides:
      toString in class Object