Package org.djunits.unit
Class AbstractUnit<U extends Unit<U,Q>,Q extends Quantity<Q>>
java.lang.Object
org.djunits.unit.AbstractUnit<U,Q>
- Type Parameters:
U- the unit typeQ- the quantity type belonging to this unit
- All Implemented Interfaces:
Unit<U,Q>
- Direct Known Subclasses:
AbsorbedDose.Unit,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,SolidAngle.Unit,Speed.Unit,Temperature.Unit,Torque.Unit,Unitless,Volume.Unit,VolumetricObjectDensity.Unit
public abstract class AbstractUnit<U extends Unit<U,Q>,Q extends Quantity<Q>>
extends Object
implements Unit<U,Q>
The AbstractUnit is the parent class of all units, and encodes the common behavior of the units. All units are internally
stored relative to a standard unit with conversion factor. This means that e.g., a meter is stored with conversion
factor 1.0, and kilometer is stored with a conversion factor 1000.0. This means that if we want to express a length meter in
kilometers, we have to divide by the conversion factor.
The conversion to and from the base unit is left to a Scale. Many scales are linear (e.g., converting dm, cm, and mm to meters), but there are also non-linear scales such as the percentage for an angle, where 90 degrees equals an infinite percentage. 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
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractUnit(String textualAbbreviation, String displayAbbreviation, String name, Scale scale, UnitSystem unitSystem) Create a new unit, with textual abbreviation(s) and a display abbreviation.AbstractUnit(String textualAbbreviation, String name, Scale scale, UnitSystem unitSystem) Create a new unit, where the textual abbreviation is the same as the display abbreviation. -
Method Summary
Modifier and TypeMethodDescriptionderiveUnit(String textualAbbreviation, String name, double scaleFactor, UnitSystem unitSystem) Return a linearly scaled derived unit for this unit, where the textual abbreviation is the same as the display abbreviation.abstract UderiveUnit(String textualAbbreviation, String displayAbbreviation, String name, double scaleFactor, UnitSystem unitSystem) Return a linearly scaled derived unit for this unit, with textual abbreviation(s) and a display abbreviation.booleangenerateSiPrefixes(boolean kilo, boolean perUnit) Generate and register the units with all SI-prefixes.Retrieve the display abbreviation, and apply localization when possible.getId()Return the id, which is the main abbreviation, of the unit.getName()Return the name, which is the main written explanation, of the unit.getScale()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.inthashCode()setSiPrefix(String prefix) Set the SI-prefix so it can be localized if necessary.setSiPrefix(SIPrefix siPrefix) Set the SI-prefix so it can be localized if necessary.setSiPrefixKilo(String prefix) Set the SI-prefix so it can be localized if necessary.setSiPrefixPer(String prefix) Set the SI-prefix so it can be localized if necessary.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.unit.Unit
fromBaseValue, getBaseUnit, ofSi, quantityInUnit, siUnit, toBaseValue
-
Constructor Details
-
AbstractUnit
Create a new unit, where the textual abbreviation is the same as the display abbreviation.- Parameters:
textualAbbreviation- the textual abbreviation of the unit, which also serves as the idname- the full name of the unitscale- the scale to use to convert between this unit and the standard (e.g., SI, BASE) unitunitSystem- unit system, e.g. SI or Imperial
-
AbstractUnit
public AbstractUnit(String textualAbbreviation, String displayAbbreviation, String name, Scale scale, UnitSystem unitSystem) Create a new unit, with textual abbreviation(s) and a display abbreviation.- Parameters:
textualAbbreviation- the textual abbreviation of the unit, which also serves as the iddisplayAbbreviation- the display abbreviation of the unitname- the full name of the unitscale- the scale to use to convert between this unit and the standard (e.g., SI, BASE) unitunitSystem- unit system, e.g. SI or Imperial
-
-
Method Details
-
generateSiPrefixes
Generate and register the units with all SI-prefixes.- Parameters:
kilo- whether the base unit already has a "kilo" in its abbreviation/name, such as the kilogramperUnit- whether it is a "per unit" such as "per meter"- Returns:
- the unit for method chaining
-
deriveUnit
public U deriveUnit(String textualAbbreviation, String name, double scaleFactor, UnitSystem unitSystem) Return a linearly scaled derived unit for this unit, where the textual abbreviation is the same as the display abbreviation.- Parameters:
textualAbbreviation- the textual abbreviation of the unit, which doubles as the idname- the full name of the unitscaleFactor- the (linear) scale factor to multiply with the current (linear) scale factorunitSystem- unit system, e.g. SI or Imperial- Returns:
- a derived unit for this unit
-
deriveUnit
public abstract U deriveUnit(String textualAbbreviation, String displayAbbreviation, String name, double scaleFactor, UnitSystem unitSystem) Return a linearly scaled derived unit for this unit, with textual abbreviation(s) and a display abbreviation.- Parameters:
textualAbbreviation- the textual abbreviation of the unit, which doubles as the iddisplayAbbreviation- the display abbreviation of the unitname- the full name of the unitscaleFactor- the (linear) scale factor to multiply with the current (linear) scale factorunitSystem- unit system, e.g. SI or Imperial- Returns:
- a derived unit for this unit
-
getId
Description copied from interface:UnitReturn the id, which is the main abbreviation, of the unit. -
getStoredTextualAbbreviation
Description copied from interface:UnitRetrieve the stored textual abbreviation, which doubles as the id of the unit. Do not apply localization. -
getTextualAbbreviation
Description copied from interface:UnitRetrieve the textual abbreviation, which doubles as the id of the unit. Apply localization when possible. -
getStoredDisplayAbbreviation
Description copied from interface:UnitRetrieve the stored display abbreviation, without localization. -
getDisplayAbbreviation
Description copied from interface:UnitRetrieve the display abbreviation, and apply localization when possible. -
getStoredName
Description copied from interface:UnitReturn the name, which is the main written explanation, of the unit. Do not apply localization. -
getName
Description copied from interface:UnitReturn the name, which is the main written explanation, of the unit. Apply localization when possible. -
getScale
Description copied from interface:UnitRetrieve the scale of this unit. -
getUnitSystem
Description copied from interface:UnitRetrieve the unit system of this unit. -
setSiPrefix
Description copied from interface:UnitSet the SI-prefix so it can be localized if necessary. -
setSiPrefix
Description copied from interface:UnitSet the SI-prefix so it can be localized if necessary. This method does NOT handle kilo-prefixes. -
setSiPrefixKilo
Description copied from interface:UnitSet the SI-prefix so it can be localized if necessary. This method handles kilo-prefixes. -
setSiPrefixPer
Description copied from interface:UnitSet the SI-prefix so it can be localized if necessary. This method handles per-unit prefixes. -
getSiPrefix
Description copied from interface:UnitReturn the SI-prefix so it can be localized if necessary. -
hashCode
public int hashCode() -
equals
-
toString
-