Class AbsBasic<A extends AbsBasic<A,Q,R>,Q extends Quantity<Q>,R extends Reference<R,A,Q>>

java.lang.Object
org.djunits.quantity.def.AbsBasic<A,Q,R>
Type Parameters:
A - the absolute quantity type
Q - the relative quantity type
R - the reference type to use for the absolute quantity
All Implemented Interfaces:
Serializable, Value<A,Q>
Direct Known Subclasses:
AbsQuantity, Direction

public abstract class AbsBasic<A extends AbsBasic<A,Q,R>,Q extends Quantity<Q>,R extends Reference<R,A,Q>> extends Object implements Value<A,Q>
AbsBasic stores the basic information about a absolute quantity and implements the basic operations that hold for all absolute quantities. An absolute quantity wraps a relative Quantity and has a reference point that acts as an origin or zero point. Note that the absolute quantity Direction directly extends AbsBasic because of its circular scale. The other absolute quantities Position, Temperature and Time extends AbsQuantity that extends this class and implements comparators as well.

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
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbsBasic(Q quantity, R reference)
    Instantiate an absolute quantity with a quantity and a reference.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract A
    add(Q other)
    Add a relative quantity to this absolute quantity, resulting in a new absolute quantity containing the sum.
    boolean
     
    Concise description of this quantity.
    String representation of this quantity after applying the format.
    format(Unit<?,Q> targetUnit)
    String representation of this quantity, expressed in the specified unit.
    Unit<?,Q>
    Retrieve the unit of this Value.
    final double
    Retrieve the relative quantity value in the current display unit.
    final double
    getInUnit(Unit<?,Q> targetUnit)
    Retrieve the relative quantity value converted into some specified unit.
    Return the "pretty" and localized name of the quantity.
    Return the (relative) quantity relative to the reference.
    Return the reference point (zero or origin).
    int
     
    abstract A
    instantiate(Q quantity, R reference)
    Instantiate an absolute quantity with a quantity and a reference.
    boolean
    Indicate whether this is a Relative Value.
    static <A extends AbsBasic<A, Q, R>, Q extends Quantity<Q>, R extends Reference<R, A, Q>>
    A
    of(double valueInUnit, String unitString, A example, R reference)
    Returns an absolute quantity based on a value and the textual representation of the unit, which can be localized.
    relativeTo(R otherReference)
    Return the quantity relative to another reference point.
    setDisplayUnit(Unit<?,Q> newUnit)
    Set a new display unit for the value.
    double
    si()
    Return the SI value of the quantity.
    Return the SI unit of this quantity.
    abstract Q
    subtract(A other)
    Subtract two absolute quantities from each other, resulting in the corresponding relative quantity.
    abstract A
    subtract(Q other)
    Subtract a relative quantity from this absolute quantity, resulting in a new absolute quantity containing the difference.
    Description of this quantity with default formatting.
    static <A extends AbsBasic<A, Q, R>, Q extends Quantity<Q>, R extends Reference<R, A, Q>>
    A
    valueOf(String text, A example, R reference)
    Returns an absolute quantity for the textual representation of a value with a unit.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.djunits.value.Value

    isAbsolute, setDisplayUnit
  • Constructor Details

    • AbsBasic

      public AbsBasic(Q quantity, R reference)
      Instantiate an absolute quantity with a quantity and a reference.
      Parameters:
      quantity - the relative quantity that indicates the 'distance' to the reference point
      reference - the reference point
  • Method Details

    • getDisplayUnit

      public Unit<?,Q> getDisplayUnit()
      Description copied from interface: Value
      Retrieve the unit of this Value.
      Specified by:
      getDisplayUnit in interface Value<A extends AbsBasic<A,Q,R>,Q extends Quantity<Q>>
      Returns:
      the unit of this Value
    • setDisplayUnit

      public A setDisplayUnit(Unit<?,Q> newUnit)
      Description copied from interface: Value
      Set a new display unit for the value. Internally, the value will not changed since it is stored in a base unit.
      Specified by:
      setDisplayUnit in interface Value<A extends AbsBasic<A,Q,R>,Q extends Quantity<Q>>
      Parameters:
      newUnit - the new display unit of this value
      Returns:
      'this' for fluent design
    • getInUnit

      public final double getInUnit()
      Retrieve the relative quantity value in the current display unit.
      Returns:
      the relative quantity value in the current display unit
    • getInUnit

      public final double getInUnit(Unit<?,Q> targetUnit)
      Retrieve the relative quantity value converted into some specified unit.
      Parameters:
      targetUnit - the unit to convert the relative quantity value into
      Returns:
      the value of the relative quantity in the target unit
    • getQuantity

      public Q getQuantity()
      Return the (relative) quantity relative to the reference.
      Returns:
      the (relative) quantity relative to the reference
    • getReference

      public R getReference()
      Return the reference point (zero or origin).
      Returns:
      the reference point
    • getName

      public String getName()
      Return the "pretty" and localized name of the quantity.
      Returns:
      the "pretty" and localized name of the quantity
    • siUnit

      public SIUnit siUnit()
      Return the SI unit of this quantity.
      Returns:
      the SI unit of this quantity
    • si

      public double si()
      Return the SI value of the quantity.
      Returns:
      the SI value of the quantity
    • instantiate

      public abstract A instantiate(Q quantity, R reference)
      Instantiate an absolute quantity with a quantity and a reference.
      Parameters:
      quantity - the relative quantity that indicates the 'distance' to the reference point
      reference - the reference point
      Returns:
      the absolute quantity with a quantity and a reference
    • hashCode

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

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

      public static <A extends AbsBasic<A, Q, R>, Q extends Quantity<Q>, R extends Reference<R, A, Q>> A valueOf(String text, A example, R reference)
      Returns an absolute quantity for the textual representation of a value with a unit. The String representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are allowed, but not required, between the value and the unit.
      Type Parameters:
      A - the absolute quantity type
      Q - the relative quantity type
      R - the reference type to use for the absolute quantity
      Parameters:
      text - the textual representation to parse into the quantity
      example - an example instance to deliver
      reference - the reference point
      Returns:
      the absolute quantity representation of the value with its unit
      Throws:
      IllegalArgumentException - when the text cannot be parsed
      NullPointerException - when the text argument is null
    • of

      public static <A extends AbsBasic<A, Q, R>, Q extends Quantity<Q>, R extends Reference<R, A, Q>> A of(double valueInUnit, String unitString, A example, R reference)
      Returns an absolute quantity based on a value and the textual representation of the unit, which can be localized.
      Type Parameters:
      A - the absolute quantity type
      Q - the relative quantity type
      R - the reference type to use for the absolute quantity
      Parameters:
      valueInUnit - the value, expressed in the unit as given by unitString
      unitString - the textual representation of the unit
      example - an absolute example instance to deliver
      reference - the reference point
      Returns:
      the absolute quantity representation of the value in its unit
      Throws:
      IllegalArgumentException - when the unit cannot be parsed or is incorrect
      NullPointerException - when the unitString argument is null
    • relativeTo

      public A relativeTo(R otherReference)
      Return the quantity relative to another reference point.
      Parameters:
      otherReference - the reference point to which it has to be defined relatively.
      Returns:
      the absolute quantity relative to the other reference point
      Throws:
      IllegalArgumentException - when there is no translation from the current reference point to the provided reference
    • toString

      public String toString()
      Description of this quantity with default formatting.
      Overrides:
      toString in class Object
      Returns:
      a String with the value of the quantity, with the unit attached.
    • format

      public String format()
      Concise description of this quantity.
      Specified by:
      format in interface Value<A extends AbsBasic<A,Q,R>,Q extends Quantity<Q>>
      Returns:
      a String with the value of the quantity, with the unit attached.
    • format

      public String format(QuantityFormat format)
      String representation of this quantity after applying the format.
      Parameters:
      format - the format to apply for the quantity
      Returns:
      a String representation of this quantity, formatted according to the given format
    • format

      public String format(Unit<?,Q> targetUnit)
      String representation of this quantity, expressed in the specified unit.
      Specified by:
      format in interface Value<A extends AbsBasic<A,Q,R>,Q extends Quantity<Q>>
      Parameters:
      targetUnit - the unit into which the quantity is converted for display
      Returns:
      printable string with the quantity value expressed in the specified unit
    • subtract

      public abstract Q subtract(A other)
      Subtract two absolute quantities from each other, resulting in the corresponding relative quantity. The unit of the resulting quantity will be the unit of 'this' absolute quantity. Quantity 'other' will be transformed to the reference point of this absolute quantity. If the reference points of this and other are different, and no transformations between the reference points exist, an exception will be thrown.
      Parameters:
      other - the absolute quantity to subtract
      Returns:
      the relative quantity as a result of the subtraction
      Throws:
      IllegalArgumentException - when the reference points are unequal and cannot be transformed to each other
    • add

      public abstract A add(Q other)
      Add a relative quantity to this absolute quantity, resulting in a new absolute quantity containing the sum. The new quantity will have the same reference point and unit as this absolute quantity.
      Parameters:
      other - the relative quantity to add
      Returns:
      the absolute quantity as a result of the addition
    • subtract

      public abstract A subtract(Q other)
      Subtract a relative quantity from this absolute quantity, resulting in a new absolute quantity containing the difference. The new quantity will have the same reference point and unit as this absolute quantity.
      Parameters:
      other - the relative quantity to subtract
      Returns:
      the absolute quantity as a result of the subtraction
    • isRelative

      public boolean isRelative()
      Description copied from interface: Value
      Indicate whether this is a Relative Value.
      Specified by:
      isRelative in interface Value<A extends AbsBasic<A,Q,R>,Q extends Quantity<Q>>
      Returns:
      whether this is a Relative Value