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 itself
Q - 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 Details

    • REFERENCES

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

      public Q 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

      public R getOffsetReference()
      Return the offset reference for the offset, or null when the offset reference is not defined.
      Returns:
      the offset reference
    • getId

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

      public String getName()
      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