Interface UnitInterface<U extends UnitInterface<U,Q>,Q extends Quantity<Q,U>>

Type Parameters:
U - the unit type
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<U extends UnitInterface<U,Q>,Q extends Quantity<Q,U>>
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 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

      U 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
    • setSiPrefix

      U setSiPrefix(SIPrefix siPrefix)
      Set the SI-prefix so it can be localized if necessary.
      Parameters:
      siPrefix - the SI-prefix to set
      Returns:
      the unit for method chaining
    • setSiPrefix

      U setSiPrefix(String prefix)
      Set the SI-prefix so it can be localized if necessary. This method does NOT handle kilo-prefixes.
      Parameters:
      prefix - the string-representation of the SI-prefix to set
      Returns:
      the unit for method chaining
    • setSiPrefixKilo

      U setSiPrefixKilo(String prefix)
      Set the SI-prefix so it can be localized if necessary. This method handles kilo-prefixes.
      Parameters:
      prefix - the string-representation of the SI-prefix to set
      Returns:
      the unit for method chaining
    • setSiPrefixPer

      U setSiPrefixPer(String prefix)
      Set the SI-prefix so it can be localized if necessary. This method handles per-unit prefixes.
      Parameters:
      prefix - the string-representation of the SI-prefix to set
      Returns:
      the unit for method chaining
    • 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

      Q ofSi(double si)
      Return an SI-quantity for this unit with a value.
      Parameters:
      si - the value in SI or BASE units
      Returns:
      an SI-quantity for this unit with the given si-value
    • 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