Interface UnitInterface<Q extends Quantity<Q>>

Type Parameters:
Q - the quantity type
All Known Implementing Classes:
AbsorbedDose.Unit, AbstractUnit, Acceleration.Unit, AmountOfSubstance.Unit, Angle.Unit, AngularAcceleration.Unit, AngularVelocity.Unit, Area.Unit, ArealObjectDensity.Unit, CatalyticActivity.Unit, Density.Unit, Duration.Unit, ElectricalCapacitance.Unit, ElectricalConductance.Unit, ElectricalInductance.Unit, ElectricalResistance.Unit, ElectricCharge.Unit, ElectricCurrent.Unit, ElectricPotential.Unit, Energy.Unit, EquivalentDose.Unit, FlowMass.Unit, FlowVolume.Unit, Force.Unit, Frequency.Unit, Illuminance.Unit, Length.Unit, LinearDensity.Unit, LinearObjectDensity.Unit, LuminousFlux.Unit, LuminousIntensity.Unit, MagneticFlux.Unit, MagneticFluxDensity.Unit, Mass.Unit, Momentum.Unit, Power.Unit, Pressure.Unit, RadioActivity.Unit, SIUnit, SolidAngle.Unit, Speed.Unit, Temperature.Unit, Torque.Unit, Unitless, Volume.Unit, VolumetricObjectDensity.Unit

public interface UnitInterface<Q extends Quantity<Q>>
UnitInterface defines the contract for a unit.

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
  • Method Summary

    Modifier and Type
    Method
    Description
    default double
    fromBaseValue(double si)
    Convert an SI value to a value expressed in this unit.
    Return the base unit for this unit.
    Retrieve the display abbreviation, and apply localization when possible.
    Return the id, which is the main abbreviation, of the unit.
    Return the name, which is the main written explanation, of the unit.
    Retrieve the scale of this unit.
    Return the SI-prefix so it can be localized if necessary.
    Retrieve the stored display abbreviation, without localization.
    Return the name, which is the main written explanation, of the unit.
    Retrieve the stored textual abbreviation, which doubles as the id of the unit.
    Retrieve the textual abbreviation, which doubles as the id of the unit.
    Retrieve the unit system of this unit.
    default Q
    ofSi(double si)
    Return a quantity for this unit with the given si-value and the SI-unit as the display unit.
    ofSi(double si, UnitInterface<Q> displayUnit)
    Return a quantity for this unit with the SI-value and the provided display unit.
    default Q
    quantityInUnit(double value)
    Return a quantity for this unit where the value is expressed in the current unit.
    Return the SI unit for this unit.
    default double
    toBaseValue(double value)
    Convert a value expressed in this unit to its base (SI) value.
  • Method Details

    • getId

      String getId()
      Return the id, which is the main abbreviation, of the unit.
      Returns:
      the id (main abbreviation) of the unit
    • getScale

      Scale getScale()
      Retrieve the scale of this unit.
      Returns:
      the scale of this unit
    • getUnitSystem

      UnitSystem getUnitSystem()
      Retrieve the unit system of this unit.
      Returns:
      unitSystem the unit system of this unit
    • siUnit

      SIUnit siUnit()
      Return the SI unit for this unit.
      Returns:
      the SI unit for this unit
    • toBaseValue

      default double toBaseValue(double value)
      Convert a value expressed in this unit to its base (SI) value.
      Parameters:
      value - the value expressed in this unit
      Returns:
      the value converted to its SI value
    • fromBaseValue

      default double fromBaseValue(double si)
      Convert an SI value to a value expressed in this unit.
      Parameters:
      si - the SI value
      Returns:
      the value converted to this unit
    • getBaseUnit

      UnitInterface<Q> getBaseUnit()
      Return the base unit for this unit.
      Returns:
      the base unit for this unit
    • getDisplayAbbreviation

      String getDisplayAbbreviation()
      Retrieve the display abbreviation, and apply localization when possible.
      Returns:
      the (localized) display abbreviation
    • getTextualAbbreviation

      String getTextualAbbreviation()
      Retrieve the textual abbreviation, which doubles as the id of the unit. Apply localization when possible.
      Returns:
      the (localized) textual abbreviation
    • getName

      String getName()
      Return the name, which is the main written explanation, of the unit. Apply localization when possible.
      Returns:
      the (localized) name of the unit
    • getStoredDisplayAbbreviation

      String getStoredDisplayAbbreviation()
      Retrieve the stored display abbreviation, without localization.
      Returns:
      the stored (non-localized) display abbreviation
    • getStoredTextualAbbreviation

      String getStoredTextualAbbreviation()
      Retrieve the stored textual abbreviation, which doubles as the id of the unit. Do not apply localization.
      Returns:
      the stored (non-localized) textual abbreviation
    • getStoredName

      String getStoredName()
      Return the name, which is the main written explanation, of the unit. Do not apply localization.
      Returns:
      the stored (non-localized) name of the unit
    • getSiPrefix

      SIPrefix getSiPrefix()
      Return the SI-prefix so it can be localized if necessary.
      Returns:
      the SI-prefix of this unit, or null when the unit has no SI-prefix
    • ofSi

      default Q ofSi(double si)
      Return a quantity for this unit with the given si-value and the SI-unit as the display unit.
      Parameters:
      si - the value in SI or BASE units
      Returns:
      a quantity for this unit with the given si-value and the SI-unit as the display unit
    • ofSi

      Q ofSi(double si, UnitInterface<Q> displayUnit)
      Return a quantity for this unit with the SI-value and the provided display unit.
      Parameters:
      si - the value in SI or BASE units
      displayUnit - the display unit to use
      Returns:
      a quantity for this unit with the SI-value and the provided display unit
    • quantityInUnit

      default Q quantityInUnit(double value)
      Return a quantity for this unit where the value is expressed in the current unit. When the unit is, e.g., kilometer, and the value is 10.0, the quantity returned will be 10 km, internally stored as 10,000 m with a displayUnit in km.
      Parameters:
      value - the value in the current unit
      Returns:
      a quantity with the value in the current unit