Package org.djunits.unit.si
Class SIUnit
java.lang.Object
org.djunits.unit.si.SIUnit
- All Implemented Interfaces:
UnitInterface<SIUnit,SIQuantity>
SIUnit stores the dimensionality of a unit using the SI standards. Angle (rad) and solid angle (sr) have been added to be
able to specify often used units regarding rotation.
Copyright (c) 2019-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License
- Author:
- Alexander Verbraeck
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SIUnitthe dimensionless SIUnit.static final intThe (currently) 9 dimensions we take into account: rad, sr, kg, m, s, A, K, mol, cd. -
Constructor Summary
ConstructorsConstructorDescriptionSIUnit(int[] dimensions) Create an immutable SIUnit instance based on a safe copy of a given dimensions specification.SIUnit(int angle, int solidAngle, int mass, int length, int time, int current, int temperature, int amountOfSubstance, int luminousIntensity) Create an immutable SIUnit instance based on a safe copy of a given dimensions specification. -
Method Summary
Modifier and TypeMethodDescriptionstatic SIUnitAdd two SIUnit and return the new SIUnit.booleanReturn the base unit for this unit.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()invert()Invert a set of SI dimensions; instead of m/s we get s/m.Subtract a set of SI dimensions from this SIUnit.static SIUnitParse a string representing SI dimensions to an SIUnit object.ofSi(double si) Return an SI-quantity for this unit with a value.Add a set of SI dimensions to this SIUnit.pow(int n) Raise a set of SI dimensions to the n-th power.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.String[]Returns a safe copy of the SI abbreviations (a public static final String[] is mutable).int[]Return a safe copy of the exponents of the SI dimensions in the order rad, sr, kg, m, s, A, K, mol, cd.siUnit()Return the SI unit for this unit.static SIUnitSubtract an SIUnit (dim2) from another SIUnit (dim1) and return the new SIUnit.toHTMLString(boolean divided, boolean separator) Return a string such as "kgm/s2" or or "kg.m.s-2" from this SIUnit.toString()toString(boolean divided, boolean separator) Return a string such as "kgm/s2" or "kg.m/s2" or "kg.m.s-2" from this SIUnit.toString(boolean divided, boolean separator, boolean power) Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIUnit.Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIUnit.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.unit.UnitInterface
fromBaseValue, quantityInUnit, toBaseValue
-
Field Details
-
NUMBER_DIMENSIONS
public static final int NUMBER_DIMENSIONSThe (currently) 9 dimensions we take into account: rad, sr, kg, m, s, A, K, mol, cd.- See Also:
-
DIMLESS
the dimensionless SIUnit.
-
-
Constructor Details
-
SIUnit
public SIUnit(int[] dimensions) Create an immutable SIUnit instance based on a safe copy of a given dimensions specification. As an example, speed is indicated as length = 1; time = -1 with the other dimensions equal to zero.- Parameters:
dimensions- The (currently) 9 dimensions of the SI unit we distinguish: 0: angle (rad), 1: solid angle (sr), 2: mass (kg), 3: length (m), 4: time (s), 5: current (A), 6: temperature (K), 7: amount of substance (mol), 8: luminous intensity (cd).
-
SIUnit
public SIUnit(int angle, int solidAngle, int mass, int length, int time, int current, int temperature, int amountOfSubstance, int luminousIntensity) Create an immutable SIUnit instance based on a safe copy of a given dimensions specification.- Parameters:
angle- dimension of the angle (rad)solidAngle- dimension of the solidAngle (sr)mass- dimension of the mass (kg)length- dimension of the length (m)time- dimension of the time (s)current- dimension of the current (A)temperature- dimension of the temperature (K)amountOfSubstance- dimension of the amount of substance (mol)luminousIntensity- dimension of the luminous intensity (cd)
-
-
Method Details
-
of
Parse a string representing SI dimensions to an SIUnit object. Example: SIUnit.of("kgm/s2") and SIUnit.of("kgms-2") will both be translated to a dimensions object with vector {0,0,1,1,-2,0,0,0,0}. It is allowed to use 0 or 1 for the dimensions. Having the same unit in the numerator and the denominator is not seen as a problem: the values are subtracted from each other, so m/m will have a length dimensionality of 0. Dimensions between -9 and 9 are allowed. Spaces, periods and ^ are taken out, but other characters are not allowed and will lead to a UnitException. The order of allowed units is arbitrary, so "kg/ms2" is accepted as well as "kg/s^2.m".- Parameters:
siString- the string to parse- Returns:
- the corresponding SI dimensions
- Throws:
UnitRuntimeException- when the string could not be parsed into dimensions
-
siAbbreviations
Returns a safe copy of the SI abbreviations (a public static final String[] is mutable).- Returns:
- a safe copy of the SI abbreviations
-
siDimensions
public int[] siDimensions()Return a safe copy of the exponents of the SI dimensions in the order rad, sr, kg, m, s, A, K, mol, cd. Since it is a safe copy, calculations can be carried out on the int[] return value.- Returns:
- a safe copy of the exponents of the SI dimensions in the order rad, sr, kg, m, s, A, K, mol, cd
-
plus
Add a set of SI dimensions to this SIUnit. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.- Parameters:
other- the dimensions to add (usually as a result of multiplication of scalars)- Returns:
- the new dimensions with the dimensions of this object plus the dimensions in the parameter
-
minus
Subtract a set of SI dimensions from this SIUnit. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.- Parameters:
other- the dimensions to subtract (usually as a result of division of scalars)- Returns:
- the new dimensions with the dimensions of this object minus the dimensions in the parameter
-
invert
Invert a set of SI dimensions; instead of m/s we get s/m. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.- Returns:
- the new dimensions that are the inverse of the dimensions in this object
-
pow
Raise a set of SI dimensions to the n-th power. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.- Parameters:
n- the power to which to raise this set of dimensions- Returns:
- the new dimensions with the dimensions of this object raised to the n-th power
-
add
Add two SIUnit and return the new SIUnit. Usually, dimensions are added as a result of multiplication of scalars.- Parameters:
dim1- the first set of dimensionsdim2- the second set of dimensions- Returns:
- the new dimensions with the sum of the dimensions in the parameters
-
subtract
Subtract an SIUnit (dim2) from another SIUnit (dim1) and return the new SIUnit. Usually, dimensions are added as a result of division of scalars.- Parameters:
dim1- the first set of dimensionsdim2- the second set of dimensions that will be subtracted from dim1- Returns:
- the new dimensions with the difference of the dimensions in the parameters
-
ofSi
Description copied from interface:UnitInterfaceReturn an SI-quantity for this unit with a value.- Specified by:
ofSiin interfaceUnitInterface<SIUnit,SIQuantity> - Parameters:
si- the value in SI or BASE units- Returns:
- an SI-quantity for this unit with the given si-value
-
toString
Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIUnit.- Parameters:
divided- if true, return m/s2 for acceleration; if false return ms-2separator- add this string between successive units, e.g. kg.m.s-2 instead of kgms-2powerPrefix- the prefix for the power, e.g., "^" or "<sup>"powerPostfix- the postfix for the power, e.g., "</sup>"- Returns:
- a formatted string for this SIUnit
-
toString
Return a string such as "kgm/s2" or "kg.m/s2" or "kg.m.s-2" from this SIUnit.- Parameters:
divided- if true, return m/s2 for acceleration; if false return ms-2separator- if true, add a period between successive units, e.g. kg.m.s-2 instead of kgms-2- Returns:
- a formatted string describing this SIUnit
-
toString
Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIUnit.- Parameters:
divided- if true, return m/s2 for acceleration; if false return ms-2separator- if true, add a period between successive units, e.g. kg.m.s-2 instead of kgms-2power- if true, add a ^ sign before the power, e.g., "kg.m^2/s^3" instead of "kg.m2/s3"- Returns:
- a formatted string describing this SIUnit
-
toHTMLString
Return a string such as "kgm/s2" or or "kg.m.s-2" from this SIUnit.- Parameters:
divided- if true, return "m/s2" for acceleration; if false return "ms-2"separator- if true, add a period between successive units, e.g. kg.m.s-2- Returns:
- a formatted string describing this SIUnit
-
toString
-
getId
Description copied from interface:UnitInterfaceReturn the id, which is the main abbreviation, of the unit.- Specified by:
getIdin interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the id (main abbreviation) of the unit
-
getScale
Description copied from interface:UnitInterfaceRetrieve the scale of this unit.- Specified by:
getScalein interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the scale of this unit
-
getUnitSystem
Description copied from interface:UnitInterfaceRetrieve the unit system of this unit.- Specified by:
getUnitSystemin interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- unitSystem the unit system of this unit
-
siUnit
Description copied from interface:UnitInterfaceReturn the SI unit for this unit.- Specified by:
siUnitin interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the SI unit for this unit
-
getBaseUnit
Description copied from interface:UnitInterfaceReturn the base unit for this unit.- Specified by:
getBaseUnitin interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the base unit for this unit
-
getTextualAbbreviation
Description copied from interface:UnitInterfaceRetrieve the textual abbreviation, which doubles as the id of the unit. Apply localization when possible.- Specified by:
getTextualAbbreviationin interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the (localized) textual abbreviation
-
getDisplayAbbreviation
Description copied from interface:UnitInterfaceRetrieve the display abbreviation, and apply localization when possible.- Specified by:
getDisplayAbbreviationin interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the (localized) display abbreviation
-
getName
Description copied from interface:UnitInterfaceReturn the name, which is the main written explanation, of the unit. Apply localization when possible.- Specified by:
getNamein interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the (localized) name of the unit
-
getStoredTextualAbbreviation
Description copied from interface:UnitInterfaceRetrieve the stored textual abbreviation, which doubles as the id of the unit. Do not apply localization.- Specified by:
getStoredTextualAbbreviationin interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the stored (non-localized) textual abbreviation
-
getStoredDisplayAbbreviation
Description copied from interface:UnitInterfaceRetrieve the stored display abbreviation, without localization.- Specified by:
getStoredDisplayAbbreviationin interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the stored (non-localized) display abbreviation
-
getStoredName
Description copied from interface:UnitInterfaceReturn the name, which is the main written explanation, of the unit. Do not apply localization.- Specified by:
getStoredNamein interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the stored (non-localized) name of the unit
-
setSiPrefix
Description copied from interface:UnitInterfaceSet the SI-prefix so it can be localized if necessary.- Specified by:
setSiPrefixin interfaceUnitInterface<SIUnit,SIQuantity> - Parameters:
siPrefix- the SI-prefix to set- Returns:
- the unit for method chaining
-
setSiPrefix
Description copied from interface:UnitInterfaceSet the SI-prefix so it can be localized if necessary. This method does NOT handle kilo-prefixes.- Specified by:
setSiPrefixin interfaceUnitInterface<SIUnit,SIQuantity> - Parameters:
prefix- the string-representation of the SI-prefix to set- Returns:
- the unit for method chaining
-
setSiPrefixKilo
Description copied from interface:UnitInterfaceSet the SI-prefix so it can be localized if necessary. This method handles kilo-prefixes.- Specified by:
setSiPrefixKiloin interfaceUnitInterface<SIUnit,SIQuantity> - Parameters:
prefix- the string-representation of the SI-prefix to set- Returns:
- the unit for method chaining
-
setSiPrefixPer
Description copied from interface:UnitInterfaceSet the SI-prefix so it can be localized if necessary. This method handles per-unit prefixes.- Specified by:
setSiPrefixPerin interfaceUnitInterface<SIUnit,SIQuantity> - Parameters:
prefix- the string-representation of the SI-prefix to set- Returns:
- the unit for method chaining
-
getSiPrefix
Description copied from interface:UnitInterfaceReturn the SI-prefix so it can be localized if necessary.- Specified by:
getSiPrefixin interfaceUnitInterface<SIUnit,SIQuantity> - Returns:
- the SI-prefix of this unit, or null when the unit has no SI-prefix
-
hashCode
public int hashCode() -
equals
-