Package org.djunits.unit
Class AbsoluteLinearUnit<AU extends AbsoluteLinearUnit<AU,RU>,RU extends Unit<RU>>
java.lang.Object
org.djunits.unit.Unit<AU>
org.djunits.unit.AbsoluteLinearUnit<AU,RU>
- Type Parameters:
AU
- the specific unitRU
- the corresponding relative unit
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
AbsoluteTemperatureUnit
,DirectionUnit
,PositionUnit
,TimeUnit
public abstract class AbsoluteLinearUnit<AU extends AbsoluteLinearUnit<AU,RU>,RU extends Unit<RU>> extends Unit<AU> implements Serializable
The AbsoluteUnit class indicates that a unit is absolute and has a "zero" point. The relative unit base will be set correctly
for each derived unit, as this is one of the fields that will be cloned to create a derived unit.
Copyright (c) 2019-2019 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:
- Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbsoluteLinearUnit.Builder<AU extends AbsoluteLinearUnit<AU,RU>,RU extends Unit<RU>>
Builder for the AbsoluteUnit. -
Constructor Summary
Constructors Constructor Description AbsoluteLinearUnit()
-
Method Summary
Modifier and Type Method Description AU
build(Unit.Builder<AU> builder)
Build the unit, using the information of the provided builder class.AU
deriveLinearOffset(double scaleFactor, double offset, RU derivedRelativeUnit, String derivedId, String derivedName)
Create a linearly scaled version of this unit with an offset.AU
deriveLinearOffset(double scaleFactor, double offset, RU derivedRelativeUnit, String derivedId, String derivedName, UnitSystem derivedUnitSystem)
Create a linearly scaled version of this unit with an offset.AU
deriveLinearOffset(double scaleFactor, double offset, RU derivedRelativeUnit, String derivedId, String derivedName, UnitSystem derivedUnitSystem, String derivedDefaultDisplayAbbreviation, String derivedDefaultTextualAbbreviation, String... derivedAbbreviations)
Create a linearly scaled version of this unit with an offset.Quantity<RU>
getRelativeQuantity()
Return the corresponding relative unit base.RU
getRelativeUnit()
Return the corresponding relative unit.OffsetLinearScale
getScale()
Retrieve the scale of this unit.AbsoluteLinearUnit.Builder<AU,RU>
makeBuilder()
Create a Builder.Methods inherited from class org.djunits.unit.Unit
clone, deriveLinear, deriveLinear, deriveLinear, derivePerSI, deriveSI, deriveSI, deriveSIKilo, equals, getAbbreviations, getDefaultDisplayAbbreviation, getDefaultTextualAbbreviation, getId, getName, getQuantity, getStandardUnit, getUnit, getUnitSystem, hashCode, isBaseSIUnit, isGenerated, lookupOrCreateUnitWithSIDimensions, toString
-
Constructor Details
-
AbsoluteLinearUnit
public AbsoluteLinearUnit()
-
-
Method Details
-
getRelativeQuantity
Return the corresponding relative unit base.- Returns:
- Unit<RU>; the the corresponding relative unit base
-
getRelativeUnit
Return the corresponding relative unit.- Returns:
- Unit<RU>; the the corresponding relative unit
-
build
Build the unit, using the information of the provided builder class. First check rigorously if all necessary fields in the builder have been set, and whether they are consistent and valid. The behavior is as follows: the defaultAbbreviation and defaultTextualAbbreviation are added to the abbreviations set, if they are not yet already there. When the defaultAbbreviation is set and the defaultTextualAbbreviation is not set, the defaultTextualAbbreviation gets the value of defaultAbbreviation. The reverse also holds: When the defaultTextualAbbreviation is set and the defaultAbbreviation is not set, the defaultAbbreviation gets the value of defaultTextualAbbreviation. When neither the defaultTextualAbbreviation, nor the defaultAbbreviation are set, both get the value of the unitId provided in the builder.- Overrides:
build
in classUnit<AU extends AbsoluteLinearUnit<AU,RU>>
- Parameters:
builder
- Builder<U>; Builder<U> the object that contains the information about the construction of the class- Returns:
- U; the constructed unit
- Throws:
UnitRuntimeException
- when not all fields have been set
-
deriveLinearOffset
public AU deriveLinearOffset(double scaleFactor, double offset, RU derivedRelativeUnit, String derivedId, String derivedName, UnitSystem derivedUnitSystem, String derivedDefaultDisplayAbbreviation, String derivedDefaultTextualAbbreviation, String... derivedAbbreviations)Create a linearly scaled version of this unit with an offset. The scale field will be filled with the correct scaleFactor. Note that the unit that is used for derivation is currently not allowed to already have a scaleFactor and an offset.
When this has to be implemented later, it might work as follows: when we have an original scale with offset o1 and scalefactor f1, the calculation to the unit base is valueSI = (value1 + o1) * f1. So the offset is expressed in the "unit" of the value. If we combine a second scale factor for a derived unit with offset o2 and scalefactor f2, we need to calculate the ultimate scale to the base (si) unit. The factor then becomes:value1 = (value2 + o2) * f2
, and thereforevalueSI = ((value2 + o2) * f2 + o1) * f1
, which can also be written asvalue2 * f1 * f2 + f1 * f2 * o2 + f1 * o1
.- Parameters:
scaleFactor
- double; the linear scale factor of the unitoffset
- double; the offset to use for the scalederivedRelativeUnit
- RU; the corresponding relative unit with the same scale factorderivedId
- String; the new id of the derived unitderivedName
- String; the new name of the derived unitderivedUnitSystem
- UnitSystem; the unit system of the derived unitderivedDefaultDisplayAbbreviation
- String; the default abbreviation to use in e.g, the toString() method. Can be null.derivedDefaultTextualAbbreviation
- String; the default textual abbreviation to use in, e.g, typing. Can be null.derivedAbbreviations
- String...; String... any other valid abbreviations for the unit, e.g. {"h", "hr", "hour"}. Can be empty.- Returns:
- AU; a linearly scaled instance of this unit with new id, abbreviation, name, and unit system
- Throws:
UnitRuntimeException
- when cloning fails
-
deriveLinearOffset
public AU deriveLinearOffset(double scaleFactor, double offset, RU derivedRelativeUnit, String derivedId, String derivedName, UnitSystem derivedUnitSystem)Create a linearly scaled version of this unit with an offset. The scale field will be filled with the correct scaleFactor. Note that the unit that is used for derivation can already have a scaleFactor.- Parameters:
scaleFactor
- double; the linear scale factor of the unitoffset
- double; the offset to use for the scalederivedRelativeUnit
- RU; the corresponding relative unit with the same scale factorderivedId
- String; the new id of the derived unitderivedName
- String; the new name of the derived unitderivedUnitSystem
- UnitSystem; the unit system of the derived unit- Returns:
- AU; a linearly scaled instance of this unit with new id, abbreviation, name, and unit system
- Throws:
UnitRuntimeException
- when cloning fails
-
deriveLinearOffset
public AU deriveLinearOffset(double scaleFactor, double offset, RU derivedRelativeUnit, String derivedId, String derivedName)Create a linearly scaled version of this unit with an offset. The unitSystem will be copied. The scale field will be filled with the correct scaleFactor. Note that the unit that is used for derivation can already have a scaleFactor.- Parameters:
scaleFactor
- double; the linear scale factor of the unitoffset
- double; the offset to use for the scalederivedRelativeUnit
- RU; the corresponding relative unit with the same scale factorderivedId
- String; the new id of the derived unitderivedName
- String; the new name of the derived unit- Returns:
- AU; a linearly scaled instance of this unit with new id, abbreviation, name, and unit system
- Throws:
UnitRuntimeException
- when cloning fails
-
makeBuilder
Create a Builder. Override at subclasses to create extended builder.- Overrides:
makeBuilder
in classUnit<AU extends AbsoluteLinearUnit<AU,RU>>
- Returns:
- an instance of a builder.
-
getScale
Retrieve the scale of this unit.
-