Class Density

All Implemented Interfaces:
Serializable, Comparable<Density>, Additive<Density>, Scalable<Density>, Value<Density>

public class Density extends Quantity<Density>
Density is mass per unit volume of a substance, measured in kilograms per cubic meter (kg/m3).

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:
  • Field Details

    • ZERO

      public static final Density ZERO
      Constant with value zero.
    • ONE

      public static final Density ONE
      Constant with value one.
    • NaN

      public static final Density NaN
      Constant with value NaN.
    • POSITIVE_INFINITY

      public static final Density POSITIVE_INFINITY
      Constant with value POSITIVE_INFINITY.
    • NEGATIVE_INFINITY

      public static final Density NEGATIVE_INFINITY
      Constant with value NEGATIVE_INFINITY.
    • POS_MAXVALUE

      public static final Density POS_MAXVALUE
      Constant with value MAX_VALUE.
    • NEG_MAXVALUE

      public static final Density NEG_MAXVALUE
      Constant with value -MAX_VALUE.
  • Constructor Details

    • Density

      public Density(double value, Density.Unit displayUnit, boolean useSi)
      Instantiate a Density quantity with an SI or base value and a display unit.
      Parameters:
      value - the quantity value expressed in the SI or base unit
      displayUnit - the display unit to use
      useSi - use SI value when true, use value in unit when false
    • Density

      public Density(double valueInUnit, Density.Unit unit)
      Instantiate a Density quantity expressed in the given unit.
      Parameters:
      valueInUnit - the quantity value expressed in the given unit
      unit - the unit of the value, also acts as the display unit
  • Method Details

    • ofSi

      public static Density ofSi(double si)
      Return a Density instance based on an SI value.
      Parameters:
      si - the si value
      Returns:
      the Density instance based on an SI value
    • ofSi

      public static Density ofSi(double siValue, Density.Unit displayUnit)
      Instantiate a Density quantity with an SI or base value and a display unit.
      Parameters:
      siValue - the quantity value expressed in the SI or base unit
      displayUnit - the display unit to use
      Returns:
      the Density instance based on an SI value with the given display unit
    • instantiateSi

      public Density instantiateSi(double siValue, UnitInterface<Density> displayUnit)
      Description copied from class: Quantity
      Instantiate a quantity with an SI or base value, and a display unit.
      Specified by:
      instantiateSi in class Quantity<Density>
      Parameters:
      siValue - the value expressed in the base (SI) unit
      displayUnit - the display unit to use for the quantity
      Returns:
      a quantity with the given SI or base value, and the given display unit
    • valueOf

      public static Density valueOf(String text)
      Returns a Density representation of a 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.
      Parameters:
      text - the textual representation to parse into a Density
      Returns:
      the Scalar representation of the value in its unit
      Throws:
      IllegalArgumentException - when the text cannot be parsed
      NullPointerException - when the text argument is null
    • of

      public static Density of(double valueInUnit, Density.Unit unit)
      Returns a Density based on a value expressed in the unit.
      Parameters:
      valueInUnit - the value, expressed in the given unit
      unit - the unit of the value, also acts as the display unit
      Returns:
      ab Density representation of the value in its unit
    • of

      public static Density of(double valueInUnit, String unitString)
      Returns a Density based on a value and the textual representation of the unit, which can be localized.
      Parameters:
      valueInUnit - the value, expressed in the unit as given by unitString
      unitString - the textual representation of the unit
      Returns:
      the Scalar 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
    • getDisplayUnit

      public Density.Unit getDisplayUnit()
      Description copied from interface: Value
      Retrieve the unit of this Value.
      Specified by:
      getDisplayUnit in interface Value<Density>
      Overrides:
      getDisplayUnit in class Quantity<Density>
      Returns:
      the unit of this Value
    • divide

      public Dimensionless divide(Density v)
      Calculate the division of Density and Density, which results in a Dimensionless quantity.
      Parameters:
      v - quantity
      Returns:
      quantity as a division of Density and Density
    • multiply

      public Mass multiply(Volume v)
      Calculate the multiplication of Density and Volume, which results in a Mass scalar.
      Parameters:
      v - scalar
      Returns:
      scalar as a multiplication of Density and Volume
    • multiply

      public FlowMass multiply(FlowVolume v)
      Calculate the multiplication of Density and FlowVolume, which results in a FlowMass scalar.
      Parameters:
      v - scalar
      Returns:
      scalar as a multiplication of Density and FlowVolume