Package org.djunits.quantity
Class Quantity<U extends Unit<U>>
java.lang.Object
org.djunits.quantity.Quantity<U>
- Type Parameters:
U
- the unit to reference the actual unit in return values
- All Implemented Interfaces:
Serializable
Quantity contains a map of all registered units belonging to this base. It also contains the SI 'fingerprint' of the unit.
The fingerprint is registered in the UnitTypes singleton where are unit types are registered.
Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License
- Author:
- Alexander Verbraeck
- See Also:
-
Constructor Summary
ConstructorDescriptionCreate a unit base with the SI dimensions, provided as a byte array.Create a unit base with the SI dimensions as a String.Quantity
(String name, SIDimensions siDimensions) Create a unit base with the SI dimensions. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Check whether the locale for which abbreviation maps have been loaded is still current.boolean
getLocalizedAbbreviations
(U unit) Retrieve a safe copy of the localized unit abbreviations.Retrieve the localized display abbreviation.Retrieve the localized name of this unit.Retrieve the localized textual abbreviation.final String
getName()
Retrieve the name of the quantity.final SIDimensions
Retrieve the standard unit for this unit base (usually the first registered unit).getUnitByAbbreviation
(String abbreviation) Retrieve a unit by one of its abbreviations.getUnitById
(String id) Retrieve a unit by Id.Return a safe copy of the unitsByAbbreviation.Retrieve a safe copy of the unitsById.Return a safe copy of the unitsByLocalizedAbbreviation.int
hashCode()
Retrieve a unit by one of its abbreviations.void
registerUnit
(U unit, SIPrefixes siPrefixes, double siPrefixPower) Register the unit in the map.toString()
void
unregister
(U unit) Unregister a unit from the registry, e.g. after a Unit test, or to insert a replacement for an already existing unit.
-
Constructor Details
-
Quantity
Create a unit base with the SI dimensions.- Parameters:
name
- String; the quantity name (CamelCase)siDimensions
- SIDimensions; the 9 dimensions of the unit, wrapped in an SIDimensions object- Throws:
NullPointerException
- when one of the arguments is null
-
Quantity
Create a unit base with the SI dimensions as a String.- Parameters:
name
- String; the quantity name (CamelCase)siString
- String; the 9 dimensions of the unit, represented as an SI string- Throws:
UnitRuntimeException
- when the String cannot be translated into an SIDimensions objectNullPointerException
- when one of the arguments is null
-
Quantity
Create a unit base with the SI dimensions, provided as a byte array.- Parameters:
name
- String; the quantity name (CamelCase)siSignature
- byte[]; the 9 dimensions of the unit- Throws:
NullPointerException
- when one of the arguments is null
-
-
Method Details
-
registerUnit
Register the unit in the map. If the unit supports SI prefixes from yocto to yotta, 20 additional abbreviations are registered. When there is both a unit with an "SI prefix" and a separately registered unit, the most specific specification will be registered in the map. As an example, when the LengthUnit "METER" is registered, all 20 units such as the millimeter and the kilometer are registered as well. When earlier or later the "KILOMETER" is created as a separate unit, the "km" lookup will result in the "KILOMETER" registration rather than in the "METER" registration with a factor of 1000.- Parameters:
unit
- U; the unit to register in the map.siPrefixes
- SIPrefixes; indicates whether and which SI prefixes should be generated.siPrefixPower
- double; the power factor of the SI prefixes, e.g. 2.0 for square meters and 3.0 for cubic meters.
-
unregister
Unregister a unit from the registry, e.g. after a Unit test, or to insert a replacement for an already existing unit.- Parameters:
unit
- U; the unit to unregister.
-
getName
Retrieve the name of the quantity.- Returns:
- String; the name of the quantity
-
getSiDimensions
- Returns:
- the siDimensions
-
getUnitById
Retrieve a unit by Id.- Parameters:
id
- String; the id to look up- Returns:
- the corresponding unit or null when it was not found
-
checkLocale
protected void checkLocale()Check whether the locale for which abbreviation maps have been loaded is still current. If not, (re)load. -
getUnitByAbbreviation
Retrieve a unit by one of its abbreviations. First try whether the abbreviation itself is available. If not, look up the unit without spaces, "." and "^" to map e.g., "kg.m/s^2" to "kgm/s2". If that fails, see if the unit is an SIDimensions string. If not, return null.- Parameters:
abbreviation
- String; the abbreviation to look up- Returns:
- the corresponding unit or null when it was not found
-
of
Retrieve a unit by one of its abbreviations. First try whether the abbreviation itself is available. If not, try without "." that might separate the units (e.g., "N.m"). If that fails, look up the unit without "." and "^" to map e.g., "kg.m/s^2" to "kgm/s2". If that fails, see if the unit is an SIDimensions string. If not, return null.- Parameters:
abbreviation
- String; the abbreviation to look up- Returns:
- the corresponding unit or null when it was not found
-
getUnitsById
Retrieve a safe copy of the unitsById.- Returns:
- Map<String, U>; a safe copy of the unitsById
-
getUnitsByAbbreviation
Return a safe copy of the unitsByAbbreviation.- Returns:
- Map<String, U>; a safe copy of the unitsByAbbreviation
-
getUnitsByLocalizedAbbreviation
Return a safe copy of the unitsByLocalizedAbbreviation.- Returns:
- Map<String, U>; a safe copy of the unitsByLocalizedAbbreviation
-
getLocalizedAbbreviations
Retrieve a safe copy of the localized unit abbreviations.- Parameters:
unit
- U; the unit for which to retrieve the abbreviations- Returns:
- Set<String>; the localized unit abbreviations
-
getLocalizedDisplayAbbreviation
Retrieve the localized display abbreviation.- Parameters:
unit
- U; the unit for which to retrieve the display abbreviation- Returns:
- String; the localized display abbreviation
-
getLocalizedTextualAbbreviation
Retrieve the localized textual abbreviation.- Parameters:
unit
- U; the unit for which to retrieve the textual abbreviation- Returns:
- String; the localized textual abbreviation
-
getLocalizedName
Retrieve the localized name of this unit.- Returns:
- String; the localized name of this unit
-
getStandardUnit
Retrieve the standard unit for this unit base (usually the first registered unit).- Returns:
- U; the standardUnit for this unit base (usually the first registered unit)
-
hashCode
public int hashCode() -
equals
-
toString
-