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 unit
RU - 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-2020 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
  • Constructor Details

  • Method Details

    • getRelativeQuantity

      public Quantity<RU> getRelativeQuantity()
      Return the corresponding relative unit base.
      Returns:
      Unit<RU>; the the corresponding relative unit base
    • getRelativeUnit

      public RU getRelativeUnit()
      Return the corresponding relative unit.
      Returns:
      Unit<RU>; the the corresponding relative unit
    • build

      public AU build​(Unit.Builder<AU> builder) throws UnitRuntimeException
      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 class Unit<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 therefore valueSI = ((value2 + o2) * f2 + o1) * f1, which can also be written as value2 * f1 * f2 + f1 * f2 * o2 + f1 * o1.
      Parameters:
      scaleFactor - double; the linear scale factor of the unit
      offset - double; the offset to use for the scale
      derivedRelativeUnit - RU; the corresponding relative unit with the same scale factor
      derivedId - String; the new id of the derived unit
      derivedName - String; the new name of the derived unit
      derivedUnitSystem - UnitSystem; the unit system of the derived unit
      derivedDefaultDisplayAbbreviation - 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 unit
      offset - double; the offset to use for the scale
      derivedRelativeUnit - RU; the corresponding relative unit with the same scale factor
      derivedId - String; the new id of the derived unit
      derivedName - String; the new name of the derived unit
      derivedUnitSystem - 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 unit
      offset - double; the offset to use for the scale
      derivedRelativeUnit - RU; the corresponding relative unit with the same scale factor
      derivedId - String; the new id of the derived unit
      derivedName - 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

      public AbsoluteLinearUnit.Builder<AU,​RU> makeBuilder()
      Create a Builder. Override at subclasses to create extended builder.
      Overrides:
      makeBuilder in class Unit<AU extends AbsoluteLinearUnit<AU,​RU>>
      Returns:
      an instance of a builder.
    • getScale

      public OffsetLinearScale getScale()
      Retrieve the scale of this unit.
      Overrides:
      getScale in class Unit<AU extends AbsoluteLinearUnit<AU,​RU>>
      Returns:
      Scale; the scale of this unit