Class AbsoluteQuantity<A extends AbsoluteQuantity<A,Q,U,R>,Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>,R extends AbstractReference<R,Q>>

java.lang.Object
java.lang.Number
org.djunits.quantity.def.AbsoluteQuantity<A,Q,U,R>
Type Parameters:
A - the absolute quantity type
Q - the relative quantity type
U - the (shared) unit type
R - the reference type to use for the absolute quantity
All Implemented Interfaces:
Serializable, Comparable<A>, Value<U,A>
Direct Known Subclasses:
Direction, Position, Temperature, Time

public abstract class AbsoluteQuantity<A extends AbsoluteQuantity<A,Q,U,R>,Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>,R extends AbstractReference<R,Q>> extends Number implements Value<U,A>, Comparable<A>
AbsoluteQuantity is an abstract class that stores the basic information about a absolute quantity. An absolute quantity wraps a relative Quantity and has a reference point that acts as an origin or zero point.

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
    AbsoluteQuantity(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.
    final int
    compareTo(A other)
    double
     
    boolean
    eq(A other)
    Test if this Quantity is equal to another Quantity.
    boolean
    eq0()
    Test if this Quantity is equal to 0.0.
    boolean
     
    float
     
    format(double d)
    Format a string according to the current locale and the standard (minimized) format, such as "3.14" or "300.0".
    format(double d, String format)
    Format a string according to the current locale and the provided format string.
    boolean
    ge(A other)
    Test if this Quantity is greater than or equal to another Quantity.
    boolean
    ge0()
    Test if this Quantity is greater than or equal to 0.0.
    Retrieve the unit of this Value.
    final double
    Retrieve the relative quantity value in the current display unit.
    final double
    getInUnit(U 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).
    boolean
    gt(A other)
    Test if this Quantity is greater than another Quantity.
    boolean
    gt0()
    Test if this Quantity is greater than 0.0.
    int
     
    abstract A
    instantiate(Q quantity, R reference)
    Instantiate an absolute quantity with a quantity and a reference.
    static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>>
    A
    interpolate(A zero, A one, double ratio)
    Interpolate between two absolute quantities.
    int
     
    boolean
    Indicate whether this is a Relative Value.
    boolean
    le(A other)
    Test if this Quantity is less than or equal to another Quantity.
    boolean
    le0()
    Test if this Quantity is less than or equal to 0.0.
    long
     
    boolean
    lt(A other)
    Test if this Quantity is less than another Quantity.
    boolean
    lt0()
    Test if this Quantity is less than 0.0.
    static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>>
    A
    max(A quantity1, A... quantities)
    Return the maximum value of one or more quantities.
    static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>>
    A
    mean(A quantity1, A... quantities)
    Return the mean of one or more quantities.
    static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>>
    A
    min(A quantity1, A... quantities)
    Return the minimum value of one or more quantities.
    boolean
    ne(A other)
    Test if this Quantity is not equal to another Quantity.
    boolean
    ne0()
    Test if this Quantity is not equal to 0.0.
    static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>>
    A
    of(double value, 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(U 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.
    static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>>
    A
    sum(A quantity1, A... quantities)
    Return the sum of one or more quantities.
    Concise display description of this value, without the engineering formatting, so without trailing zeroes.
    toDisplayString(U displayUnit)
    Concise display description of this value, without the engineering formatting, so without trailing zeroes.
    Concise description of this value.
    toString(boolean verbose, boolean withUnit)
    Somewhat verbose description of this value with optional type and unit information.
    toString(U displayUnit)
    Somewhat verbose description of this value with the values expressed in the specified unit.
    toString(U displayUnit, boolean verbose, boolean withUnit)
    Somewhat verbose description of this value with the values expressed in the specified unit.
    Format this DoubleScalar in SI unit using prefixes when possible.
    toStringSIPrefixed(int smallestPower, int biggestPower)
    Format this DoubleScalar in SI unit using prefixes when possible and within the specified size range.
    Concise textual representation of this value, without the engineering formatting, so without trailing zeroes.
    toTextualString(U displayUnit)
    Concise textual representation of this value, without the engineering formatting, so without trailing zeroes.
    static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, 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.Number

    byteValue, shortValue

    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

    • AbsoluteQuantity

      public AbsoluteQuantity(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 U getDisplayUnit()
      Description copied from interface: Value
      Retrieve the unit of this Value.
      Specified by:
      getDisplayUnit in interface Value<A extends AbsoluteQuantity<A,Q,U,R>,Q extends Quantity<Q,U>>
      Returns:
      the unit of this Value
    • setDisplayUnit

      public A setDisplayUnit(U 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 AbsoluteQuantity<A,Q,U,R>,Q extends Quantity<Q,U>>
      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(U 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
    • doubleValue

      public double doubleValue()
      Specified by:
      doubleValue in class Number
    • intValue

      public int intValue()
      Specified by:
      intValue in class Number
    • longValue

      public long longValue()
      Specified by:
      longValue in class Number
    • floatValue

      public float floatValue()
      Specified by:
      floatValue in class Number
    • lt

      public boolean lt(A other)
      Test if this Quantity is less than another Quantity.
      Parameters:
      other - the right hand side operand of the comparison
      Returns:
      true if this is less than o; false otherwise
      Throws:
      IllegalArgumentException - when the two absolute quantities have a different reference point
    • le

      public boolean le(A other)
      Test if this Quantity is less than or equal to another Quantity.
      Parameters:
      other - the right hand side operand of the comparison
      Returns:
      true if this is less than or equal to o; false otherwise
      Throws:
      IllegalArgumentException - when the two absolute quantities have a different reference point
    • gt

      public boolean gt(A other)
      Test if this Quantity is greater than another Quantity.
      Parameters:
      other - the right hand side operand of the comparison
      Returns:
      true if this is greater than o; false otherwise
      Throws:
      IllegalArgumentException - when the two absolute quantities have a different reference point
    • ge

      public boolean ge(A other)
      Test if this Quantity is greater than or equal to another Quantity.
      Parameters:
      other - the right hand side operand of the comparison
      Returns:
      true if this is greater than or equal to o; false otherwise
      Throws:
      IllegalArgumentException - when the two absolute quantities have a different reference point
    • eq

      public boolean eq(A other)
      Test if this Quantity is equal to another Quantity.
      Parameters:
      other - the right hand side operand of the comparison
      Returns:
      true if this is equal to o; false otherwise
      Throws:
      IllegalArgumentException - when the two absolute quantities have a different reference point
    • ne

      public boolean ne(A other)
      Test if this Quantity is not equal to another Quantity.
      Parameters:
      other - the right hand side operand of the comparison
      Returns:
      true if this is not equal to o; false otherwise
      Throws:
      IllegalArgumentException - when the two absolute quantities have a different reference point
    • lt0

      public boolean lt0()
      Test if this Quantity is less than 0.0.
      Returns:
      true if this is less than 0.0; false if this is not less than 0.0
    • le0

      public boolean le0()
      Test if this Quantity is less than or equal to 0.0.
      Returns:
      true if this is less than or equal to 0.0; false if this is not less than or equal to 0.0
    • gt0

      public boolean gt0()
      Test if this Quantity is greater than 0.0.
      Returns:
      true if this is greater than 0.0; false if this is not greater than 0.0
    • ge0

      public boolean ge0()
      Test if this Quantity is greater than or equal to 0.0.
      Returns:
      true if this is greater than or equal to 0.0; false if this is not greater than or equal to 0.0
    • eq0

      public boolean eq0()
      Test if this Quantity is equal to 0.0.
      Returns:
      true if this is equal to 0.0; false if this is not equal to 0.0
    • ne0

      public boolean ne0()
      Test if this Quantity is not equal to 0.0.
      Returns:
      true if this is not equal to 0.0; false if this is equal to 0.0
    • compareTo

      public final int compareTo(A other)
      Specified by:
      compareTo in interface Comparable<A extends AbsoluteQuantity<A,Q,U,R>>
      Throws:
      IllegalArgumentException - when the two absolute quantities have a different reference point
    • 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 AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, 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
      U - the unit 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 AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>> A of(double value, 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
      U - the unit type
      R - the reference type to use for the absolute quantity
      Parameters:
      value - the value to use
      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
    • format

      public String format(double d)
      Format a string according to the current locale and the standard (minimized) format, such as "3.14" or "300.0".
      Parameters:
      d - the number to format
      Returns:
      the formatted number using the current Locale
    • format

      public String format(double d, String format)
      Format a string according to the current locale and the provided format string.
      Parameters:
      d - the number to format
      format - the formatting string to use for the number
      Returns:
      the formatted number using the current Locale and the format string
    • toString

      public String toString()
      Concise description of this value.
      Specified by:
      toString in interface Value<A extends AbsoluteQuantity<A,Q,U,R>,Q extends Quantity<Q,U>>
      Overrides:
      toString in class Object
      Returns:
      a String with the value, non-verbose, with the unit attached.
    • toString

      public String toString(U displayUnit)
      Somewhat verbose description of this value with the values expressed in the specified unit.
      Specified by:
      toString in interface Value<A extends AbsoluteQuantity<A,Q,U,R>,Q extends Quantity<Q,U>>
      Parameters:
      displayUnit - the unit into which the values are converted for display
      Returns:
      printable string with the value contents expressed in the specified unit
    • toString

      public String toString(boolean verbose, boolean withUnit)
      Somewhat verbose description of this value with optional type and unit information.
      Parameters:
      verbose - if true; include type info; if false; exclude type info
      withUnit - if true; include the unit; of false; exclude the unit
      Returns:
      printable string with the value contents
    • toString

      public String toString(U displayUnit, boolean verbose, boolean withUnit)
      Somewhat verbose description of this value with the values expressed in the specified unit.
      Parameters:
      displayUnit - the unit into which the values are converted for display
      verbose - if true; include type info; if false; exclude type info
      withUnit - if true; include the unit; of false; exclude the unit
      Returns:
      printable string with the value contents
    • toStringSIPrefixed

      public String toStringSIPrefixed()
      Format this DoubleScalar in SI unit using prefixes when possible. If the value is too small or too large, e-notation and the plain SI unit are used.
      Returns:
      formatted value of this DoubleScalar
    • toStringSIPrefixed

      public String toStringSIPrefixed(int smallestPower, int biggestPower)
      Format this DoubleScalar in SI unit using prefixes when possible and within the specified size range. If the value is too small or too large, e-notation and the plain SI unit are used.
      Parameters:
      smallestPower - the smallest exponent value that will be written using an SI prefix
      biggestPower - the largest exponent value that will be written using an SI prefix
      Returns:
      formatted value of this DoubleScalar
    • toTextualString

      public String toTextualString()
      Concise textual representation of this value, without the engineering formatting, so without trailing zeroes. A space is added between the number and the unit.
      Returns:
      a String with the value with the default textual representation of the unit attached.
    • toTextualString

      public String toTextualString(U displayUnit)
      Concise textual representation of this value, without the engineering formatting, so without trailing zeroes. A space is added between the number and the unit.
      Parameters:
      displayUnit - the display unit for the value
      Returns:
      a String with the value with the default textual representation of the provided unit attached.
    • toDisplayString

      public String toDisplayString()
      Concise display description of this value, without the engineering formatting, so without trailing zeroes. A space is added between the number and the unit.
      Returns:
      a String with the value with the default display representation of the unit attached.
    • toDisplayString

      public String toDisplayString(U displayUnit)
      Concise display description of this value, without the engineering formatting, so without trailing zeroes. A space is added between the number and the unit.
      Parameters:
      displayUnit - the display unit for the value
      Returns:
      a String with the value with the default display representation of the provided unit attached.
    • 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 AbsoluteQuantity<A,Q,U,R>,Q extends Quantity<Q,U>>
      Returns:
      whether this is a Relative Value
    • interpolate

      public static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>> A interpolate(A zero, A one, double ratio)
      Interpolate between two absolute quantities. Note that the first quantities does not have to be smaller than the second.
      Type Parameters:
      A - the absolute quantity type
      Q - the relative quantity type
      U - the unit type
      R - the reference type to use for the absolute quantity
      Parameters:
      zero - the quantity at a ratio of zero
      one - the quantity at a ratio of one
      ratio - the ratio between 0 and 1, inclusive
      Returns:
      a Quantity at the given ratio between 0 and 1
      Throws:
      IllegalArgumentException - when absolute quantities have a different reference point
    • max

      @SafeVarargs public static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>> A max(A quantity1, A... quantities)
      Return the maximum value of one or more quantities.
      Type Parameters:
      A - the absolute quantity type
      Q - the relative quantity type
      U - the unit type
      R - the reference type to use for the absolute quantity
      Parameters:
      quantity1 - the first quantity
      quantities - the other quantities
      Returns:
      the maximum value of more than two quantities
      Throws:
      IllegalArgumentException - when absolute quantities have a different reference point
    • min

      @SafeVarargs public static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>> A min(A quantity1, A... quantities)
      Return the minimum value of one or more quantities.
      Type Parameters:
      A - the absolute quantity type
      Q - the relative quantity type
      U - the unit type
      R - the reference type to use for the absolute quantity
      Parameters:
      quantity1 - the first quantity
      quantities - the other quantities
      Returns:
      the minimum value of more than two quantities
      Throws:
      IllegalArgumentException - when absolute quantities have a different reference point
    • sum

      @SafeVarargs public static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>> A sum(A quantity1, A... quantities)
      Return the sum of one or more quantities.
      Type Parameters:
      A - the absolute quantity type
      Q - the relative quantity type
      U - the unit type
      R - the reference type to use for the absolute quantity
      Parameters:
      quantity1 - the first quantity
      quantities - the other quantities
      Returns:
      the sum of the quantities
      Throws:
      IllegalArgumentException - when absolute quantities have a different reference point
    • mean

      @SafeVarargs public static <A extends AbsoluteQuantity<A, Q, U, R>, Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>, R extends AbstractReference<R, Q>> A mean(A quantity1, A... quantities)
      Return the mean of one or more quantities.
      Type Parameters:
      A - the absolute quantity type
      Q - the relative quantity type
      U - the unit type
      R - the reference type to use for the absolute quantity
      Parameters:
      quantity1 - the first quantity
      quantities - the other quantities
      Returns:
      the mean of the quantities
      Throws:
      IllegalArgumentException - when absolute quantities have a different reference point