Class Unit<Q extends Quantity>


  • public class Unit<Q extends Quantity>
    extends Object
    Unit of measurement. The representation of a unit of measurement. This generic type is specialised by the dimension type for the unit; for example Length. A unit of measurement belongs to a measurement system with a corresponding symbol. Additionally, a scaling factor and offset provide the means to scale the unit to the base unit for the measuring system, and hence perform unit conversions. There is always one measurement system per dimension type, but additional systems may be added, and these may or may not be interconvertible. For example, an abstract length representation such as pixel size would not be convertible to the SI length units without an explicit conversion with a conversion factor.
    Since:
    5.1.0
    • Method Detail

      • getSymbol

        public String getSymbol()
        Get the symbol for this unit.
        Returns:
        the symbol.
      • getScaleFactor

        public Double getScaleFactor()
        Get the conversion scaling factor for this unit.
        Returns:
        the scaling factor.
      • getOffset

        public Double getOffset()
        Get the conversion offset for this unit.
        Returns:
        the offset.
      • isConvertible

        public Boolean isConvertible​(Unit<Q> inUnit)
        Check if this unit is convertible to another unit.
        Parameters:
        inUnit - the unit to which to convert.
        Returns:
        true if convertible or false if not convertible.
      • convertValue

        public Double convertValue​(Number inValue,
                                   Unit<Q> inUnit)
        Convert a value in this unit to the specified unit.
        Parameters:
        inValue - the value to convert.
        inUnit - the unit to which to convert.
        Returns:
        the converted value
        Throws:
        ArithmeticException - if the conversion is not possible.
      • multiply

        public Unit<Q> multiply​(Integer scalar)
        Multiply the scaling conversion factor in this unit by a scalar.
        Parameters:
        scalar - the multiplication factor.
        Returns:
        a new Unit containing the result of the multiplication.
      • multiply

        public Unit<Q> multiply​(Double scalar)
        Multiply the scaling conversion factor in this unit by a scalar.
        Parameters:
        scalar - the multiplication factor.
        Returns:
        a new Unit with the result of the multiplication.
      • divide

        public Unit<Q> divide​(Integer scalar)
        Divide the scaling conversion factor in this unit by a scalar.
        Parameters:
        scalar - the division factor.
        Returns:
        a new Unit with the result of the division.
      • divide

        public Unit<Q> divide​(Double scalar)
        Divide the scaling conversion factor in this unit by a scalar.
        Parameters:
        scalar - the division factor.
        Returns:
        a new Unit with the result of the division.
      • add

        public Unit<Q> add​(Integer scalar)
        Increase the scaling offset in this unit by a scalar.
        Parameters:
        scalar - the value to add.
        Returns:
        a new Unit with the result of the addition.
      • add

        public Unit<Q> add​(Double scalar)
        Increase the scaling offset in this unit by a scalar.
        Parameters:
        scalar - the value to add.
        Returns:
        a new Unit with the result of the addition.
      • setSymbol

        public Unit<Q> setSymbol​(String inSymbol)
        Change the unit symbol in this unit.
        Parameters:
        inSymbol - the new unit symbol.
        Returns:
        a new Unit with the result of the unit symbol change.
      • prefixSymbol

        public Unit<Q> prefixSymbol​(String prefix)
        Add a prefix to the unit symbol in this unit.
        Parameters:
        prefix - the unit symbol prefix.
        Returns:
        a new Unit with the result of the unit symbol prefix addition.
      • CreateBaseUnit

        public static <Q extends QuantityUnit<Q> CreateBaseUnit​(String inMeasurementSystem,
                                                                  String inSymbol)
        Create the "base unit" for a given measurement system. This is the default or reference unit representing unity for the measurement system. For example, for a unit system representing length, the measurement system and symbol could be "SI.METRE" and "m", respectively.
        Parameters:
        inMeasurementSystem - the name of the measurement system.
        inSymbol - the symbol of the base unit.